git rebase - Git cherry-pick multiple commits without manually copy-pasting hashes - Stack Overflow

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 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
  • 2 You don't need temporary branches. You can work with detached HEAD and git rebase -i. – j6t Commented Mar 6 at 15:11
  • +1 for git 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
Add a comment  | 

1 Answer 1

Reset to default 1

Making @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

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信