When using git diff
, how can I ignore changes which start with #
?
For normal diff
command, I would use something like:
diff <(grep -v '^#' file1) <(grep -v '^#' file2)
But none of the suggested solutions below work!
Is there really no way to see git diff
with comments omitted?
UPDATE:
I tries this in my .gitconfig
:
[pager]
cdiff = diff-highlight
[alias]
cdiff = "diff -w --ignore-blank-lines -I'^#'"
When I do git cdiff
, I get this error:
error: invalid option: -I^#
UPDATE2:
this is so frustrating. The syntax git diff -G'^[^#]'
does not work reliably. Example:
$ cat 1.txt
aaa
bbb
ccc
ddd
eee
fff
ggg
hhh
iii
jjj
initialize new git repo:
$ git init && git add . && git commit -m "initial commit" -a
add only comment on top of file:
$ cat 1.txt
# comment
aaa
bbb
ccc
ddd
eee
fff
ggg
hhh
iii
jjj
so far, it works as expected. git diff -G'^[^#]'
does not show the comment as change. But if I add a real change at the last line, and then do git diff -G'^[^#]'
again, it then shows the added last line (as it should), but also the first line comment which it did not show before.
So basically, as soon as I add any non-comment change, git shows everything, even comments.
[[0;0m
instead of"\033[0m"
-I'^#'
with-G'^[^#]
' ?diff
.