Re: Correcting forgetting to make a new branch

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

 



Howard Miller venit, vidit, dixit 11.03.2011 16:31:
> The scenario is that I have done work on a branch and made a number of
> commits. What I wanted to do was to start a new branch before I made
> these commits. Unfortunatel, I got distracted and forgot that I hadn't
> done it.
> 
> Is there are neat way to create the branch and 'move' the commits over?

It depends on which commit you wanted the new branch to start with. If
you have

...-*-*-*-X-*-*-*-*-A

on branch A and X is the commit where you meant to create a new branch B
starting at X you can simply

git checkout A
git branch B
git reset --hard X

or simply

git branch -m A B
git branch -f A X

If, on the other hand, you wanted to start B from a different commit Y,
you will need to rebase:

git branch B A
git branch -f A X
git rebase --onto Y A B

After backing up, of course ;)

Michael
--
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]