git 合并到特定的提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8223103/
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
Merge up to a specific commit
提问by Dau
I created a new branch named newbranch
from the master
branch in git. Now I have done some work and want to merge newbranch
to master
; however, I have made some extra changes to newbranch
and I want to merge newbranch
up to the fourth-from-the-last commit to master
.
我创建了一个名为新的分支newbranch
从master
Git的分支。现在我已经完成了一些工作并想合并newbranch
到master
; 不过,我做出了一些额外的变化newbranch
,我想合并newbranch
到第四来自该最后承诺master
。
I used cherry-pick
but it shows the message to use the right options:
我使用过,cherry-pick
但它显示了使用正确选项的消息:
git checkout master
git cherry-pick ^^^^HEAD newbranch
Can I use git merge
to do it instead?
我可以用 gitmerge
来代替吗?
git merge newbranch <commitid>
回答by KL-7
Sure, being in master
branch all you need to do is:
当然,在master
分支中您需要做的就是:
git merge <commit-id>
where commit-id
is hash of the last commit from newbranch
that you want to get in your master
branch.
您希望在分支中获得commit-id
的最后一次提交的哈希值在哪里。newbranch
master
You can find out more about any git command by doing git help <command>
. It that case it's git help merge
. And docs are saying that the last argument for merge
command is <commit>...
, so you can pass reference to any commit or even multiple commits. Though, I never did the latter myself.
您可以通过执行 来了解有关任何 git 命令的更多信息git help <command>
。就是这种情况git help merge
。并且文档说merge
command的最后一个参数是<commit>...
,因此您可以传递对任何提交甚至多个提交的引用。不过,我自己从来没有做过后者。
回答by tkruse
To keep the branching clean, you could do this:
为了保持分支干净,你可以这样做:
git checkout newbranch
git branch newbranch2
git reset --hard <commit Id> # the commit at which you want to merge
git checkout master
git merge newbranch
git checkout newbranch2
This way, newbranch will end where it was merged into master, and you continue working on newbranch2.
这样,newbranch 将在它合并到 master 的地方结束,您将继续在 newbranch2 上工作。
回答by ElasticCode
Run below command into the current branch folder to merge from this <commit-id>
to current branch, --no-commit
do not make a new commit automatically
在当前分支文件夹中运行以下命令以从此分支合并<commit-id>
到当前分支,--no-commit
不要自动进行新的提交
git merge --no-commit <commit-id>
git merge --continue
can only be run after the merge has resulted in conflicts.
git merge --continue
只能在合并导致冲突后运行。
git merge --abort
Abort the current conflict resolution process, and try to reconstruct the pre-merge state.
git merge --abort
中止当前的冲突解决过程,并尝试重建合并前的状态。