如何防止使用Git自动合并? [英] How do I prevent an automerge using Git?
问题描述
我正在尝试将本地分支合并到master分支中,而无需Git进行自动合并.我想手工挑选"我想合并到母版中的内容.
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.
使用Git的difftool命令时,我可以进行比较并选择要添加到master分支中的内容.但是,当我进行合并时,我将丢失之前选择的内容,因为Git会进行自动合并.我可以在合并之前将更改提交到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.
只有在合并冲突时,Git的mergetool才可用.但是,如果Git执行自动合并,则通常不会发生冲突,因此我无法运行mergetool命令.
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.
更新:
我开始认为我要实现的目标是错误的做法,或者根本不可能.也就是说,要合并一个主题分支,并且只让它合并我从比较中需要的东西.另外,要在历史中体现这一点.无论如何,我在尝试Git时提出的问题浮出水面.
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.
推荐答案
您正试图绕过Git参与合并过程,并手动选择要合并的每个已修改文件的每一行.这与git cherry-pick
不同. git merge --no-commit
等都无济于事.您需要执行以下操作:
You are trying to 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. You will need to do:
$ git checkout master
$ git difftool -t kdiff3 local-branch HEAD
在 KDiff3
窗口中,左侧(A
)是您的本地分支,右侧(B
)是您的当前分支(主分支).
In the KDiff3
window, the left hand side (A
) is your local-branch and the right hand side (B
) is your current branch (master).
从菜单中选择Merge | Merge Current File
(或按具有相同标题的彩色菱形图标).
Select Merge | Merge Current File
from the menu (or press the colorful diamond shaped icon with the same title).
然后您将看到每个文件的差异和冲突(如果有).您将可以选择左侧或右侧(A
或B
)或两者,和/或手动调整合并的文件.
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自动合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!