I have two branches, X
and Y
, and I want to cherry-pick a bunch of commits from Y
to X
, say, C..F, H, M
. I can achieve this with:
git switch X
git log Y
# Look up commits of interest
git cherry-pick C..F H M
However, looking up and copy-pasting the commit hashes of interest is cumbersome. I'd prefer Git to present me with a list of candidate commits (hashes and messages) from which I can simply select the ones I want to pick.
git rebase -i
provides just such a list, and this seems to achieve what I want (source):
# Checkout a new temporary branch at the current location git checkout -b tmp # Move the integration branch to the head of the new patchset git branch -f integration last_SHA-1_of_working_branch_range # Rebase the patchset onto tmp, the old location of integration git rebase --onto tmp first_SHA-1_of_working_branch_range~1 integration
However, having to create and later clean up a temporary branch makes this similarly cumbersome ans hand-picking the hashes of interest. Is there a simpler way to do such an "interactive cherry-pick"?
I have two branches, X
and Y
, and I want to cherry-pick a bunch of commits from Y
to X
, say, C..F, H, M
. I can achieve this with:
git switch X
git log Y
# Look up commits of interest
git cherry-pick C..F H M
However, looking up and copy-pasting the commit hashes of interest is cumbersome. I'd prefer Git to present me with a list of candidate commits (hashes and messages) from which I can simply select the ones I want to pick.
git rebase -i
provides just such a list, and this seems to achieve what I want (source):
# Checkout a new temporary branch at the current location git checkout -b tmp # Move the integration branch to the head of the new patchset git branch -f integration last_SHA-1_of_working_branch_range # Rebase the patchset onto tmp, the old location of integration git rebase --onto tmp first_SHA-1_of_working_branch_range~1 integration
However, having to create and later clean up a temporary branch makes this similarly cumbersome ans hand-picking the hashes of interest. Is there a simpler way to do such an "interactive cherry-pick"?
Share Improve this question asked Mar 6 at 15:02 flotzillaflotzilla 1,2561 gold badge15 silver badges24 bronze badges 2 |1 Answer
Reset to default 1Making @j6t's comment concrete:
git rebase -i @ Y^0 # `Y^0` rather than `Y` to skip the label and get just the commits
git checkout -B X @ # re-hang the `X` label on the new tip and attach i.e. check it out.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744967584a4603774.html
HEAD
andgit rebase -i
. – j6t Commented Mar 6 at 15:11git rebase -i
does the job. "Cleaning up the temp branch" is really a noop here, if you care to describe the issue you see on that point someone will probably help you write the script or alias to do it quickly. – LeGEC Commented Mar 6 at 15:34