简体   繁体   中英

Create New Git Branch Skipping A Commit From the Middle

I have a git branch and want to create a new branch from that one. I have merged a bunch of Pull Requests to that branch and want to include them all in the new branch, except for one that is somewhere in the middle of all the PRs merged in. How do I exclude just that check-in in my new branch?

I was thinking of creating the new branch from the commit just before the one I want to exclude and then doing a cherry-pick merge from the old branch into the new branch skipping the commit I want to exclude. Not sure if that is the best solution though.

I think the easiest is to use rebase:

git checkout -b new-branch # on top of the old branch, say
git rebase -i revision-to-delete~
# in what will show up, the revision to delete should be the first one
# set that one to _skip_
# save, exit and let it run

In the end you should have your rebased branch. I think there are options to keep merges and stuff but I'm not that experienced playing with them so feel free to experiment, specially given that you are working on a separate branch. If you don't like the result, start over again

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM