How do you display the list of files that were changed in a specific commit, along with the number of lines added or deleted?
Posted by PaulAnd
Last Updated: June 19, 2024
To display the list of files changed in a specific commit, along with the number of lines added and deleted, you can use the git show command with the --stat and --numstat options. Here's how to do it:
Using git show
1. Basic command: This will display a summary of changes including the number of lines added and deleted per file along with the commit message.
git show --stat <commit_hash>
Replace <commit_hash> with the hash of the commit you are interested in. 2. Detailed line changes: If you want a more detailed output that includes specific numbers of lines added and deleted for each file, use:
git show --numstat <commit_hash>
This will give you an output showing three columns for each changed file: - Lines added - Lines deleted - File name
Example
For a commit with hash abc123, you could run:
git show --numstat abc123
Additional Tip
If you wish to visualize just the changes in a more compact format without commit messages but still want to see added and deleted line counts, you can format the output using:
git diff --numstat <commit_hash>^ <commit_hash>
This makes it clear what has changed between the commit and its parent.
Important Points
- Make sure you replace <commit_hash> with the actual hash of the commit you wish to inspect. - You can also combine these commands in a script or with further processing (such as grep, awk, etc.) if you want to format the output further.