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

时间:2011-10-21 19:09:42

标签: git

我在master分支上做了一个很好的提交后做了一系列的提交,事后我应该在另一个分支中做出来。我可以将这些提交(从特定提交开始)移动到另一个分支,并将良好提交保留为master上的最后一次提交吗?

2 个答案:

答案 0 :(得分:25)

不确定

$ 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

答案 1 :(得分:1)

是的,你可以,那将是 2个单独的操作

将提交从一个分支复制到您希望它们的分支:

git cherry-pick <hash_of_commit> --onto <target_branch>

然后修复 master 分支,恢复为良好的提交:

git checkout master
git reset --hard <hash_of_good_commit>
相关问题