* Moving commits from one branch to another (improving my git fu!)
@ 2013-10-22 5:38 Mandeep Sandhu
2013-10-22 5:52 ` Peter Krefting
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Mandeep Sandhu @ 2013-10-22 5:38 UTC (permalink / raw)
To: git
Hi All,
I'm in a bit of a pickle! :) So I've come to ask for help from the guru's here.
My story is not unique but somehow the various suggested solutions
don't seem to work in my case.
* I was working on a feature which was supposed to be done off our
'dev' branch. But instead I forgot and branched out my topic branch
from master (or as we call it 'stable').
* I did 2 commits and finished off my work. Only later realizing that
it had to be done off 'dev'.
* Now I want to move my 2 commits (which are the top 2 commits on my
topic branch) to a new branch which is branched off 'dev'.
$ git branch
* topicA
* stable
* dev
topicA was based on stable. But now I want to base it dev.
So I did what was most suggested, i.e use 'git rebase --onto'.
Here's what I did when I was in topicA:
$ git rebase dev stable topicA
(this was suggested in the manpage as well).
This started off a massive rebase operation, because the 'dev' branch
is vastly diverged from stable, and a lot of conflicts started
appearing.
I'm not sure if I'm doing it right here, so can anyone suggest whether
this is right or do I need to do it differently?
PS: Please CC me (mandeepsandhu.chd@gmail.com) in your reply as I'm
not currently subscribed to the list.
Thanks for your time.
Regards,
-mandeep
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: Moving commits from one branch to another (improving my git fu!)
2013-10-22 5:38 Moving commits from one branch to another (improving my git fu!) Mandeep Sandhu
@ 2013-10-22 5:52 ` Peter Krefting
2013-10-22 6:11 ` Mandeep Sandhu
2013-10-22 6:00 ` Bryan Turner
2013-10-22 12:42 ` Noufal Ibrahim
2 siblings, 1 reply; 7+ messages in thread
From: Peter Krefting @ 2013-10-22 5:52 UTC (permalink / raw)
To: Mandeep Sandhu; +Cc: git
Mandeep Sandhu:
> Here's what I did when I was in topicA:
>
> $ git rebase dev stable topicA
> (this was suggested in the manpage as well).
I guess you also had an "--onto" in there, as the above would throw a
syntax error. As long as the branches are in order, I cannot see how
that wouldn't do what you wanted.
However, the easiest way to do it would probably just to run:
git checkout topicA
git rebase dev
As long as "dev" already contains all the commits in "stable", that
should work fine. If not, then you would need something more
complicated.
Another way to do it would be to use cherry-pick on a new branch:
git checkout -b new_topicA dev
git cherry-pick stable..topicA
--
\\// Peter - http://www.softwolves.pp.se/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Moving commits from one branch to another (improving my git fu!)
2013-10-22 5:52 ` Peter Krefting
@ 2013-10-22 6:11 ` Mandeep Sandhu
0 siblings, 0 replies; 7+ messages in thread
From: Mandeep Sandhu @ 2013-10-22 6:11 UTC (permalink / raw)
To: Peter Krefting; +Cc: git
>> $ git rebase dev stable topicA
>> (this was suggested in the manpage as well).
>
>
> I guess you also had an "--onto" in there, as the above would throw a syntax
> error. As long as the branches are in order, I cannot see how that wouldn't
> do what you wanted.
Yes, you're right. There was "--onto" there.
The only problem is that there were a LOT of conflicts when I ran this
cmd in places which have nothing to do with my commit. And as I said,
dev is vastly different from stable.
>
> However, the easiest way to do it would probably just to run:
>
> git checkout topicA
> git rebase dev
>
> As long as "dev" already contains all the commits in "stable", that should
> work fine. If not, then you would need something more complicated.
I don't think thats the case currently. People commit bug-fixes to
'stable' (from which a release will be made later) and all new and
experimental stuff is tried on 'dev'. So there's a lot in 'dev' that's
not there in 'stable'.
>
> Another way to do it would be to use cherry-pick on a new branch:
>
> git checkout -b new_topicA dev
> git cherry-pick stable..topicA
Hmmm...this looks safe to do. If I do "git log stable..topicA" it
should only show my commits made on top of stable, right? Or I can
even mention the commit SHA here?
Thanks,
-mandeep
>
> --
> \\// Peter - http://www.softwolves.pp.se/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Moving commits from one branch to another (improving my git fu!)
2013-10-22 5:38 Moving commits from one branch to another (improving my git fu!) Mandeep Sandhu
2013-10-22 5:52 ` Peter Krefting
@ 2013-10-22 6:00 ` Bryan Turner
2013-10-22 6:15 ` Mandeep Sandhu
2013-10-22 12:42 ` Noufal Ibrahim
2 siblings, 1 reply; 7+ messages in thread
From: Bryan Turner @ 2013-10-22 6:00 UTC (permalink / raw)
To: Mandeep Sandhu; +Cc: Git Users
A quick glance at your command line and the man page for git rebase
suggests the problem was you didn't actually use --onto. I believe the
correct command would be:
git rebase --onto dev stable topicA
That should start by determining which commits are one topicA but not
stable and then checkout dev and apply those new commits.
Hope this helps,
Bryan Turner
On 22 October 2013 16:38, Mandeep Sandhu <mandeepsandhu.chd@gmail.com> wrote:
> Hi All,
>
> I'm in a bit of a pickle! :) So I've come to ask for help from the guru's here.
>
> My story is not unique but somehow the various suggested solutions
> don't seem to work in my case.
>
> * I was working on a feature which was supposed to be done off our
> 'dev' branch. But instead I forgot and branched out my topic branch
> from master (or as we call it 'stable').
> * I did 2 commits and finished off my work. Only later realizing that
> it had to be done off 'dev'.
> * Now I want to move my 2 commits (which are the top 2 commits on my
> topic branch) to a new branch which is branched off 'dev'.
>
> $ git branch
> * topicA
> * stable
> * dev
>
> topicA was based on stable. But now I want to base it dev.
>
> So I did what was most suggested, i.e use 'git rebase --onto'.
>
> Here's what I did when I was in topicA:
>
> $ git rebase dev stable topicA
> (this was suggested in the manpage as well).
>
> This started off a massive rebase operation, because the 'dev' branch
> is vastly diverged from stable, and a lot of conflicts started
> appearing.
>
> I'm not sure if I'm doing it right here, so can anyone suggest whether
> this is right or do I need to do it differently?
>
> PS: Please CC me (mandeepsandhu.chd@gmail.com) in your reply as I'm
> not currently subscribed to the list.
>
> Thanks for your time.
>
> Regards,
> -mandeep
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Moving commits from one branch to another (improving my git fu!)
2013-10-22 6:00 ` Bryan Turner
@ 2013-10-22 6:15 ` Mandeep Sandhu
0 siblings, 0 replies; 7+ messages in thread
From: Mandeep Sandhu @ 2013-10-22 6:15 UTC (permalink / raw)
To: Bryan Turner; +Cc: Git Users
On Tue, Oct 22, 2013 at 11:30 AM, Bryan Turner <bturner@atlassian.com> wrote:
> A quick glance at your command line and the man page for git rebase
> suggests the problem was you didn't actually use --onto. I believe the
> correct command would be:
>
> git rebase --onto dev stable topicA
Yes, thats the cmd I gave. (missed typing onto in the mail though)
>
>
> That should start by determining which commits are one topicA but not
> stable and then checkout dev and apply those new commits.
Thats what I expected too. There are only 2 commits that were made in
topicA. So I was expecting it to pick those 2 and apply them on the
dev branch. But instead it's applying a LOT of commits on dev.
Remember that 'dev' is very different from 'stable'.
As suggested, maybe cherry-pciking is what I need to do.
Thanks,
-mandeep
>
>
> Hope this helps,
> Bryan Turner
>
> On 22 October 2013 16:38, Mandeep Sandhu <mandeepsandhu.chd@gmail.com> wrote:
>> Hi All,
>>
>> I'm in a bit of a pickle! :) So I've come to ask for help from the guru's here.
>>
>> My story is not unique but somehow the various suggested solutions
>> don't seem to work in my case.
>>
>> * I was working on a feature which was supposed to be done off our
>> 'dev' branch. But instead I forgot and branched out my topic branch
>> from master (or as we call it 'stable').
>> * I did 2 commits and finished off my work. Only later realizing that
>> it had to be done off 'dev'.
>> * Now I want to move my 2 commits (which are the top 2 commits on my
>> topic branch) to a new branch which is branched off 'dev'.
>>
>> $ git branch
>> * topicA
>> * stable
>> * dev
>>
>> topicA was based on stable. But now I want to base it dev.
>>
>> So I did what was most suggested, i.e use 'git rebase --onto'.
>>
>> Here's what I did when I was in topicA:
>>
>> $ git rebase dev stable topicA
>> (this was suggested in the manpage as well).
>>
>> This started off a massive rebase operation, because the 'dev' branch
>> is vastly diverged from stable, and a lot of conflicts started
>> appearing.
>>
>> I'm not sure if I'm doing it right here, so can anyone suggest whether
>> this is right or do I need to do it differently?
>>
>> PS: Please CC me (mandeepsandhu.chd@gmail.com) in your reply as I'm
>> not currently subscribed to the list.
>>
>> Thanks for your time.
>>
>> Regards,
>> -mandeep
>> --
>> To unsubscribe from this list: send the line "unsubscribe git" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Moving commits from one branch to another (improving my git fu!)
2013-10-22 5:38 Moving commits from one branch to another (improving my git fu!) Mandeep Sandhu
2013-10-22 5:52 ` Peter Krefting
2013-10-22 6:00 ` Bryan Turner
@ 2013-10-22 12:42 ` Noufal Ibrahim
2013-10-22 12:51 ` Mandeep Sandhu
2 siblings, 1 reply; 7+ messages in thread
From: Noufal Ibrahim @ 2013-10-22 12:42 UTC (permalink / raw)
To: Mandeep Sandhu; +Cc: git
Mandeep Sandhu <mandeepsandhu.chd@gmail.com> writes:
> Hi All,
>
> I'm in a bit of a pickle! :) So I've come to ask for help from the guru's here.
>
> My story is not unique but somehow the various suggested solutions
> don't seem to work in my case.
>
> * I was working on a feature which was supposed to be done off our
> 'dev' branch. But instead I forgot and branched out my topic branch
> from master (or as we call it 'stable').
> * I did 2 commits and finished off my work. Only later realizing that
> it had to be done off 'dev'.
> * Now I want to move my 2 commits (which are the top 2 commits on my
> topic branch) to a new branch which is branched off 'dev'.
I had a situtation similar to this a while ago and used the --onto
option to rebase. The details are at
http://nibrahim.net.in/2012/01/09/moving_topic_branches_in_git.html
[...]
--
Cordially,
Noufal
http://nibrahim.net.in
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Moving commits from one branch to another (improving my git fu!)
2013-10-22 12:42 ` Noufal Ibrahim
@ 2013-10-22 12:51 ` Mandeep Sandhu
0 siblings, 0 replies; 7+ messages in thread
From: Mandeep Sandhu @ 2013-10-22 12:51 UTC (permalink / raw)
To: Noufal Ibrahim; +Cc: Git Users
Thanks for the link.
I too tried doing a rebase with --onto, though as I said, I was
getting a lot of conflicts while doing it.
So cherry-picking my 2 commits was the solution that worked. I had
also screwed up my topic branch by doing different combo's of this cmd
and using --set-upstream-to option to point to 'dev' on a branch that
was branched off from 'stable'! :)
Lesson learned. I'll be careful when doing branching next time :)
-mandeep
On Tue, Oct 22, 2013 at 6:12 PM, Noufal Ibrahim <noufal@nibrahim.net.in> wrote:
> Mandeep Sandhu <mandeepsandhu.chd@gmail.com> writes:
>
>> Hi All,
>>
>> I'm in a bit of a pickle! :) So I've come to ask for help from the guru's here.
>>
>> My story is not unique but somehow the various suggested solutions
>> don't seem to work in my case.
>>
>> * I was working on a feature which was supposed to be done off our
>> 'dev' branch. But instead I forgot and branched out my topic branch
>> from master (or as we call it 'stable').
>> * I did 2 commits and finished off my work. Only later realizing that
>> it had to be done off 'dev'.
>> * Now I want to move my 2 commits (which are the top 2 commits on my
>> topic branch) to a new branch which is branched off 'dev'.
>
> I had a situtation similar to this a while ago and used the --onto
> option to rebase. The details are at
> http://nibrahim.net.in/2012/01/09/moving_topic_branches_in_git.html
>
> [...]
>
>
> --
> Cordially,
> Noufal
> http://nibrahim.net.in
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-10-22 13:18 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-22 5:38 Moving commits from one branch to another (improving my git fu!) Mandeep Sandhu
2013-10-22 5:52 ` Peter Krefting
2013-10-22 6:11 ` Mandeep Sandhu
2013-10-22 6:00 ` Bryan Turner
2013-10-22 6:15 ` Mandeep Sandhu
2013-10-22 12:42 ` Noufal Ibrahim
2013-10-22 12:51 ` Mandeep Sandhu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox