空合并冲突
Empty merge conflicts
有时,当我从本地分支执行 git pull origin master
时,我会遇到合并冲突,例如:
<<<<<<HEAD
======
>>>>>>xxxxxx
如何避免?可能是因为有些空格,所以我尝试放入一个包含 * -whitespace
的 .gitattributes
文件,但这并没有解决问题。
在这种情况下,您有白色-space 差异。 Git 认为白色 space 差异显着。 (如果不是这种情况,那么......想象维护一个用 Whitespace 编写的程序。)
您的评论:
... followed by git merge -s recursive -Xignore-space-change origin/master
. This worked and I got no confict this time.
确认冲突仅与白色space有关。 -X
论点——我称这些 扩展论点 ,X
代表 eXtended)——ignore-space-change
告诉Git,在合并过程中,如果你的更改和他们的更改相同,除了白色space,这不是真正的冲突。
这四个扩展选项的具体规则在the documentation:
中描述
ignore-space-change
ignore-all-space
ignore-space-at-eol
ignore-cr-at-eol
Treats lines with the indicated type of whitespace change as
unchanged for the sake of a three-way merge. Whitespace changes
mixed with other changes to a line are not ignored. See also
git-diff[1] -b
, -w
, --ignore-space-at-eol
, and
--ignore-cr-at-eol
.
If their version only introduces whitespace changes to a
line, our version is used;
If our version introduces whitespace changes but their
version includes a substantial change, their version is
used;
Otherwise, the merge proceeds in the usual way.
请注意,您通常可以将此命令更简单地拼写为:
git merge -X ignore-space-change
-s recursive
是默认值,origin/master
可能已经设置为当前分支 master
的上游,因此这也是默认值。
(-X
和它的参数之间的 space 是可选的,但我更喜欢使用它。)
有时,当我从本地分支执行 git pull origin master
时,我会遇到合并冲突,例如:
<<<<<<HEAD
======
>>>>>>xxxxxx
如何避免?可能是因为有些空格,所以我尝试放入一个包含 * -whitespace
的 .gitattributes
文件,但这并没有解决问题。
在这种情况下,您有白色-space 差异。 Git 认为白色 space 差异显着。 (如果不是这种情况,那么......想象维护一个用 Whitespace 编写的程序。)
您的评论:
... followed by
git merge -s recursive -Xignore-space-change origin/master
. This worked and I got no confict this time.
确认冲突仅与白色space有关。 -X
论点——我称这些 扩展论点 ,X
代表 eXtended)——ignore-space-change
告诉Git,在合并过程中,如果你的更改和他们的更改相同,除了白色space,这不是真正的冲突。
这四个扩展选项的具体规则在the documentation:
中描述
ignore-space-change
ignore-all-space
ignore-space-at-eol
ignore-cr-at-eol
Treats lines with the indicated type of whitespace change as unchanged for the sake of a three-way merge. Whitespace changes mixed with other changes to a line are not ignored. See also git-diff[1]
-b
,-w
,--ignore-space-at-eol
, and--ignore-cr-at-eol
.
If their version only introduces whitespace changes to a line, our version is used;
If our version introduces whitespace changes but their version includes a substantial change, their version is used;
Otherwise, the merge proceeds in the usual way.
请注意,您通常可以将此命令更简单地拼写为:
git merge -X ignore-space-change
-s recursive
是默认值,origin/master
可能已经设置为当前分支 master
的上游,因此这也是默认值。
(-X
和它的参数之间的 space 是可选的,但我更喜欢使用它。)