I mean, I want GIT to disregard modifications like these when listing files for the commit with git status.
I understand that you would like this behavior after doing some kind of merge with a branch in which the standardization of spaces used is different from your.
Although it is possible to do this "git status" by ignoring the space differences, using a git diff
(untested example: git diff -w | git apply --cached --ignore-whitespace
), Solving your problem starts when branches merge.
Unfortunately it is not possible to simply skip file spaces. A file with 2 spaces is different from a file with 4 spaces inside git, as they generate different hashs. When git sees this situation in a merge, it remains for it to try to merge or show the problem (in conflict form).
However, you can make it resolve this merge for you automatically by "ignoring" this space problem. Note that in this case you’re not really ignoring, you’re just telling git what to do in this case.
For this, at the time of the merge, use the flag -Xignore-space-change
:
git merge -s recursive -Xignore-space-change
The -Xignore-space-change
here is explained as follows, by documentation, how it affects your merge:
- If its version only introduces space changes to the line, its version is used.
- If your version introduces space changes but its version includes a substantial amount of changes, its version is used.
- Otherwise, the merge follows normally.
Finally
In addition, if your friend likes 2 spaces and you like 4 spaces, and you can’t reach an agreement, you can consider a change to tabulation per tab, then each of you chooses the size of the tab by the IDE, better solving this question of how they prefer to view the code.
Yeah, that’s all I wanted to say :P
– Maniero
@Maniero wants me to add "How to do this"? kkkkkk
– Wallace Maxters
You do not want the files in question to be listed when you use
git status
but wants them to be part ofcommit
? I don’t know if there’s any way to do it... While my suggestion doesn’t work for everyone but my team is using tools like google-java-format in the Jenkins pipeline. After merging a PR, Jenkins commits to format the code. Works well despite taking some fine control of the devs.– Anthony Accioly
@Example anthonyaccioly: if I give that
git commit -am
that picks up the files, I would like to ignore those who had whitespace– Wallace Maxters
Just for real: I think space or tabs are characters, edits in Git won’t necessarily go to releases and the like, so I think a code organization, like: Today I use 3 spaces for bar, but I think 4 four is better, is a valid edition is something that can be shared among all developers, even change something from
if(){
forif () {
. I notice a lot of people worrying about Git’s history, but I think any minimal action can be solved and shared. So to conclude:– Guilherme Nascimento
About the characters, even if minimum is interesting share to avoid problems with the "DIFF"
– Guilherme Nascimento
@Wallacemaxters, in the
git status
will appear only your modified files, respecting your spacing. I did not understand how would appear the spacing of your colleague in this case. You’re not talking about merging with spacing conflict and "ignoring" it ongit status
?– Dherik