简体   繁体   中英

Problem with git reset on rolling back to the previous commit

I accidentally committed the huge unwanted folder and pushed it to master in git. And i had one more commit after that. so its like this

A - B - C - D

C - is the problematic commit

After realizing the mistake i used the command

git reset --hard <sha1-commit-id-of-B>

and

git push origin HEAD --force

to rollback to the B. It was fine, but the size of the repo is still same. i was confused. how can i get rid of the unwanted files(permanently), so it wont appear on the git?

Even if you move the branch pointer back in this way, git doesn't immediately garbage-collect the objects that are now no longer referenced. This is a good thing - it means, for example, that if you mistakenly do a git reset --hard , then you can recover the old commits easily, typically by using the reflog to find the object names of those commits, and creating a branch from one of them. If you really want to garbage collect immediately to reclaim the space, you can do:

git gc --prune=now

However, one almost never needs to do this...

使用http://git-scm.com/docs/git-filter-branch ,但后果自负!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM