DEV Community

Discussion on: Useful Git Commands For Removing Accidentally Pushed or Committed Files

Collapse
 
oscherler profile image
Olivier “Ölbaum” Scherler

Good post, thank you.

It’s worth noting that the first approach doesn’t completely remove the offending file from the remote repository. Checking out a commit between the times it was added and removed, the file will still be available. It might be important depending on the reason why you wanted to remove it. Two typical cases where it won’t be enough to delete the file in a new commit:

  • very large file that should not be committed and will unnecessarily blow up the repository size;
  • sensitive file containing passwords or API tokens.

In this case, and if the file has been there for a few commits, you will probably need to use git filter-branch, which is not for the faint of heart, or the easier to use BFG Repo-Cleaner.

Collapse
 
morinoko profile image
Felice Forby

Thanks for pointing that out! Definitely want to be careful with sensitive data. I added a note and link to your comment in the article so everyone will see it.