Skip to content

Commit e72b43a

Browse files
authored
Suggest using git range-diff (rust-lang#1092)
I have found it to be very helpful when rebasing.
1 parent 0355e12 commit e72b43a

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

src/git.md

+60
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ there are no glaring errors.
217217
Once you're all done fixing the conflicts, you need to stage the files that had
218218
conflicts in them via `git add`. Afterwards, run `git rebase --continue` to let
219219
Git know that you've resolved the conflicts and it should finish the rebase.
220+
220221
Once the rebase has succeeded, you'll want to update the associated branch on
221222
your fork with `git push --force-with-lease`.
222223

@@ -263,6 +264,65 @@ You also may want to squash just the last few commits together, possibly
263264
because they only represent "fixups" and not real changes. For example,
264265
`git rebase --interactive HEAD~2` will allow you to edit the two commits only.
265266

267+
### `git range-diff`
268+
269+
After completing a rebase, and before pushing up your changes, you may want to
270+
review the changes between your old branch and your new one. You can do that
271+
with `git range-diff master @{upstream} HEAD`.
272+
273+
The first argument to `range-diff`, `master` in this case, is the base revision
274+
that you're comparing your old and new branch against. The second argument is
275+
the old version of your branch; in this case, `@upstream` means the version that
276+
you've pushed to GitHub, which is the same as what people will see in your pull
277+
request. Finally, the third argument to `range-diff` is the *new* version of
278+
your branch; in this case, it is `HEAD`, which is the commit that is currently
279+
checked-out in your local repo.
280+
281+
Note that you can also use the equivalent, abbreviated form `git range-diff
282+
master @{u} HEAD`.
283+
284+
Unlike in regular Git diffs, you'll see a `-` or `+` next to another `-` or `+`
285+
in the range-diff output. The marker on the left indicates a change between the
286+
old branch and the new branch, and the marker on the right indicates a change
287+
you've committed. So, you can think of a range-diff as a "diff of diffs" since
288+
it shows you the differences between your old diff and your new diff.
289+
290+
Here's an example of `git range-diff` output (taken from [Git's
291+
docs][range-diff-example-docs]):
292+
293+
```
294+
-: ------- > 1: 0ddba11 Prepare for the inevitable!
295+
1: c0debee = 2: cab005e Add a helpful message at the start
296+
2: f00dbal ! 3: decafe1 Describe a bug
297+
@@ -1,3 +1,3 @@
298+
Author: A U Thor <author@example.com>
299+
300+
-TODO: Describe a bug
301+
+Describe a bug
302+
@@ -324,5 +324,6
303+
This is expected.
304+
305+
-+What is unexpected is that it will also crash.
306+
++Unexpectedly, it also crashes. This is a bug, and the jury is
307+
++still out there how to fix it best. See ticket #314 for details.
308+
309+
Contact
310+
3: bedead < -: ------- TO-UNDO
311+
```
312+
313+
(Note that `git range-diff` output in your terminal will probably be easier to
314+
read than in this example because it will have colors.)
315+
316+
Another feature of `git range-diff` is that, unlike `git diff`, it will also
317+
diff commit messages. This feature can be useful when amending several commit
318+
messages so you can make sure you changed the right parts.
319+
320+
`git range-diff` is a very useful command, but note that it can take some time
321+
to get used to its output format. You may also find Git's documentation on the
322+
command useful, especially their ["Examples" section][range-diff-example-docs].
323+
324+
[range-diff-example-docs]: https://git-scm.com/docs/git-range-diff#_examples
325+
266326
## No-Merge Policy
267327

268328
The rust-lang/rust repo uses what is known as a "rebase workflow." This means

0 commit comments

Comments
 (0)