Git: moving commits from master to another branch
I made a series of commits after a good commit on the master branch, which in hindsight I should have made in another branch. Can I move those commits, beginning with a specific commit, to another branch, and keep the good commit as the last commit on master?
当然:
$ git branch new-branch-name # Create a new branch from the current commit
$ git reset --hard <last good commit on master> # Reset master to the good commit
Yes, you can, and that would be 2 separate operations :
Copy the commits from one branch to the branch you want them to be:
git cherry-pick <hash_of_commit> --onto <target_branch>
Then fix the master branch reverting to a good commit:
git checkout master
git reset --hard <hash_of_good_commit>
链接地址: http://www.djcxy.com/p/4306.html
上一篇: Git reset =致命:无法读取树
下一篇: Git:将提交从主控移动到另一个分支