markmcdermott.io (js, ruby, ...etc) by mark mcdermott

Quick Git Notes

03/14/2024

estimated reading time:1 min

I’ve been working collaboratively on Drivetracks with a couple people and have forced to improve my git-fu a bit and want to jot down real quick what I’ve learned.

descriptiongit command
change last commit messagegit commit --amend
change specific commit messagegit rebase -i HEAD~3
add stuff to the last commitgit commit --amend --no-edit
sqash last n commitsgit reset --soft HEAD~n
interactive squashgit rebase -i HEAD~n
(…but keep original commit date)git rebase -i --committer-date-is-author-date HEAD~n
see a branch’s changesgit diff main
see a branch’s divergent changesgit diff main...branch
see diff between two commitsgit diff hash1...hash2

When you accidentally make a commit on master that you need on a new branch (and you haven’t pushed it up to the remote yet)