Useful Git Commands
Git log w/ context
git log --oneline --decorate --graph --all
Configure an alias for this log command
This log command, while relatively self describing, is a bit much to type each time you want to use it. If you’d like, you can configure an alias in git to make your life easier.
git config --global alias.slap 'log --oneline --decorate --graph --all'
With that in place, you can now simply run:
git slap
which is both fun and useful!
Uncommit
Looking to keep the changes, but drop the most recent commit on the current branch?
git reset --soft HEAD^
Configure an alias for ‘uncommit’
git config --global alias.uncommit 'reset --soft HEAD^'
With that in place, you can now simply run:
git uncommit
which I, personally, find wayyyy easier to remember.
Unstage
Similar to wanting to ‘uncommit’, we may at times want to ‘unstage’ a file. The command for this is:
git reset
Configure an alias for ‘unstage’
git config --global alias.unstage 'reset'
With that in place, you can now simply run:
git unstage
It may seem strange to create an alias that is longer than the base command, but I value ease of remembering over typing, and frankly tab completion will be doing the typing for me.
Explicitly set the commit a ref points at
git reset --hard <commit-ish>
Re-apply the changes from a commit
git cherry-pick
Git fulllll history
Git stores the history of every change to HEAD and all refs in something called the “reflog”.
git reflog
Show me what happened in a commit
git show
git show feature-branch