我已经完成了一些类似的 SOQ,但没有找到适合这种情况的解决方案。
我注意到在许多文件中混用了用于缩进的制表符和空格。我们遵循的编码标准目前使用 4 个空格作为制表符。
虽然这应该在它发生时得到解决,但我现在需要考虑它并希望修复我遇到的文件。问题是有两个团队使用不同的代码分支,我们最终将不得不 merge 这些分支。如果我们将分支的所有文件更改为正确的格式并尝试 merge 它,会发生什么?最终会很难做到吗?它会向我展示大量的冲突吗?理想情况下,id 像 git merge 一样忽略空格,但我不知道它如何知道选择哪个版本。
从 react 的角度来看是否有更好的解决方案?
这主要是技术领导、代码 lint、代码审查问题,但我目前不在那个位置或案例中。我可以轻松解决这个问题吗? (不幸的是,让违规者处理 merge 是不可能的!)
最佳答案
默认情况下,git 会将行缩进中的每个差异视为更改,所以是的,您很可能会在进行股票 merge 时遇到大规模冲突。
但是您可以选择 merge 策略以与 -s
选项一起使用:
git merge -s recursive -Xignore-space-change
此命令将使用递归策略并使用它的 ignore-space-change
选项。 git-merge docs很好地解释这将如何影响您的 merge :
- 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
在使用带有一些额外选项的 diff 进行 merge 之前,先看看 git 认为发生了什么变化也是明智的。翻看diff docs看起来这些选项最能帮助您:
-b
--ignore-space-change Ignore changes in amount of whitespace. This ignores whitespace at line end, and considers all other sequences of one or more whitespace characters to be equivalent.-w
--ignore-all-space Ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none.
关于Git merge 和修复带有两个分支的混合空间和制表符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5256769/