Re: Commit to wrong branch. How to fix?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Howard Miller <howardsmiller@xxxxxxxxxxxxxx> writes:

> I must admit I don't understand what 'reflog' is (more reading) - not heard
> of that before.

I'll try to explain it with some ASCII-art.

Let's say that you had the following situation:

  ...---A---B---C           <-- foo  <--- HEAD

Current branch is named 'foo', and three last commits on it are named
A, B, C.

Now you create new commit (I assume that you comitted unwanted
changes; the recipe would be different (much simpler) if you have
realized that you are on wrong branch[1] before committing)

[1] git aware shell prompt, countaing branch name, could help there

  ...---A---B---C---X           <-- foo  <--- HEAD

Reflog records that commit in 'foo' reflog and in HEAD reflog

  foo@{0}: X


You have realized that you are on wrong branch, and you did 
"git reset --hard HEAD^" (too early)

  ...---A---B---C               <-- foo  <--- HEAD
                 \
                  \-X

Reflog records that fact (it records where tip of branch was)

  foo@{0}: C
  foo@{1}: X


Then if you want to create new branch 'bar' with X, you would do

 $ git checkout -b bar foo@{1}

If you wanted to have this commit on some other existing branch, let's
call it 'baz', you would do instead (I think):

 $ git checkout baz
 $ git cherry-pick foo@{1}

HTH (hope that helps).
-- 
Jakub Narebski
Poland
ShadeHawk on #git
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]