Some commands I use daily, kept here for my future environments
Go back on latest branch checked out
$ git checkout -
"Cancel" previous commit, keeping its changes staged
$ git reset --soft HEAD^
Add staged changes to previous commit
$ git commit --amend -C HEAD
Combine last (e.g.) 3 commits into a single one
-
Run
$ git rebase -i HEAD~3
-
Editor 1: Squash all commits except the first
pick d701f467 Three commits ago s 5aa7d581 Two commits ago s 514f6795 Last commit
-
Editor 2: New commit message
Tip: to cancel the rebase, save an empty commit message in Editor 2
As (2), (3) and (4) are rewriting history, you need to force push (not recommended on shared remote branches)
$ git push --force-with-lease
To avoid committing unwanted local changes, it's safer to review each change individually.
Just don't use git add .
, instead:
$ git add -p
Only show changes, without unnecessary info
$ git status -s
Better Terminal with ohmyzsh
alias gss = 'git status -s'
alias gap = 'git add -p'
alias gc = 'git commit -m'
alias gp = 'git push'
alias gco = 'git checkout'
alias gg = 'git log --graph --oneline --decorate'
alias ggd = 'gg --cc'