Git Merge and Fixing Mixed Spaces and Tabs with two Branches

后端 未结 4 1976
失恋的感觉
失恋的感觉 2020-12-02 08:34

I\'ve gone through some similar SOQ\'s and have not seen an adequate solution for this case.

I\'ve noticed that in many files there is a dirty mix of tabs and spaces

4条回答
  •  旧时难觅i
    2020-12-02 08:51

    By default git will see each difference in a line's indentation as a change, so yes you're likely to end up with mass conflicts doing a stock merge.

    However you can choose the merge strategy to use with the -s option:

    git merge -s recursive -Xignore-space-change
    

    This command would use the recursive strategy and uses it's ignore-space-change option. 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

    It would also be prudent to look at what git thinks has changed before doing the merge using diff with some extra options. Looking through the diff docs it looks like these options would help you out the most:

    -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.

提交回复
热议问题