7

git commit giving me the following message

*
* You have some suspicious patch lines:
*
* In projects/bong/traid/apps/controller/project.php
* trailing whitespace (line 220)
projects/bong/traid/apps/controller/project.php:220:        
* trailing whitespace (line 223)

What does that mean ?

Neel Basu
  • 12,638
  • 12
  • 82
  • 146

3 Answers3

17

That happens when the file has trailing whitespace, if you run:

git commit --no-verify

it will commit ok. ref

Jack Bracken
  • 1,233
  • 12
  • 23
andrebola
  • 383
  • 2
  • 9
  • 2
    This message can somtimes be the cause of CRLF line endings (Windows) You can replace those with UNIX style line endings using notepad++ Short version: strg+h, extended search, find:\r\n replace \n More details: http://stackoverflow.com/questions/133965/find-crlf-in-notepad – s.Daniel May 05 '12 at 20:58
  • 1
    @s.Daniel the commandline tool `dos2unix` is another simple approach to newline substitution which may be worth considering – Frank Farmer Jan 23 '14 at 23:08
7

I find it disturbing to just deactivate pre-commit altogether. If you have a look at the content of .git/hooks/pre-commit, it also checks for unresolved merge conflicts, and I would like to continue to check for those!

Towards the end of the file it runs some regular expressions that check for spaces at line endings and untidy tab characters. I just commented out these lines so it doesn't look for those, and I got rid of the pre-commit warning problem.


 55     if (s/^\+//) {
 56         $lineno++;
 57         chomp;
 **58         # if (/\s$/) {
 59         # bad_line("trailing whitespace", $_);
 60         # }
 61         # if (/^\s* \t/) {
 62         # bad_line("indent SP followed by a TAB", $_);
 63         # }**
 64         if (/^([])\1{6} |^={7}$/) {
 65         bad_line("unresolved merge conflict", $_);
 66         }
 67     }
Greg Robbins
  • 610
  • 5
  • 9
1

In short, it means that you have trailing white space on the lines mentioned. Trailing white is a bit of an odd choice, and sometimes is a compiler error or other error waiting to happen.

You can either clean up those lines, or you can force the commit just this time by adding the --no-verify flag to your git commit.

Alternatively, you can just turn off this checking by disabling pre-commit hooks, like this: cd .git/hooks/ chmod -x pre-commit

BTW, this answer is extracted from: http://danklassen.com/wordpress/2008/12/git-you-have-some-suspicious-patch-lines/

Joshua D. Boyd
  • 4,808
  • 3
  • 29
  • 44