I have this command
git merge -Xignore-all-space origin/dev
scares me a little bit b/c I am afraid of merging a file where whitespace matters. Is there a way to limit it to certain files, something like this:
git merge -Xignore-all-space *.js origin/dev
The git-merge docs explain quite well how this will affect your 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.
3-way merges use a dedicated commit to tie together the two histories. The nomenclature comes from the fact that Git uses three commits to generate the merge commit: the two branch tips and their common ancestor.
Recursive is the default merge strategy when pulling or merging one branch. Additionally this can detect and handle merges involving renames, but currently cannot make use of detected copies. This is the default merge strategy when pulling or merging one branch.
Instead, Git uses an algorithm to determine what bits of a file have changed and if any of those bits could represent a conflict. For simple text files, Git uses an approach known as the longest common subsequence algorithm to perform merges and to detect merge conflicts.
Anytime you want to set a configuration per file extension, a good place to start is gitattributes
.
In a .gitattributes
files, you can set a directive per file, or per file extension.
However, the *.js -whitespace I mentioned in 2009 might not apply during a merge.
Since ignore-all-space
is first a git diff
option, you might need to set up a diff driver in a .gitattributes
(again, only for *.js
files), emulating --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.
For example (to be tweaked in order to match what you need in a javascript file for a diff without spaces)
*.js diff=js
[diff "js"]
wordRegex = "[^[:space:]]+"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With