March 24, 2021 • 3 min read
You spend a lot of time reviewing your own pull request on Github before asking for a review and you always find stuff that needs to be changed. So you need to add/edit commits, losing lots of time.
Before committing, make good use of git diff, so you avoid having to change code later.
Here are some not-so-known git tips, sorted from more common to more uncommon:
git diff
git diff --cached
git diff HEAD
git log --oneline
# 4833545 cleanup
# c3a1ee6 add navbar
# ca2f968 initial commit
git diff ca2f968
git diff HEAD~2
git diff script.js
git log --oneline
# 4833545 cleanup
# c3a1ee6 add navbar
# ca2f968 initial commit
git diff ca2f968 script.js
To be run from your feature branch.
git diff master
git diff master --stat
git diff master --shortstat
Finally, here’s a neat trick by Shime.sh, to make your diffs more readable by removing the + and - symbols, since they are colored anyway!
git config --global pager.diff 'sed "s/^\([^-+ ]*\)[-+ ]/\\1/"'