Skip to content

Commit c508219

Browse files
committed
Add a section for how to review code more easily
1 parent 586474f commit c508219

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/git.md

+38
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,44 @@ tradeoff. The main advantage is the generally linear commit history. This
441441
greatly simplifies bisecting and makes the history and commit log much easier
442442
to follow and understand.
443443

444+
## Tips for reviewing
445+
446+
**NOTE**: This section is for *reviewing* PRs, not authoring them.
447+
448+
### Hiding whitespace
449+
450+
Github has a button for disabling whitespace changes that may be useful.
451+
You can also use `git diff -w origin/master` to view changes locally.
452+
453+
![hide whitespace](./img/github-whitespace-changes.png)
454+
455+
### Fetching PRs
456+
457+
To checkout PRs locally, you can use `git fetch upstream pull/NNNNN/head && git checkout
458+
FETCH_HEAD`.
459+
460+
You can also use github's cli tool. Github shows a button on PRs where you can copy-paste the
461+
command to check it out locally. See <https://cli.github.com/> for more info.
462+
463+
![`gh` suggestion](./img/github-cli.png)
464+
465+
### Moving large sections of code
466+
467+
Git and Github's default diff view for large moves *within* a file is quite poor; it will show each
468+
line as deleted and each line as added, forcing you to compare each line yourself. Git has an option
469+
to show moved lines in a different color:
470+
471+
```
472+
git log -p --color-moved=dimmed-zebra --color-moved-ws=allow-indentation-change
473+
```
474+
475+
See [the docs for `--color-moved`](https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---color-movedltmodegt) for more info.
476+
477+
### range-diff
478+
479+
See [the relevant section for PR authors](#git-range-diff). This can be useful for comparing code that was
480+
force-pushed to make sure there are no unexpected changes.
481+
444482
## Git submodules
445483

446484
**NOTE**: submodules are a nice thing to know about, but it *isn't* an absolute

src/img/github-cli.png

26.2 KB
Loading

src/img/github-whitespace-changes.png

28.5 KB
Loading

0 commit comments

Comments
 (0)