Git cheatsheet
Various things I need to remember for Git, but that I don’t remember. I know I can read the help to get this, but I still have to wade through a bunch of verbiage.
Undo the last commit (--soft keeps changes):
$ git reset --soft HEAD~1
$ git reset --hard HEAD~1Delete remote branches (Stackoverflow):
$ git push REMOTENAME --delete <branch-name>
$ git push REMOTENAME :<branch-name>
$ git remote prune originShow filenames in log messages (Stackoverflow)
$ git log --name-onlyGive someone else the author credit:
$ git commit --author="Joe Cool <cool@example.com>" -m "Fix the thing"Add a trailer:
$ git commit --trailer "Co-authored-by: Joe Cool <cool@example.com>" -m "Fix the thing"Show all merged branches
$ git branch --merged masterSee which .gitignore rules exclude a file (Stackoverflow)
$ git check-ignore -v **/*Find the commit that deleted a file (git docs) (Stackoverflow)
$ git rev-list -n 1 HEAD -- <file_path>Diff the same file across two branches:
$ git diff mybranch..master -- filename