0

I want to suppress all the output for files in

    dir/* 

when using the command

    git diff

I decided to follow the suggestions from Excluding files from git-diff

Method 1.

Adding to .git/config

[alias]
    mydiff = !git diff -- $(git diff --name-only | grep -Ev "dir/")

and using

git mydiff

worked as expected and thus solved my problem. However, I wanted to use Method 2.

Method 2.

Adding to .gitattributes

dir/* -diff

and then using

git diff

Produces the output

diff --git a/dir/1 b/dir/1
deleted file mode 100644
index 05e9130..0000000
...

Question How to suppress this undesired output for all the files in dir/?

Community
  • 1
  • 1
user1541776
  • 497
  • 4
  • 14

1 Answers1

1

The reason you see output with your settings is that dir/* -diff only marks files in dir as binary files, so text diff would not apply to them (see man 5 gitattributes).

To suppress any output for files in dir you have to define an external diff driver like this:

  1. Assign new "silent" (you can choose your name) diff driver:

    $ cat .gitattributes 
    dir/* diff=silent
    
  2. Define "silent" diff function:

    $ tail -n2 .git/config
    [diff "silent"]
        command = "true"
    

That should do the trick.

artyom
  • 2,390
  • 2
  • 16
  • 18
  • thank you very much! Great example for me that reading man is the right way to do things. The only thing I didn't get is what means "man **5** gitattributes" - 5th page of man? How can I find it? – user1541776 Feb 10 '13 at 05:15
  • 3
    `man 5 gitattributes` explicitly states to use 5th section of manpages. Manpages are grouped into sections by its type: 1 for executable programs or shell commands, 2 for system calls, 3 for library calls, etc. Section 5 contain file formats description. You actually can just type `man gitattributes` and see the same page, but when you have name collisions (i.e. looking manpage for `stat` you should know what you looking for: command (1), syscall (2), library function (3)) you have to specify section to look at. You can tell what section manpage belongs to by looking for number at its header. – artyom Feb 10 '13 at 12:27