How can I permanently delete a commit from Git's history?
One of the developers on the team has accidentally committed a 200 MB file and pushed it to our Git server. It was deleted a few days later but the history is there. Our code files are only about 75 MB, and we have 4 branches. Due to the 200 MB file commit, the history is preserved and the size of our project folder (specifically the hidden .git folder) has ballooned to close to 700 MB. How do I permanently delete the two check-ins (commit of the huge file, delete of the huge file) from git as if it never happened? I'm using `TortoiseGit if that matters.
By deleting line of the commit or writing drop instead of pick, you can remove the commit from history. Thus, we deleted a commit locally. To remove it from remote repository, we should push our changes to remote. The + sign before the name of the branch you are pushing, this tells git to force the push.
To entirely remove unwanted files from a repository's history you can use either the git filter-repo tool or the BFG Repo-Cleaner open source tool. The git filter-repo tool and the BFG Repo-Cleaner rewrite your repository's history, which changes the SHAs for existing commits that you alter and any dependent commits.
90 days. no (you actually can contact GitHub support to ask them and restore a deleted pushed branch)
As forvaidya suggested, git filter-branch
is the way to go. Specifically, in your case, you can execute the following command to remove that one file from the repo's history:
git filter-branch --tree-filter 'rm -f filename' HEAD
Substitute filename
with the actual file name. Again, as forvaidya said, this rewrites the entire history of the repo so anyone who pulls after you make this change will get an error.
Edit: for performance reasons, it's actually better to use Git's rm
command:
git filter-branch --index-filter 'git rm --cached --ignore-unmatch filename' HEAD
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With