Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter git diff by type of change

Tags:

git

diff

You are looking for --diff-filter=M to show only files *M*odified between the two branches.

From man git-diff

--diff-filter=[ACDMRTUXB*]

Select only files that are

  • A Added
  • C Copied
  • D Deleted
  • M Modified
  • R Renamed
  • T have their type (mode) changed
  • U Unmerged
  • X Unknown
  • B have had their pairing Broken
  • * All-or-none

Any combination of the filter characters may be used.

When * (All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing is selected.


As Git 2.10 (Q3 2016) will remind us, there is an easier way to "show everything except added/deleted files." (actually since Git 1.8.5, July 2013)

 git diff --diff-filter=ad master..

See commit 16726cf (14 Jul 2016) by Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit 2f8c654, 08 Aug 2016)

diff: document diff-filter exclusion

In v1.8.5 days, 7f2ea5f (diff: allow lowercase letter to specify what change class to exclude, 2013-07-17) taught the "--diff-filter" mechanism to take lowercase letters as exclusion, but we forgot to document it.

So the documentation on diff-options now (finally) includes:

These upper-case letters can be downcased to exclude.
E.g. --diff-filter=ad excludes added and deleted paths.


You can use the --diff-filter flag to do precisely this. git diff --diff-filter=CMRTUXB master.. should show everything except added/deleted files.


To see all modified and new files you can use

git diff --name-only --diff-filter=ACMR PREV_VERSION master

PREV_VERSION is the hash of your first commit.

To get an export as zip you can use this code

git archive --output=export.zip HEAD $(git diff --name-only --diff-filter=ACMR PREV_VERSION HEAD)

Note: .gitignore is not in export.zip