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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:22:52  来源:igfitidea点击:

Merge up to a specific commit

gitgit-mergegit-cherry-pick

提问by Dau

I created a new branch named newbranchfrom the masterbranch in git. Now I have done some work and want to merge newbranchto master; however, I have made some extra changes to newbranchand I want to merge newbranchup to the fourth-from-the-last commit to master.

我创建了一个名为新的分支newbranchmasterGit的分支。现在我已经完成了一些工作并想合并newbranchmaster; 不过,我做出了一些额外的变化newbranch,我想合并newbranch到第四来自该最后承诺master

I used cherry-pickbut it shows the message to use the right options:

我使用过,cherry-pick但它显示了使用正确选项的消息:

git checkout master    
git cherry-pick ^^^^HEAD newbranch

Can I use git mergeto do it instead?

我可以用 gitmerge来代替吗?

git merge newbranch <commitid>

回答by KL-7

Sure, being in masterbranch all you need to do is:

当然,在master分支中您需要做的就是:

git merge <commit-id>

where commit-idis hash of the last commit from newbranchthat you want to get in your masterbranch.

您希望在分支中获得commit-id的最后一次提交的哈希值在哪里。newbranchmaster

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 mergecommand 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。并且文档说mergecommand的最后一个参数是<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-commitdo not make a new commit automatically

在当前分支文件夹中运行以下命令以从此分支合并<commit-id>到当前分支,--no-commit不要自动进行新的提交

git merge --no-commit <commit-id>

git merge --continuecan only be run after the merge has resulted in conflicts.

git merge --continue只能在合并导致冲突后运行。

git merge --abortAbort the current conflict resolution process, and try to reconstruct the pre-merge state.

git merge --abort中止当前的冲突解决过程,并尝试重建合并前的状态。