How do I find out what files were affected as part of a commit in git?
Hello everyone and welcome back to my blog! Today, we are going to look at some git fundamentals. I found myself needing to find out what files of my code repository were changed in one of my past commits.
Surprisingly, it's really simple to do this, here's the command:git diff-tree --no-commit-id --name-only -r <commit hash>
The --no-commit-id suppresses the commit ID output.
The --pretty argument specifies an empty format string to avoid the cruft at the beginning.
The --name-only argument shows only the file names that were affected.
Use --name-status instead, if you want to see what happened to each file (Deleted, Modified, Added)
The -r argument is to recurse into sub-trees
And that's it! To give credit where it's due, i found this from Stack Overflow: https://stackoverflow.com/questions/424071/how-do-i-list-all-of-the-files-in-a-commit
Hope you learned something new! ☺️