Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: show all files changed between two commits

Tags:

git

A riff on git: show all changed files between two commits: I want a listing of all files that have been changed between two commits, even if they are now the same (ie, changed and then changed back).

like image 326
Andrew Avatar asked Jun 29 '10 20:06

Andrew


People also ask

How can I see what changed between two commits?

To see the changes between two commits, you can use git diff ID1.. ID2 , where ID1 and ID2 identify the two commits you're interested in, and the connector .. is a pair of dots. For example, git diff abc123.. def456 shows the differences between the commits abc123 and def456 , while git diff HEAD~1..

How do I get a list of files changed in a commit?

Find what file changed in a commit To find out which files changed in a given commit, use the git log --raw command.


2 Answers

This is the best I could come up with:

git log --name-only --pretty=oneline --full-index HEAD^^..HEAD | grep -vE '^[0-9a-f]{40} ' | sort | uniq 

Replace HEAD^^ and HEAD with the commits you want to compare.

My attempt uses git log with --name-only to list all files of each commit between the specified ones. --pretty=oneline makes the part above the file listing consist only of the commit SHA and message title. --full-index makes the SHA be the full 40 characters. grep filters out anything looking like a SHA followed by a space. Unless you have files beginning with a SHA followed by a space, the result should be accurate.

like image 165
igorw Avatar answered Sep 25 '22 20:09

igorw


I think this command is your answer:

git diff --stat abc123 xyz123  # where abc123 and xyz123 are SHA1 hashes of commit objects 

Straight from the git community book:

If you don't want to see the whole patch, you can add the '--stat' option, which will limit the output to the files that have changed along with a little text graph depicting how many lines changed in each file.

like image 30
brycemcd Avatar answered Sep 25 '22 20:09

brycemcd