Git Cheatsheet
N. P. O'Donnell, 2020
Remotes
List all commits on all remotes:
for c in $(git rev-list --remotes); do git show $c | head -n8; done | less
Commits
Commit with empty commit message
git commit --allow-empty-message -m ""
Housekeeping
Remove untracked files (dryrun):
git clean -d -n
Remove untracked files (for real):
git clean -d -f
Navigation
Moving HEAD Back and Forth Along the History
Next commit:
function n() {
git log --reverse --pretty=%H master | grep -A 1 $(git rev-parse HEAD) | tail -n1 | xargs git checkout
}
Previous commit:
function p() {
git checkout HEAD^1
}
Reflog
View the reflog:
git reflog
Revert to a point in the reflog (e.g.: HEAD@{10}
):
git reset --hard HEAD@{10}