如何防止使用git automerge? [英] How to prevent an automerge using git?
问题描述
我试图将本地分支合并到主分支中,而不让Git执行自动合并。我想手工挑选我想要合并到master中。
当我使用Git的difftool命令时,我可以区分和选择我想要的被添加到主分支中。但是当我进行合并时,我会失去之前选择的内容,因为Git会执行自动合并。我可以在合并之前将更改提交给master,但这样做似乎不自然。
Git的mergetool仅在合并时发生冲突时可用。但是,如果Git执行automerge,那么通常没有冲突,所以我无法运行mergetool命令。
更新:
我开始认为我想要完成的是不好的做法或者它不可能。也就是说,合并一个主题分支,只有合并我需要的差异。另外,这也反映在历史上。无论如何,当我尝试使用git时,我发布的问题就浮出水面。
你试图做的是绕过Git参与合并过程并手动选择每一行修改后的文件被合并。这与 git cherry-pick
不一样。 git都不会合并--no-commit
等帮助。这里是你需要做的:
$ git checkout master
$ git difftool -t kdiff3 local-branch HEAD
在 KDiff3
窗口,左手边( A
)是你的 local-branch 和右手边( B
)是您的当前分支(主)。
选择合并|从菜单中合并当前文件
(或按下具有相同标题的彩色菱形图标)。
然后,您将显示每个文件的差异和冲突(如果有的话) 。您可以选择左侧或右侧( A
或 B
)或两者,和/或手动调整合并的文件。
在另一个笔记上,有一些事情告诉我您的工作流程存在一些更大的问题。
I am trying to merge a local branch into the master branch without having Git to do an automerge. I would like to "hand pick" what I would like to be merged into master.
When I use Git’s difftool command, I am able to diff and select what I want to be added into the master branch. But then when I do a merge, I will lose what I selected prior because Git will do an automerge. I can commit the changes into master prior to the merge, but doing so seems unnatural.
And Git’s mergetool is only available when there are conflicts from a merge. But if Git does an automerge then usually there aren’t conflicts, so I am unable to run the mergetool command.
Update: I am starting to think what I am trying to accomplish is bad practice or it’s just not possible. That is, to merge a topic branch and only have it merge what I need from diffing. And in an addition, to have this reflected in history. At any rate, the question I posted surfaced when experimenting with git.
What you are trying to do is bypass Git from getting involved in the merge process and to hand-pick each line of each modified file to be merged. This not the same as git cherry-pick
. Neither will git merge --no-commit
, etc. help. Here is what you will need to do:
$ git checkout master
$ git difftool -t kdiff3 local-branch HEAD
In the KDiff3
window, the left hand side (A
) is your local-branch and the right hand side (B
) is your current branch (master).
Select Merge | Merge Current File
from the menu (or press the colorful diamond shaped icon with the same title).
You will then be shown a diff and conflicts (if any) for each file. And you will have the ability to pick left or right side (A
or B
), or both, and/or manually tweak the merged file.
On another note, something is telling me you have some bigger issues with your workflow.
这篇关于如何防止使用git automerge?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!