Skip to content

Commit 022bb49

Browse files
author
Jonathan Corbet
committed
docs: Add a document on how to fix a messy diffstat
A branch with merges in will sometimes create a diffstat containing a lot of unrelated work at "git request-pull" time. Create a document based on Linus's advice (found in the links below) and add it to the maintainer manual in the hope of saving some wear on Linus's keyboard going forward. Link: https://lore.kernel.org/lkml/CAHk-=wg3wXH2JNxkQi+eLZkpuxqV+wPiHhw_Jf7ViH33Sw7PHA@mail.gmail.com/ Link: https://lore.kernel.org/lkml/CAHk-=wgXbSa8yq8Dht8at+gxb_idnJ7X5qWZQWRBN4_CUPr=eQ@mail.gmail.com/ Acked-by: Borislav Petkov <bp@suse.de> Reviewed-by: Akira Yokosawa <akiyks@gmail.com> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
1 parent be78837 commit 022bb49

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

Documentation/maintainer/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ additions to this manual.
1212
configure-git
1313
rebasing-and-merging
1414
pull-requests
15+
messy-diffstat
1516
maintainer-entry-profile
1617
modifying-patches
1718

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
=====================================
4+
Handling messy pull-request diffstats
5+
=====================================
6+
7+
Subsystem maintainers routinely use ``git request-pull`` as part of the
8+
process of sending work upstream. Normally, the result includes a nice
9+
diffstat that shows which files will be touched and how much of each will
10+
be changed. Occasionally, though, a repository with a relatively
11+
complicated development history will yield a massive diffstat containing a
12+
great deal of unrelated work. The result looks ugly and obscures what the
13+
pull request is actually doing. This document describes what is happening
14+
and how to fix things up; it is derived from The Wisdom of Linus Torvalds,
15+
found in Linus1_ and Linus2_.
16+
17+
.. _Linus1: https://lore.kernel.org/lkml/CAHk-=wg3wXH2JNxkQi+eLZkpuxqV+wPiHhw_Jf7ViH33Sw7PHA@mail.gmail.com/
18+
.. _Linus2: https://lore.kernel.org/lkml/CAHk-=wgXbSa8yq8Dht8at+gxb_idnJ7X5qWZQWRBN4_CUPr=eQ@mail.gmail.com/
19+
20+
A Git development history proceeds as a series of commits. In a simplified
21+
manner, mainline kernel development looks like this::
22+
23+
... vM --- vN-rc1 --- vN-rc2 --- vN-rc3 --- ... --- vN-rc7 --- vN
24+
25+
If one wants to see what has changed between two points, a command like
26+
this will do the job::
27+
28+
$ git diff --stat --summary vN-rc2..vN-rc3
29+
30+
Here, there are two clear points in the history; Git will essentially
31+
"subtract" the beginning point from the end point and display the resulting
32+
differences. The requested operation is unambiguous and easy enough to
33+
understand.
34+
35+
When a subsystem maintainer creates a branch and commits changes to it, the
36+
result in the simplest case is a history that looks like::
37+
38+
... vM --- vN-rc1 --- vN-rc2 --- vN-rc3 --- ... --- vN-rc7 --- vN
39+
|
40+
+-- c1 --- c2 --- ... --- cN
41+
42+
If that maintainer now uses ``git diff`` to see what has changed between
43+
the mainline branch (let's call it "linus") and cN, there are still two
44+
clear endpoints, and the result is as expected. So a pull request
45+
generated with ``git request-pull`` will also be as expected. But now
46+
consider a slightly more complex development history::
47+
48+
... vM --- vN-rc1 --- vN-rc2 --- vN-rc3 --- ... --- vN-rc7 --- vN
49+
| |
50+
| +-- c1 --- c2 --- ... --- cN
51+
| /
52+
+-- x1 --- x2 --- x3
53+
54+
Our maintainer has created one branch at vN-rc1 and another at vN-rc2; the
55+
two were then subsequently merged into c2. Now a pull request generated
56+
for cN may end up being messy indeed, and developers often end up wondering
57+
why.
58+
59+
What is happening here is that there are no longer two clear end points for
60+
the ``git diff`` operation to use. The development culminating in cN
61+
started in two different places; to generate the diffstat, ``git diff``
62+
ends up having pick one of them and hoping for the best. If the diffstat
63+
starts at vN-rc1, it may end up including all of the changes between there
64+
and the second origin end point (vN-rc2), which is certainly not what our
65+
maintainer had in mind. With all of that extra junk in the diffstat, it
66+
may be impossible to tell what actually happened in the changes leading up
67+
to cN.
68+
69+
Maintainers often try to resolve this problem by, for example, rebasing the
70+
branch or performing another merge with the linus branch, then recreating
71+
the pull request. This approach tends not to lead to joy at the receiving
72+
end of that pull request; rebasing and/or merging just before pushing
73+
upstream is a well-known way to get a grumpy response.
74+
75+
So what is to be done? The best response when confronted with this
76+
situation is to indeed to do a merge with the branch you intend your work
77+
to be pulled into, but to do it privately, as if it were the source of
78+
shame. Create a new, throwaway branch and do the merge there::
79+
80+
... vM --- vN-rc1 --- vN-rc2 --- vN-rc3 --- ... --- vN-rc7 --- vN
81+
| | |
82+
| +-- c1 --- c2 --- ... --- cN |
83+
| / | |
84+
+-- x1 --- x2 --- x3 +------------+-- TEMP
85+
86+
The merge operation resolves all of the complications resulting from the
87+
multiple beginning points, yielding a coherent result that contains only
88+
the differences from the mainline branch. Now it will be possible to
89+
generate a diffstat with the desired information::
90+
91+
$ git diff -C --stat --summary linus..TEMP
92+
93+
Save the output from this command, then simply delete the TEMP branch;
94+
definitely do not expose it to the outside world. Take the saved diffstat
95+
output and edit it into the messy pull request, yielding a result that
96+
shows what is really going on. That request can then be sent upstream.

0 commit comments

Comments
 (0)