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.
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. Commented Jul 5, 2011 at 14:14 -
2
git whatchanged -1 --format=oneline | tail -n +2 | wc -l
Commented Dec 1, 2014 at 17:52 -
5From
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 :-) 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-ivanCommented Feb 24, 2023 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.
-
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^) 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
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
. Commented Jul 30, 2021 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}
-
5Use
--shortstat
to get straight to the point:git show --shortstat <hash>
. See git-scm.com/docs/git-show for more options. Commented Dec 1, 2020 at 8: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
-
1This should be the accepted answer, since using
git whatchanged
is discouraged. Commented Nov 9, 2017 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 ""
git whatchanged
?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.