Improved Commit Diffs
We recently rolled out a bunch of improvements to commit pages to make reviewing diffs a bit more pleasant. Diffstats Diffstat style histograms of insertions and deletions for each file…
We recently rolled out a bunch of improvements to commit pages to make reviewing diffs a bit more pleasant.
Diffstats
Diffstat style histograms of insertions and deletions for each file are now displayed on commit pages. This is useful for getting a high level feel for the impact of a commit:
The diffstat display is similar in spirit to the output generated by git diff --stat
: a numeric representing the total number of changed lines (insertions + deletions) followed by a simple visualization of the insertion to deletion ratio.
Rename Detection
Git doesn’t track file renames, but it does support heuristic detection of renamed files when performing diff
and log
operations. We’ve enabled it. The file list now displays a single line for renames instead of separate file add/remove lines:
While it’s nice to see renames reported as such in the file list, the larger benefit comes with the actual diff. Without rename detection, commits with even a small number of renamed files can generate large and noisy diffs. The entire file contents is displayed twice: first with all deleted lines and then again with all added lines. These same diffs are reduced down to pure signal with rename detection enabled because only the lines modified between the two files are shown:
See the -M
option to git-diff(1)
for information on using rename detection from the command line.
Added / Removed Files
Previously, files added or removed in a commit were shown in the file list at the top of commit pages but the actual diffs were omitted. This was a simple guard against Insanely Large Diffs That Crashed Browsers but had a few notable drawbacks:
- It was easy to miss important changes introduced by added or removed files when reviewing commits.
- It wasn’t possible to comment on specific lines in added or removed files.
- It didn’t always avoid large diffs. Consider cases like SQL database dumps where each line of a large generated file is modified as part of an otherwise tiny commit. Omitting added/removed files gave no guarantee that diffs would not exceed a reasonable size.
According to Aldo Cortesi’s GitHub project analysis, the average commit touches about 4 files and 19 lines of code. We felt that commit pages needed to do a better job showing all pertinent information on these common case commits, so from now on you’ll see diffs for added and removed files:
Large Diffs
Displaying added/removed files left the problem of how to deal with very large diffs. What we came up with is a set of rules for omitting portions of large diffs that ensures a sane upper bound on overall diff size. It works something like this:
- Diffs are not shown for any individual file with more than 300 changed lines (this includes modified files as well as added/removed files).
- No more than 150 total file diffs are displayed.
- No more than 3,000 total changed lines are shown across all diffs.
While we expect to tune these numbers over the coming weeks, the result so far has been diffs that show more of what you typically want to see and less of what you don’t.
Written by
Related posts
![](https://github.blog/wp-content/uploads/2023/10/Collaboration-DarkMode-2.png?resize=400%2C212)
2024 is the biggest global election year in history. What’s at stake for developers?
GitHub is considering what is at stake for our users and platform, how we can take responsible action to support free and fair elections, and how developers contribute to resilient democratic processes.
![](https://github.blog/wp-content/uploads/2023/10/AI-DarkMode-2.png?resize=400%2C212)
GitHub named a Leader in the Gartner first-ever Magic Quadrant for AI Code Assistants
This year, as part of its annual Magic Quadrant series, Gartner published a first-of-its-kind report analyzing the state of play in the AI Code Assistants market–and named GitHub a Leader.
![AI in software development 2024 survey results with colorful graphics and percentages.](https://github.blog/wp-content/uploads/2024/08/ai-survey-header.png?resize=400%2C212)
Survey: The AI wave continues to grow on software development teams
We surveyed 2,000 people on software development teams at enterprises in the U.S., Brazil, India, and Germany about the use, experience, and expectations around generative AI tools in software development.