Tuesday, October 6, 2015
Remove unwanted file that has been committed several commits ago from git repository
Recently I have been developing a contacts management program and as usual I've been using git for source code management. This program stores all the contacts info in a file, say contacts.info.Today I bumped into a problem I had never had:
I noticed I had committed contacts.info several commits ago. As you can imagine, I had no intention of making those contacts info public. I needed to delete that file from my git repository, from all the commits I've committed since I added contacts.info.
I ended up finding a very useful tool for the job: BFG-Repo-Cleaner.
If you have a similar problem, here is a step-by-step guide on how to completely remove an unwanted file that has been committed several commits ago from your git repository:
- Download BFG-Repo-Cleaner;
- Clone a bare copy of your repository:
- git clone --mirror https://github.com/solutiononlen/my-repo.git
- Delete contacts.info from all the commits:
- java -jar bfg-1.11.6.jar --delete-files contacts.info my-repo.git/
- Push the repository to save changes:
- git push
Labels:
Git
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment