Skip to main content


Useful flags#

  • git log --oneline - displays single commit information per line.
  • git rev-list HEAD --count - total number of commits.
    • git shortlog - Summarize 'git log' output.
  • git commit --amend -m "New commit message" - Edit the last commit message.


  • Remove a file from history

    $ git filter-branch --force --index-filter \  "git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA" \  --prune-empty --tag-name-filter cat -- --all
  • Get a list of the deleted files in git history

    git log --diff-filter=D --summary | grep delete - without commit hashes.

    git log --diff-filter=D --summary | grep -E 'delete|^commit\s+\S+' - with commit hashes.

  • Amend older or multiple commit messages

    • git rebase -i HEAD~n - display a list of the last n commits in the default text editor.
    • Replace pick with reword before each commit message you want to change, save and close the commit list file.
    • In each resulting commit file, type the new commit message, save the file, and close it.
    • git push --force - force-push the amended commits.
  • Amend the very first commit message [*]

    • git rebase -i --root
  • Squash all previous commits into one [*]

    git reset $(git commit-tree HEAD^{tree} -m "A new start")

  • Print a leaderboard of authors based on number of commits in a git repo

    git log --format='%an' | sort | uniq -c | sort -nr