'How to make git ignore comments in file?
I have a problem while trying to commit and sometimes a comment have slightly changed in some way (eg different number of spaces like // Text
compared //Text
). This is annoying and I would like to know if there is a way to make git ignore commented lines. Since git may be unaware of file type, language and so on, I guess I could restrict myself to ignore changes in lines containing //
. My guess is that I could add some kind of rule for diff to ignore this, but there is another problem as well. How do I make git understand that these lines are supposed to be ignored in a comparison and still included in the repo?
EDIT As far as I know, this was done in svn. They had some smart implementation for this. My question is if there are something similar for git.
Solution 1:[1]
Not specific to comments, but Git has an option to ignore space changes during the merge. See e.g. Merging without whitespace conflicts and http://git-scm.com/docs/git-merge.
Solution 2:[2]
I think that is not advisable. Consider two people are working on a comment simultaneously. Git should raise conflict. If you ignore comments, what do you expect git to do in that case? Besides, different programming languages have different syntax for comments. It would be little troublesome for git to identify comments.
You can definitely ignore space -w
arguments to git.
Example:-
git diff -w .
Solution 3:[3]
I don't know if you can make git
ignore the changes in the comments, this defeats the purpose of VCSs.
But you can use a smart comparison program that knows the lexical rules of several programming languages (or can be taught them) and is able to either ignore the changes in comments or show them as unimportant.
BeyondCompare is such a program.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Community |
Solution 2 | |
Solution 3 | axiac |