4

As a front end developer, I frequently add code to hide backend devs' error messages ;)

Is there a way of getting git to ignore code commented in a certain way? eg

.error { display:none; } // DEBUG-GIT-PLEASE-IGNORE

Or has someone written a plugin for this?

Jake Rayson
  • 921
  • 7
  • 20
  • Looks like a common use case for a git hook, that completely denies commits with debug code. – KingCrunch Jun 15 '12 at 13:56
  • http://stackoverflow.com/questions/6557467/can-git-ignore-a-specific-line – vergenzt Jun 15 '12 at 13:59
  • @vergenzt "better to have a config file per deployment target and some runtime parameter for however you are starting the server" -- I read this but don't know what it means or how to do it! – Jake Rayson Jun 15 '12 at 14:08
  • I think that part of the answer related to the specific web application, not git. – vergenzt Jun 15 '12 at 14:16

2 Answers2

3

You can create a clean filter, which drops all lines containing DEBUG-GIT-PLEASE-IGNORE.

But a more clean way is to change the web application, so that this behavior can be configured on the web host.

Rudi
  • 19,366
  • 3
  • 55
  • 77
  • Thanks Rudi. Seems you can either ignore whole file with [hooks](http://git-scm.com/book/en/Customizing-Git-Git-Hooks) via @[KingCrunch](http://stackoverflow.com/users/421223/kingcrunch) (in which case have to remove debug code when committing) or you can use a [filter](https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html)to drop all debug lines. But why is the second method considered "unclean"? – Jake Rayson Jun 18 '12 at 12:55
  • The main problem is, that in the repository goes different code than what is in the working copy. This can lead to subtle bug. Say there is one line with two statements, where the first one is real code, while the second one is debug code. With the clean filter both statements will be cut out, leaving a file in the repo without the wanted statement. – Rudi Jun 18 '12 at 21:29
0

Essentially, no. Git does not currently have a way to ignore particular parts of a file, only whole files.

However, one could probably write a script to modify the output from git diff, and configure git to use that script. I'm not sure how effective that would be, as I don't think git uses the diff to stage files, but it may be worth researching.

vergenzt
  • 9,669
  • 4
  • 40
  • 47