3

I have a merge tool which unfortunately removes newlines at the end of the files. So after I've used this tool, I need to check if any of the files in the Git index have their trailing newlines removed.

git diff --cached displays these trailing newline removals, but it also prints the full diff. I'd like to get a more concise view which only lists the file names of the changed files in the Git index which are lacking the trailing newline.

I tried to combine git diff --name-only and git grep, but I can't find the a regular expression to detect files without newline at the end of file. Expressions including \Z don't seem to be recognized by git grep even with extended regular expressions (-E).

oberlies
  • 11,503
  • 4
  • 63
  • 110
  • sounds like you need to tell your merge tool to stop doing that. Does it have an option to control that behaviour? – glenn jackman Dec 23 '14 at 17:33
  • This is a bit off-topic, but if you are interested, I'm having this problem because [TortoiseSVN stopped shipping recent versions of TortoiseMerge as standalone tool](http://tortoisesvn.tigris.org/ds/viewMessage.do?dsForumId=4061&dsMessageId=2876076) – oberlies Dec 23 '14 at 18:15
  • You might want to check out meld: http://meldmerge.org/ – glenn jackman Dec 23 '14 at 18:33

1 Answers1

0

Combining the answer to this related question with some Bash magic eventually got me to this solution:

for file in $(git diff --cached --name-only); do test $(tail -c 1 $file) && echo $file; done
Community
  • 1
  • 1
oberlies
  • 11,503
  • 4
  • 63
  • 110