[英]Removing files from past commits in GitHub repository with BFG Repo-Cleaner
I have a file in my GitHub repository that I would like to remove from my previous commits. 我的GitHub存储库中有一个文件,希望从以前的提交中删除。 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. 我使用了BFG Repo-Cleaner的delete-files
命令,它似乎可以正常工作,但是当我进入GitHub存储库时,该文件仍在所有先前的提交中。 If I try and do the command again, it gives me a 如果我再次尝试执行该命令,它将给我一个
BFG aborting: No refs to update - no dirty commits found?? BFG中止:没有引用更新-没有发现脏提交?
Am I misunderstanding how BFG works? 我是否误解了BFG的工作原理? If so how can I remove the file from my past commits on GitHub? 如果是这样,如何从GitHub上的以往提交中删除文件?
Here are the steps I took: 这是我采取的步骤:
--mirror
flag. 使用--mirror
标志将GitHub存储库的副本克隆到本地文件夹中。 cd
to my local visual studio project. 然后我cd
我的本地Visual Studio项目。 java -jar bfg-1.12.1.13.jar --delete-files <.json file I wanted to delete> <my local clone copy from step 1>.git
然后我输入命令java -jar bfg-1.12.1.13.jar --delete-files <.json file I wanted to delete> <my local clone copy from step 1>.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive
然后我在git reflog expire --expire=now --all && git gc --prune=now --aggressive
输入git reflog expire --expire=now --all && git gc --prune=now --aggressive
git push
跑git push
A git push
alone should not work, since BFG repo cleaner does rewrite the history of a repo. 由于BFG回购清除器确实会重写回购的历史记录,因此单独使用git push
应该不起作用。
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. 但是,当您使用--mirror
克隆(如您所做的)时,它应该可以工作,因为在git push
,本地更新的引用将在远程端强制更新。
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. 默认情况下,HEAD分支是受保护的,尽管将清除其历史记录,但最新的提交(“提示”)是受保护的提交,并且其文件层次结构将完全不会更改。
Don't forget to remove your file from your HEAD (current working tree) as well, before pushing back. 在回推之前,也不要忘记从HEAD(当前工作树)中删除文件。
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. 该文件夹应以.git
结尾: xxx.git
:一个clone --mirror
是一个裸clone --mirror
。
Skip step 2 in your steps and it should work (don't cd
into your <repo-name>.git
). 跳过您的步骤中的第2步,它应该可以工作(不要cd
到您的<repo-name>.git
)。
You need to run BFG from the folder that contains the folder <repo-name>.git
. 您需要从包含文件夹<repo-name>.git
的文件夹中运行BFG。 BFG is looking for a folder called <repo-name>.git
in the working directory. BFG在工作目录中寻找一个名为<repo-name>.git
的文件夹。 That's why it didn't change anything. 这就是为什么它什么都没改变的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.