git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Correcting forgetting to make a new branch
@ 2011-03-11 15:31 Howard Miller
  2011-03-11 15:46 ` Alexey Feldgendler
  2011-03-11 15:49 ` Michael J Gruber
  0 siblings, 2 replies; 5+ messages in thread
From: Howard Miller @ 2011-03-11 15:31 UTC (permalink / raw)
  To: git

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?

TYIA

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Correcting forgetting to make a new branch
  2011-03-11 15:31 Correcting forgetting to make a new branch Howard Miller
@ 2011-03-11 15:46 ` Alexey Feldgendler
  2011-03-11 15:50   ` Matthieu Moy
  2011-03-11 15:49 ` Michael J Gruber
  1 sibling, 1 reply; 5+ messages in thread
From: Alexey Feldgendler @ 2011-03-11 15:46 UTC (permalink / raw)
  To: git

On Fri, 11 Mar 2011 16:31:18 +0100, Howard Miller  
<howard@e-learndesign.co.uk> wrote:

> 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?

Just create a new branch right where you are, it will be correct.

However, the branch that was active before when you should have branched  
will have been unintentionally updated. To fix that, you'll need to move  
the old branch a few commits back:

git branch -f <old-branch> <where-it-was-before>


-- 
Alexey Feldgendler
Software Developer, Desktop Team, Opera Software ASA
[ICQ: 115226275] http://my.opera.com/feldgendler/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Correcting forgetting to make a new branch
  2011-03-11 15:31 Correcting forgetting to make a new branch Howard Miller
  2011-03-11 15:46 ` Alexey Feldgendler
@ 2011-03-11 15:49 ` Michael J Gruber
  1 sibling, 0 replies; 5+ messages in thread
From: Michael J Gruber @ 2011-03-11 15:49 UTC (permalink / raw)
  To: Howard Miller; +Cc: git

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Correcting forgetting to make a new branch
  2011-03-11 15:46 ` Alexey Feldgendler
@ 2011-03-11 15:50   ` Matthieu Moy
  2011-03-11 15:53     ` Howard Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Matthieu Moy @ 2011-03-11 15:50 UTC (permalink / raw)
  To: Alexey Feldgendler; +Cc: git

"Alexey Feldgendler" <alexeyf@opera.com> writes:

> However, the branch that was active before when you should have
> branched will have been unintentionally updated. To fix that, you'll
> need to move the old branch a few commits back:
>
> git branch -f <old-branch> <where-it-was-before>

This is correct, but for completeness: don't do that if you've already
pushed your changes. If you pushed them and people already pulled them,
you can hardly do better than appologize to your co-workers that you
shouldn't have done that, and possibly create a new commit on top of the
branch reverting what you did.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Correcting forgetting to make a new branch
  2011-03-11 15:50   ` Matthieu Moy
@ 2011-03-11 15:53     ` Howard Miller
  0 siblings, 0 replies; 5+ messages in thread
From: Howard Miller @ 2011-03-11 15:53 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Alexey Feldgendler, git

> "Alexey Feldgendler" <alexeyf@opera.com> writes:
>
>> However, the branch that was active before when you should have
>> branched will have been unintentionally updated. To fix that, you'll
>> need to move the old branch a few commits back:
>>
>> git branch -f <old-branch> <where-it-was-before>
>
> This is correct, but for completeness: don't do that if you've already
> pushed your changes. If you pushed them and people already pulled them,
> you can hardly do better than appologize to your co-workers that you
> shouldn't have done that, and possibly create a new commit on top of the
> branch reverting what you did.

I hadn't (luckily), so that worked fine. Thanks for your help - both of you :)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-03-11 15:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-11 15:31 Correcting forgetting to make a new branch Howard Miller
2011-03-11 15:46 ` Alexey Feldgendler
2011-03-11 15:50   ` Matthieu Moy
2011-03-11 15:53     ` Howard Miller
2011-03-11 15:49 ` Michael J Gruber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).