Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to exclude file from "git diff"

Tags:

git

git-diff

diff

I am trying to exclude a file (db/irrelevant.php) from a Git diff. I have tried putting a file in the db subdirectory called .gitattributes with the line irrelevant.php -diff and I have also tried creating a file called .git/info/attributes containing db/irrelevant.php.

In all cases, the db/irrelevant.php file is included in the diff as a Git binary patch. What I want is for the changes to that file to be ignore by the diff command. What am I doing wrong?

like image 482
Michael Avatar asked May 02 '12 13:05

Michael


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 .

How do I terminate Git diff?

To exit this you can use: :q for exit; :h for help; Note: if you don't want to read the output in pager you can use an ENV variable GIT_PAGER to cat or you need to set core.

Does Git diff use diff?

Comparing changes with git diffgit 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.


1 Answers

Omg, drivers and awk to exclude a lousy file ? Since git 1.9 something you can:

git diff -- . ':(exclude)db/irrelevant.php' ':(exclude)db/irrelevant2.php' 

(On Winodws, replace the single quotes ' by double quotes ".)

Ah, elegance! See the quoted answer and for details this answer by @torek

like image 170
Mr_and_Mrs_D Avatar answered Sep 30 '22 16:09

Mr_and_Mrs_D