macx
7/29/2015 - 4:37 PM

git CheatSheet

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