Re: User's mailing list? And multiple cherry pick

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: David <wizzardx@...>
Cc: <git@...>, Junio C Hamano <gitster@...>
Date: Wednesday, June 4, 2008 - 4:16 am

On Wednesday 04 June 2008, David wrote:

Depends on you definition of "simple". Here are 5 commands that gets the job done in a (IMHO) conceptually simple way.

Use

	git checkout -b [tmpBranch] [fromBranch]

to create (and checkout) a _new_ branch pointing to the same commit as the "from"-branch. Then use

	git rebase --onto [toBranch] [fromBranchStart] [tmpBranch]

to rebase all commits between [fromBranchStart] and [fromBranch] on top of [toBranch]. Since this was done with HEAD == [tmpBranch], the original [fromBranch] is not moved, and therefore *still* points to the old commits. [tmpBranch], however, have been moved to point at the rebased commits. This in effect *copies* the commits from [fromBranch] to [tmpBranch]. Now, all that remains is to reconcile [tmpBranch] and [toBranch], and finally remove [tmpBranch]:

	git checkout [toBranch]
	git merge [tmpBranch]
	git branch -d [tmpBranch]

The merge should be a simple fast-forward without any conflicts.

Here is an illustrated version of what's going on:

Initial layout:

	          G---H---I  <---- [fromBranch]
	         /
	A---B---C---D---E---F  <-- [toBranch]
	        ^----------------- [fromBranchStart]

git checkout -b [tmpBranch] [fromBranch]

	          G---H---I  <---- [fromBranch]
	         /        ^------- [tmpBranch]      
	A---B---C---D---E---F  <-- [toBranch]
	        ^----------------- [fromBranchStart]

git rebase --onto [toBranch] [fromBranchStart] [tmpBranch]

	          G---H---I  <------------------- [fromBranch]
	         /              
	A---B---C---D---E---F---G'---H'---I'  <-- [tmpBranch]
	        ^           ^-------------------- [toBranch]
	        --------------------------------- [fromBranchStart]

git checkout [toBranch]
git merge [tmpBranch]
git branch -d [tmpBranch]

	          G---H---I  <------------------- [fromBranch]
	         /              
	A---B---C---D---E---F---G'---H'---I'  <-- [toBranch]
	        ^-------------------------------- [fromBranchStart]


This should also work even if your commit graphs are considerably more complicated.

If you need to drop/edit/squash any commits between [fromBranchStart] and [fromBranch], simply add a "--interactive" to the rebase command.


Have fun!

...Johan

-- 
Johan Herland, <johan@herland.net>
www.herland.net
--
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
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: User's mailing list? And multiple cherry pick, Stephan Beyer, (Wed Jun 4, 4:00 am)
Re: User's mailing list? And multiple cherry pick, Jakub Narebski, (Wed Jun 4, 3:39 am)
Re: User's mailing list? And multiple cherry pick, Miklos Vajna, (Wed Jun 4, 7:10 am)
Re: User's mailing list? And multiple cherry pick, Theodore Tso, (Wed Jun 4, 7:36 am)
Re: User's mailing list? And multiple cherry pick, Jakub Narebski, (Wed Jun 4, 4:50 am)
Re: User's mailing list? And multiple cherry pick, Jakub Narebski, (Wed Jun 4, 5:47 am)
Re: User's mailing list? And multiple cherry pick, Junio C Hamano, (Wed Jun 4, 2:58 am)
Re: User's mailing list? And multiple cherry pick, Johan Herland, (Wed Jun 4, 4:16 am)
Re: User's mailing list? And multiple cherry pick, Jakub Narebski, (Wed Jun 4, 4:05 am)
Re: User's mailing list? And multiple cherry pick, Wincent Colaiuta, (Wed Jun 4, 5:39 am)
Re: User's mailing list? And multiple cherry pick, Jakub Narebski, (Wed Jun 4, 7:09 am)
Re: User's mailing list? And multiple cherry pick, Wincent Colaiuta, (Wed Jun 4, 7:02 am)
Re: User's mailing list? And multiple cherry pick, Johan Herland, (Wed Jun 4, 4:23 am)