Skip to content

Instantly share code, notes, and snippets.

@macx
Last active October 17, 2019 12:44
Show Gist options
  • Select an option

  • Save macx/1a2ae26faa71d2c5cb12 to your computer and use it in GitHub Desktop.

Select an option

Save macx/1a2ae26faa71d2c5cb12 to your computer and use it in GitHub Desktop.
git CheatSheet

git CheatSheet

Remove a file from last commit

# put files back to staging
$ git reset --soft HEAD^

# unstage the file
$ git reset -- file.md

Show all local and remote Branches

$ git branch -a

Rewrite History

Rebase

To remove a specific commit from history, rebase it.

  • Find out the hash from the previous commit of the one you want to delete via g l
  • Start interactive rebase: git rebase -i <HASH-PREVOUS-COMMIT>
  • Then remove the commit from the opened rebase message in your editor. Save and close.
  • Now, force push everything git push --force-with-lease origin master.

Convert large files to LFS

To remove or convert files in the git history, use BFG (brew install bfg).

$ bfg --convert-to-git-lfs '*.mv4' --no-blob-protection
$ git reflog expire --expire=now --all && git gc --prune=now --aggressive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment