Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppressing diffs for deleted files in git

I want to get a quick overview of the local changes in my repository, but I don't want a diff that shows deleted files, since every single line is a minus.

Basically, I want something like 'git diff HEAD <list of modified files only>'. In an ideal world, it would be preceded by the list of deleted and added files, but not show the diffs within them.

I was most of the way through writing a utility that does this:

git diff HEAD `git status | grep modified | cut -d : -f 2` 

when I wondered if there was some git-y way to do it instead. Is there a flag I'm missing? I'd love to preserve the color output, too.

like image 292
Alex Feinman Avatar asked Sep 11 '10 18:09

Alex Feinman


People also ask

Does git diff show deleted files?

You can use git diff --name-status, that will show you files that where added, modified and deleted.

What happens to deleted files in git?

Git keeps a log of all the changes made to files within a repository. You can restore a file that you have deleted since a previous commit by using the git checkout command. This command lets you navigate to a previous point in your repository's history.

Does git add include deleted files?

Add All Files using Git Add. The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area.

What is -- cached in git diff?

git diff --cached: It shows only those changes of tracked files which are present in staging area. git diff HEAD: It shows all changes of tracked files which are present in working directory and staging area.


2 Answers

In Git versions 1.8.5 and newer, you can do this using the --diff-filter option and specifying "d" (lowercase) to tell it to exclude deleted files.

 $ git diff --diff-filter=d 

In Git versions older than 1.8.5, you can do this with the --diff-filter option and specifying all but the "D" (deleted) criteria:

 $ git diff --diff-filter=ACMRTUXB 
like image 195
Dan Moulding Avatar answered Oct 09 '22 16:10

Dan Moulding


git diff -D (or equivalently git diff --irreversible-delete) will omit the diff body for deleted files. I don't think there's an equivalent for added files.

like image 38
Max Nanasy Avatar answered Oct 09 '22 17:10

Max Nanasy