简体   繁体   English

Git:将提交从master转移到另一个分支

[英]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? 我可以将这些提交(从特定提交开始)移动到另一个分支,并将良好提交保留为master上的最后一次提交吗?

Sure: 当然:

$ 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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