Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore files from 'git status' if only white spaces and line breaks changed

Tags:

git

I often push code with some tab instead of spaces or vice versa, or insert a line break to improve code readability. How do I tell git not to look for those changes?

like image 543
dinigo Avatar asked Oct 19 '13 15:10

dinigo


People also ask

How to make git ignore whitespace changes?

For diff and blame, you can ignore all whitespace changes with -w : git diff -w , git blame -w . For git apply and git rebase , the documentation mentions --ignore-whitespace . For merge, it looks like you need to use an external merge tool.

Does git ignore line endings?

By default, core. autocrlf is set to false on a fresh install of Git, meaning Git won't perform any line ending normalization. Instead, Git will defer to the core. eol setting to decide what line endings should be used; core.

Does git status show ignored files?

If a directory matches an ignore pattern, then it is shown, but not paths contained in the ignored directory. If a directory does not match an ignore pattern, but all contents are ignored, then the directory is not shown, but all contents are shown.

What is git status porcelain?

" git status --branch --porcelain " displays the status of the branch (ahead, behind, gone), and used gettext to translate the string. Use hardcoded strings when --porcelain is used, but keep the gettext translation for " git status --short " which is essentially the same, but meant to be read by a human.


1 Answers

I could not find a native git solution for identifying what really changed using git status but the following one-liner works well under linux:

for m in $(git status | grep modified| awk '{print $2}');do test -z "$(git diff -w $m)" || echo $m;done

The result will be a list of modified files excluding files with only whitespace changes.

This is especially useful before writing commit messages when you want to see only the files with real edits which is often a problem when moving back and forth between windows and linux systems. If you have control of both systems then configuring whitespace settings in git may be a cleaner solution.

like image 148
chriskelly Avatar answered Oct 11 '22 05:10

chriskelly