Sometimes, when I do git pull origin master from a local branch, I get merge conflicts like:
<<<<<<HEAD
======
>>>>>>xxxxxx
Run Code Online (Sandbox Code Playgroud)
How to avoid that ? Maybe it is due to some white spaces, so I tried to put a .gitattributes file containing * -whitespace but that didn't solve the problem.
在这种情况下,您会有空白差异。Git认为空白差异很重要。(如果不是这种情况,那么……假设维护一个用Whitespace编写的程序。)
你的评论:
...然后是
git merge -s recursive -Xignore-space-change origin/master。这行得通,这次我没有任何冲突。
确认冲突仅与空格有关。自-X变量(我称这些扩展自变量,X代表eXtended)ignore-space-change告诉Git,在合并期间,如果您的更改和它们的更改(除了空格)相同,则这实际上不是冲突。
文档中介绍了这四个扩展选项的确切规则:
ignore-space-change
ignore-all-space
ignore-space-at-eol
ignore-cr-at-eol为了进行三向合并,将具有指定空白类型更改的行视为未更改。空格更改与行的其他更改混合在一起将不被忽略。另见 GIT-DIFF [1] ,
-b,-w,--ignore-space-at-eol和--ignore-cr-at-eol。
如果他们的版本仅对行进行空白更改,则使用我们的版本;
如果我们的版本引入了空白更改,但其 版本包含实质性更改,则使用其版本;
否则,合并将以常规方式进行。
请注意,您通常可以将该命令的拼写简化为:
git merge -X ignore-space-change
Run Code Online (Sandbox Code Playgroud)
的-s recursive是默认的,并且origin/master据推测已经被设置为当前分支的上游master,使这也是默认的。
(-X其参数之间的空格是可选的,但我更喜欢使用它。)
| 归档时间: |
|
| 查看次数: |
41 次 |
| 最近记录: |