57

I am working on a git repository which contains huge number of files changed b/w one commit to another, how to extract the number of files changes b/w commits.

4
  • Maybe git whatchanged?
    – Kerrek SB
    Commented Jul 5, 2011 at 14:03
  • 1
    @Kerrek SB It looks like a good answer. Why do you put that in comment and not as an answer? I'm sorry, sometimes I just don't get it.
    – SteeveDroz
    Commented Jul 5, 2011 at 14:08
  • @Oltarus: OK, done :-) Didn't seem big enough to warrant an answer, and I'm not sure if it really meets the needs. After checking some docs, though, it seems that it does!
    – Kerrek SB
    Commented Jul 5, 2011 at 14:12
  • For more recent visitors, with newer git versions, the following will more or less give you the information that OP was looking for: git show --oneline --name-only commit_hash_a..commit_hash_b This of course will also print the commit message along with the file list. But good enough for simple use-cases.
    – sdevikar
    Commented Apr 20, 2023 at 15:45

5 Answers 5

79

EDIT: "this will always count the files plus one, cause the --format=oneline includes the commit-hash/header" as mentioned by c00kiemon5ter


The git whatchanged tool shows you a summary of files that were modified. By itself it lists all commits, but you can also limit it to just the recent n commits:

git whatchanged -1

To count files:

git whatchanged -1 --format=oneline | wc -l

See git help whatchanged for details.

5
  • 8
    note that this will always count the files plus one, cause the --format=oneline includes the commit-hash/header. Commented Jul 5, 2011 at 14:14
  • 2
    git whatchanged -1 --format=oneline | tail -n +2 | wc -l
    – Bobby Jack
    Commented Dec 1, 2014 at 17:52
  • 5
    From man git-whatchanged; "The command is kept primarily for historical reasons." "New users are encouraged to use git-log(1) instead." Commented Oct 27, 2016 at 17:56
  • 9
    @StéphaneGourichon: This answer is kept primarily for historical reasons. New users are encouraged to find a different answer instead :-)
    – Kerrek SB
    Commented Oct 27, 2016 at 20:33
  • Since OP seems to have asked about getting number of changed files for all commits and not just one, the following answer seems to be fitting: stackoverflow.com/a/40777727/2184166
    – ob-ivan
    Commented Feb 24, 2023 at 10:13
33

Apart from the above listed methods you can do this too:

git diff HEAD^..HEAD --name-only - will give the list of files changed between HEAD and one revision before HEAD (HEAD^). You can replace HEAD^ with a SHA1 of the "from" commit and HEAD with the SHA1 of the "to" commit:

git diff <SHA1-of-from-commit>..<SHA1-of-to-commit> --name-only

So if you pipe the output to wc -l it should give you the number of files changed between commits.

3
  • 1
    Much more useful to be able to count files between arbitrary commits - not just the files changed in a single commit. Note that it also works with branch names and tags (and of course other commit shorthands in addition to HEAD and HEAD^) Commented Aug 25, 2017 at 23:59
  • This definitely helped when I was looking for the total files changed between my branch and master. git diff master..HEAD
    – TbWill4321
    Commented Feb 4, 2020 at 18:38
  • I was looking to count the files changed between two branches. This was the most helpful answer. The command I ended up with was git diff master..HEAD --name-only --oneline --stat | wc -l.
    – dx_over_dt
    Commented Jul 30, 2021 at 18:37
28
git show --stat

This gives the list of files changed like this:

1 file changed, 1 insertion(+), 1 deletion(-)

Optionally you can add the commit code if you don't want to get the information from the latest.

git show --stat {commit code without brackets}
1
  • 5
    Use --shortstat to get straight to the point: git show --shortstat <hash>. See git-scm.com/docs/git-show for more options.
    – Nolan Amy
    Commented Dec 1, 2020 at 8:14
14

use this:

git log --oneline --name-status <HASH> -1

eg:

$ git log --oneline --name-status bb3ae49 -1
M       .vim/spell/en.utf-8.add
M       .vim/spell/en.utf-8.add.spl

this works just like

git whatchanged --oneline --name-status <HASH> -1
1
  • 1
    This should be the accepted answer, since using git whatchanged is discouraged. Commented Nov 9, 2017 at 13:48
2

In windows:

git whatchanged -1 --format=oneline | find /v /c ""

The important windows-specific piece is that you must replace the wc command used in other solutions with this:

  | find /v /c ""

Not the answer you're looking for? Browse other questions tagged or ask your own question.