git: show all files changed between two commits

Git

Git Problem Overview


A riff on [git: show all changed files between two commits][1]: 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).

[1]: https://stackoverflow.com/questions/1552340/git-show-all-changed-files-between-two-commits "git: show all changed files between two commits"

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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.

Solution 3 - Git

If just want to see the file names where commit b is chronologically after a:

git diff <a commit sha1>...<b commit sha2> --name-only # b is after a in time

If you want to see all the file names and what was changed from commit a to commit b then drop the last argument.

git diff <a commit sha1>...<b commit sha2> # shows file names and what changed in each file

An example of <commit sha1> are the commit id's like 675ee6860d2c273bcc6c6a0536634a107e2a3d9f. Generally the first 8-10 digits will work on most projects, but may need more if the project has oodles of commits. Typically I use the output of the id from git log --oneline.

When you get a difference of a...b and b is later than a in time it's easy to see what was changed in each file chronologically.

Solution 4 - Git

This one is similar to igorw's, but it avoids the removal of the SHA via grep:

git log --pretty='format:' --name-only HEAD^^..HEAD | sort -u

If you additionally want to see how the files were modified, replace --name-only with --name-status.

Solution 5 - Git

I'd use; taking the first 8 of the commit hash. If you wanted you could pipe into a file as per the below:

git log 12345678..87654321 > C:\GitChanges.txt

Solution 6 - Git

I use this command to compare all changes between two commits:

git difftool -d <commit hash1> <commit hash2>

Like a git rebase to squash all local commits into one.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndrewView Question on Stackoverflow
Solution 1 - GitigorwView Answer on Stackoverflow
Solution 2 - GitbrycemcdView Answer on Stackoverflow
Solution 3 - GitLloyd RochesterView Answer on Stackoverflow
Solution 4 - GitIngo KarkatView Answer on Stackoverflow
Solution 5 - Gitcraig RickettView Answer on Stackoverflow
Solution 6 - GitcodewarriorView Answer on Stackoverflow