Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding files from git-diff

Tags:

git

I am tracking a project with git. There are some Xcode project files in the working copy that I want to keep tracking, but do not want to see in diffs, because there are always dozens of changed lines that I am never interested in. Is there a simple way to have git-diff skip these files? I’ve tried to set up a custom “silent” diff tool:

 $ cat .gitattributes  Project.xcodeproj/* diff=nodiff  $ cat ~/.gitconfig  [diff "nodiff"]     command = /bin/true 

But:

 $ git diff external diff died, stopping at Project.xcodeproj/zoul.mode1v3. 

What am I doing wrong?

like image 268
zoul Avatar asked Jun 19 '09 07:06

zoul


People also ask

What is Git exclude?

The . gitignore file is a text file that tells Git which files or folders to ignore in a project. A local . gitignore file is usually placed in the root directory of a project. You can also create a global .

What is Diffing in Git?

Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

Is Git diff useful?

Diff command is used in git to track the difference between the changes made on a file. Since Git is a version control system, tracking changes are something very vital to it. Diff command takes two inputs and reflects the differences between them. It is not necessary that these inputs are files only.


2 Answers

The problem is that /bin/true will return immediately without reading its input. git diff therefore thinks, quite reasonably, that it has died prematurely.

What you really want to do is to unset the diff attribute, not set it to a bogus command. Try this in your .gitattributes:

Project.xcodeproj/* -diff 
like image 85
CB Bailey Avatar answered Sep 29 '22 13:09

CB Bailey


You may use an alias in your .git/config

[alias]         mydiff = !git diff | filterdiff -x "*/Project.xcodeproj/*" 

You need filterdiff (from patchutils) for this trick.

sudo apt-get install patchutils 

Still the diff isn't perfect, it leaves some garbage :

yannick@yannick-desktop:~/git-filter-test$ git mydiff diff --git a/Project.xcodeproj/dummy.txt b/Project.xcodeproj/dummy.txt index 3e1f9e6..89dfed9 100644 diff --git a/dummy2.txt b/dummy2.txt index 91966ce..d9588a9 100644 --- a/titi.txt +++ b/titi.txt @@ -1,3 +1,3 @@  aaaaaaaaaa -bbbbbbbbb  cccccc +ddd 
like image 42
yanjost Avatar answered Sep 29 '22 14:09

yanjost