To show the number of lines changed between two commits for each file in a Git repository, you can use the git diff command. Here’s how you can do it:
1. Using git diff: You can run the following command in your terminal:
git diff --stat <commit1> <commit2>
Replace <commit1> and <commit2> with the respective commit hashes, branch names, or tags. The --stat option gives you a summary of changes including the number of files changed, insertions, and deletions.
Example:
git diff --stat abc1234 def5678
This will show you a summary of changes between the two commits identified by abc1234 and def5678.
2. Using a more detailed view: If you want to see more detailed output (such as line additions and deletions for each file), you can use:
git diff <commit1> <commit2>
This will show you the differences in the actual lines, but it may be more output than you're looking for if you only want a summary.
3. Using git log for specific files: If you want to see changes for specific files, you can also check out the diff for a single file:
git diff <commit1> <commit2> -- <file>
4. Summarizing with --shortstat: If you prefer a more concise summary, use --shortstat which shows the total number of files changed, lines added, and lines deleted:
git diff --shortstat <commit1> <commit2>
5. For historical reference or completion: If you want to see all changes and their line count in the commit history, you may also combine git log with the --stat flag:
git log --stat <commit-range>
Replace <commit-range> with the desired range (e.g., HEAD~5..HEAD).
Using these commands, you will be able to see the number of lines changed between two commits for each file in the repository.