在不同的分支上重放最后 N 次 git 提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/973268/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Replay the last N git commits on a different branch
提问by Tom Lehman
I accidentally made 10 commits on branch "testing" when I intended to commit them on branch "master". The other commits on the "testing" branch are garbage, so I don't want to merge it with "master". Instead, I just want to replay the last 10 commits on master.
当我打算在分支“master”上提交它们时,我不小心在分支“testing”上做了 10 次提交。“testing”分支上的其他提交是垃圾,所以我不想将它与“master”合并。相反,我只想重播 master 上的最后 10 次提交。
采纳答案by Ron
- git checkout master
- git whatchanged testing
- git cherry-pick _________
- git 结帐大师
- git whatchanged 测试
- git 挑选 _________
?
?
回答by Talljoe
Rebase should do it.
Rebase 应该这样做。
git rebase -p --onto master testing~10 testing
This will copy the last ten commits on testing to master and make that the new testing (the old testing will be an orphan). Then you can merge master to testing as a fast-forward.
这会将测试的最后十次提交复制到 master 并使新测试成为新测试(旧测试将是孤立的)。然后你可以将 master 合并到 test 作为快进。
git checkout master
git merge testing
回答by Tim
As said in comments, the rebase
-inspired answer is leaving the 'garbage' commits orphaned.
正如评论中所说,rebase
受启发的答案是让“垃圾”提交成为孤儿。
Just use simple tools:
只需使用简单的工具:
git checkout master
git merge testing
git checkout testing
git reset --hard HEAD~10 # Go back 10 commits (*1)
git checkout master
(*1) You will only be "losing" commits from the testing
branch, since you'll have those commits in master
thanks to the merge
.
(* 1)您只可以“丢失”从提交testing
分支,因为你必须在这些提交master
感谢merge
。