Search code examples
gitgit-diffgit-log

List all files touched by commits in git


How to list all the files that were "touched" somewhere between two commits? I am looking for a command similar to git diff COMMIT1..COMMIT2 --name-only but including the files that were modified and reverted later.

For example, let's say I have a repository with a series of commits (linear history): C0<-C1<-C2<-C3<-C4. The commit C1 introduced a new file F and then the commit C3 removed it from the repository. I am looking for a command that, given C0 and C4, would tell me that somewhere in between there was a file F. Even though there is no such file in C0 and in C4. Therefore git diff wouldn't mention file F at all.


Solution

  • git diff ref1 ref2 takes into account only given commits, yes, but git log will find the missing steps and list files for each one, which sort will aggregate :

    git log --pretty=format: --name-only COMMIT1..COMMIT2 | sort -u