我有这个命令
git merge -Xignore-all-space origin/dev
让我有点害怕 b/c 我害怕 merge 一个空格很重要的文件。有没有办法将它限制在某些文件中,像这样:
git merge -Xignore-all-space *.js origin/dev
最佳答案
任何时候你想为每个文件扩展名设置一个配置,一个好的起点是 gitattributes
.
在 .gitattributes
文件,您可以为每个文件或每个文件扩展名设置一个指令。
但是,*.js -whitespace I mentioned in 2009在 merge 期间可能不适用。
自从 ignore-all-space
首先是 git diff
option ,您可能需要设置 diff driver在 .gitattributes
(同样,仅适用于 *.js
文件),模拟 --word-diff-regex
Use
<regex>
to decide what a word is, instead of considering runs of non-whitespace to be a wordEvery non-overlapping match of the is considered a word. Anything between these matches is considered whitespace and ignored(!) for the purposes of finding differences.
You may want to append
|[^[:space:]]
to your regular expression to make sure that it matches all non-whitespace characters. A match that contains a newline is silently truncated(!) at the newline.
例如(进行调整以匹配您在 javascript 文件中对不带空格的差异所需的内容)
*.js diff=js
[diff "js"]
wordRegex = "[^[:space:]]+"
关于javascript - merge 时仅忽略某些文件扩展名的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49143341/