Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save storm1kk/c273566ab5532dcc5ff8b2e7611ded8a to your computer and use it in GitHub Desktop.
Save storm1kk/c273566ab5532dcc5ff8b2e7611ded8a to your computer and use it in GitHub Desktop.
Git: cleanup repo
Remove file from git repository (history)
SOLUTION: This is the shortest way to get rid of the files:
1. check .git/packed-refs - my problem was that I had there a refs/remotes/origin/master line for a remote repository, delete it, otherwise git won't remove those files
2. (optional) git verify-pack -v .git/objects/pack/#{pack-name}.idx | sort -k 3 -n | tail -5 - to check for the largest files
3. (optional) git rev-list --objects --all | grep #{SHA_FROM_#_3} - to check what files those are
4. git filter-branch --index-filter 'git rm --cached --ignore-unmatch file_names' - to remove the file from all revisions
5. rm -rf .git/refs/original/ - to remove git's backup
6. git reflog expire --all --expire='0 days' - to expire all the loose objects
7. (optional) git fsck --full --unreachable - to check if there are any loose objects
8. git repack -A -d - repacking the pack
9. git prune - to finally remove those objects
Completely remove a file from all revisions
git filter-branch -f --index-filter 'git update-index --remove filename' <introduction-revision-sha1>..HEAD
git push --force --verbose --dry-run
git push --force
Where introduction-revision-sha1 is the SHA1 that the file was first committed to the repository.
Removing the history from a new branch
git symbolic-ref HEAD refs/heads/newbranch
rm .git/index
git clean -fdx
<do work>
git add your files
git commit -m 'Initial commit'
http://stackoverflow.com/questions/927358/git-undo-last-commit
Undo a commit and redo
$ git commit ...
$ git reset --soft HEAD^ (1)
$ edit (2)
$ git commit -a -c ORIG_HEAD (3)
This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message, or both. Leaves working tree as it was before "reset".
Make corrections to working tree files.
"reset" copies the old head to .git/ORIG_HEAD; redo the commit by starting with its log message. If you do not need to edit the message further, you can give -C option instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment