How can you display the number of lines changed between two commits for each file in the repository?
Posted by MaryJns
Last Updated: July 08, 2024
To display the number of lines changed between two commits for each file in a Git repository, you can use the git diff command with specific options. Here’s how you can do it: 1. Open your terminal and navigate to your Git repository. 2. Use the git diff command with the --stat option to get a summary of changes, including the number of lines added and removed for each file. The command syntax is as follows:
git diff --stat COMMIT1 COMMIT2
Replace COMMIT1 and COMMIT2 with the actual commit hashes, branch names, or tags you want to compare. 3. If you want a more detailed view of the changes, you can use the --numstat option instead, which will show you the specific number of lines added and deleted for each file:
git diff --numstat COMMIT1 COMMIT2
Examples
- To compare the changes between two specific commits:
git diff --stat abc1234 def5678
- To see detailed line changes:
git diff --numstat abc1234 def5678
Output Explanation
- With --stat: You'll see a summary line for each file, indicating how many lines were added and removed. - With --numstat: The output will show three columns: - The number of lines added. - The number of lines deleted. - The file path.
Note
- If you want to compare the changes in the working directory with the last commit, you can use HEAD:
git diff --stat HEAD
This approach provides a straightforward way to analyze code changes between any two commits directly within your Git repository.
Related Content