简体   繁体   中英

Remove several git commits from parent branch

I pushed some commits to a feature_branch and integrated the latest state of the parent branch staging . Then, pushed other few ones.

I did not use rebase and now my feature_branch 's history looks like this:

feature_commit_Y

feature_commit_X

staging_commit_D

staging_commit_C

feature_commit_B

feature_commit_A

How can I get rid of those 2 staging commits so I can pull rebase and then push my future feature_commits to come?

Use

git rebase -i HEAD~4

The -i option will start an interactive rebase and HEAD~4 will include the last 4 commits for rebase. Commenting out the commits will take out the commits from the list of commits to be applied. You can then continue the rebase which will apply feature_commit_X and feature_commit_y

  1. Assuming both feature_commit_X and feature_commit_Y are single commits:

     git checkout feature_commit_B git cherry-pick feature_commit_X feature_commit_Y 

    git cherry-pick copies a set of commits to the current branch.

  2. In any case:

     git rebase --onto feature_commit_B staging_commit_D feature_commit_Y 

    This will “transplant” the commits starting with the one after staging_commit_D up to feature_commit_Y onto feature_commit_B . If you use a branch name in the place of feature_commit_Y , this branch will be updated.

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