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.
-
Maybe `git whatchanged`? – Kerrek SB Jul 05 '11 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 Jul 05 '11 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 Jul 05 '11 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 Apr 20 '23 at 15:45
5 Answers
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.
-
8note that this will always count the files plus one, cause the `--format=oneline` includes the commit-hash/header. – c00kiemon5ter Jul 05 '11 at 14:14
-
1
-
5From `man git-whatchanged`; "The command is kept primarily for historical reasons." "New users are encouraged to use git-log(1) instead." – Stéphane Gourichon Oct 27 '16 at 17:56
-
8@StéphaneGourichon: This answer is kept primarily for historical reasons. New users are encouraged to find a different answer instead :-) – Kerrek SB Oct 27 '16 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: https://stackoverflow.com/a/40777727/2184166 – ob-ivan Feb 24 '23 at 10:13
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.

- 5,113
- 2
- 27
- 41
-
1Much 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^) – Stan Kurdziel Aug 25 '17 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 Feb 04 '20 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 Jul 30 '21 at 18:37
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}

- 5,321
- 2
- 39
- 61
-
4Use `--shortstat` to get straight to the point: `git show --shortstat
`. See https://git-scm.com/docs/git-show for more options. – Nolan Amy Dec 01 '20 at 08: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

- 16,994
- 7
- 46
- 48
-
1This should be the accepted answer, since using `git whatchanged` is discouraged. – Sean the Bean Nov 09 '17 at 13:48
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 ""

- 468
- 2
- 10