我从git中的主分支中创建了一个名为newbranch的新分支。现在我已经做了一些工作,想合并新分支来掌握;但是,我对新分支做了一些额外的更改,我想合并新分支到从最后一次提交到master的第四次。

我使用樱桃选择,但它显示的消息使用正确的选项:

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

我可以用git merge来代替它吗?

git merge newbranch <commitid>

当前回答

运行下面的命令到当前分支文件夹,从<commit-id>合并到当前分支,——no-commit不会自动进行新的提交

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

Git merge—continue只能在合并导致冲突后运行。

git merge——abort终止当前的冲突解决进程,并尝试重建合并前的状态。

其他回答

当然,在主分支中你所需要做的就是:

git merge <commit-id>

commit-id是你想在你的主分支中从新分支获得的最后一次提交的哈希值。

你可以通过git help <command>来了解更多关于git命令的信息。在这种情况下,git帮助合并。文档中说merge命令的最后一个参数是<commit>…,因此您可以将引用传递给任何提交,甚至多个提交。不过,我自己从来没有这样做过。

为了保持分支的干净,你可以这样做:

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

这样,newbranch将在它被合并到master的地方结束,你将继续在newbranch2上工作。

合并到提交

我发现这是一种非常可靠的合并到提交的方式。“源”和“目标”分支永远不会被修改(除了“目标”分支上的合并)。

假设你想要合并分支src和分支dst,但只能合并到一个特定的提交id commitId

git checkout src
git branch temp commitId        # create temporary branch at commitId
git switch dst             
git merge temp                     # merge temp branch to dst branch
git branch -d temp                 # remove temp branch as we dont need it anymore.

运行下面的命令到当前分支文件夹,从<commit-id>合并到当前分支,——no-commit不会自动进行新的提交

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

Git merge—continue只能在合并导致冲突后运行。

git merge——abort终止当前的冲突解决进程,并尝试重建合并前的状态。

要合并一个特定的分支到你的主分支,只需这样做:

git reset——hard <commit Id> <——你想要合并的提交