Push commits to another branch

前端 未结 9 1280
走了就别回头了
走了就别回头了 2020-11-29 14:38

Is it possible to commit and push changes from one branch to another.

Assume I commited changes in BRANCH1 and want to push them to BRANCH2<

9条回答
  •  天命终不由人
    2020-11-29 15:04

    You have committed to BRANCH1 and want to get rid of this commit without losing the changes? git reset is what you need. Do:

    git branch BRANCH2
    

    if you want BRANCH2 to be a new branch. You can also merge this at the end with another branch if you want. If BRANCH2 already exists, then leave this step out.

    Then do:

    git reset --hard HEAD~3
    

    if you want to reset the commit on the branch you have committed. This takes the changes of the last three commits.

    Then do the following to bring the resetted commits to BRANCH2

    git checkout BRANCH2
    

    This source was helpful: https://git-scm.com/docs/git-reset#git-reset-Undoacommitmakingitatopicbranch

提交回复
热议问题