Skip to content

Instantly share code, notes, and snippets.

@Iksas
Last active December 27, 2023 12:41
Show Gist options
  • Save Iksas/90c9d9ed7329394bd3c10137931eb415 to your computer and use it in GitHub Desktop.
Save Iksas/90c9d9ed7329394bd3c10137931eb415 to your computer and use it in GitHub Desktop.
git cheat sheet

git cheat sheet

  • Search the reflog for info about a commit (only works if the relevant info hasn't been garbage-collected):

git reflog --no-abbrev | grep <HASH>

  • List the number of lines in each file:

git ls-files | xargs wc -l

  • Count the number of lines of all Python files

git ls-files | grep \\.py$ | xargs wc -l

  • Search the code for a certain string. The oldest commit containing the string is listed first:

git log --all -p --reverse --source -S "string"

git --no-pager log --all -p --reverse --source -S "string"

  • remove last commit

git reset HEAD^

  • interactive rebase onto origin

git rebase -i origin

links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment