1

I have a file in my GitHub repository that I would like to remove from my previous commits. I used BFG Repo-Cleaner's delete-files command and it appeared to work, but when I go on my GitHub repository the file is still on all the previous commits. If I try and do the command again, it gives me a

BFG aborting: No refs to update - no dirty commits found??

Am I misunderstanding how BFG works? If so how can I remove the file from my past commits on GitHub?

Here are the steps I took:

  1. Cloned a copy of my GitHub repo into a local folder using the --mirror flag.
  2. I then cd to my local visual studio project.
  3. I then entered in the command java -jar bfg-1.12.1.13.jar --delete-files <.json file I wanted to delete> <my local clone copy from step 1>.git
  4. I then entered in git reflog expire --expire=now --all && git gc --prune=now --aggressive
  5. Ran git push
ecain
  • 1,282
  • 5
  • 23
  • 54
  • Please include details on the procedure you used. The "usage" section on the BFG Repo-Cleaner website outlines one way to update the remote repository after doing your local cleanup. Some other procedures might not take care of that part. – Jan Krüger Sep 25 '16 at 00:36
  • I added the steps I took in my question. – ecain Sep 25 '16 at 02:17

2 Answers2

2

A git push alone should not work, since BFG repo cleaner does rewrite the history of a repo.

It should work though when you cloned (as you did) with --mirror, since, on git push, locally updated refs will be force updated on the remote end.

Note that:

By default the HEAD branch is protected, and while its history will be cleaned, the very latest commit (the 'tip') is a protected commit and its file-hierarchy won't be changed at all.

Don't forget to remove your file from your HEAD (current working tree) as well, before pushing back.

After discussion, it seems the commands were not executed in the right folder. That folder should end with .git: xxx.git: a clone --mirror is a bare repo.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Yes, I did make sure the file was not in my latest commit. The only I branch I worked with was the master branch. If this is considered the HEAD branch, the history should still be cleared right? So if git push isn't enough what should I do? – ecain Sep 25 '16 at 17:07
  • @ecain What was the output of git push? – VonC Sep 25 '16 at 17:09
  • It think it just said my branch was then up to date, but I didn't see any difference in my GitHub repo. – ecain Sep 25 '16 at 17:14
  • @ecain that is why you don't thee the files removed on the remote repo side: as long as a git push does not succeed, nothing will change. If you did clone as --mirror, it should have worked. Can you try a git push --force? – VonC Sep 25 '16 at 17:16
  • If I do a `git push --force` it just says "Everything is up to date". – ecain Sep 25 '16 at 17:31
  • @ecain If the log on the remote side display the same SHA1 as the ones in the local repo, then nothing has changed. BFG is supposed to rewrite the history. – VonC Sep 25 '16 at 17:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/124157/discussion-between-ecain-and-vonc). – ecain Sep 25 '16 at 17:40
0

Skip step 2 in your steps and it should work (don't cd into your <repo-name>.git).

You need to run BFG from the folder that contains the folder <repo-name>.git. BFG is looking for a folder called <repo-name>.git in the working directory. That's why it didn't change anything.

JLaudio
  • 63
  • 1
  • 9