在GitHub上完全删除Git仓库中的文件和远程文件 [英] Completely remove files from Git repo and remote on GitHub
问题描述
然后我使用
git rm -f ./images
删除这些文件,然后再次提交。 现在,我在该分支(主)中做了更多的提交。在我的HEAD中,我没有 ./ static / images
文件夹。
由于这个原因,我的回购规模增加了很多。我怎样才能完全去除这些斑点?我想从远程GitHub仓库中删除它。
这就是你要找的:忽略不会删除文件。我建议你阅读那个页面,但是这里有一个特定的命令:
$ b
git filter-branch --index-filter \
'git rm -r --cached --ignore-unmatch< file / dir>'HEAD
另外,要从git创建的缓存中删除所有已删除的文件,请使用:
rm -rf .git / refs / original /&& \
git reflog expire --all&& \
git gc --aggressive --prune
您可以找到更多关于最后一个命令,以及一个脚本,它可以在一个单独的动作中完成所有你想要的任务,在这里: git:永久删除历史记录中的文件或文件夹。
另有大量解释链接:删除敏感数据。
另外,请参阅此StackOverflow问题:删除敏感文件及其从Git历史提交。
$ b
(在上面链接的问题中,从 natacado
的答案复制的命令)。如果您已经删除了文件从工作副本,下面应该工作。找出添加不需要的文件的提交哈希。然后做:
$ b
git filter-branch --index-filter \
' git update-index --remove filename'< introduction-revision-sha1> .. HEAD
git push --force --verbose --dry-run
git push --force
I accidentally added a folder of images and committed. Then, I made one more commit.
Then I removed those files using git rm -f ./images
and committed again.
Right now, I have made a lot more commits in that branch (master). In my HEAD, I don't have that ./static/images
folder.
Due to this, my repo size has increased a lot. How can I remove those blobs completely? And I want to remove it from my remote GitHub repo too.
This is what you're looking for: ignoring doesn't remove a file. I suggest you read that page, but here's the specific command to use:
git filter-branch --index-filter \
'git rm -r --cached --ignore-unmatch <file/dir>' HEAD
Also, to remove all the deleted files from caches git creates, use:
rm -rf .git/refs/original/ && \
git reflog expire --all && \
git gc --aggressive --prune
You can find more info about the last command, as well as a script that does everything you want in one single action, here: git: forever remove files or folders from history.
Another links with lots of explanation: Remove sensitive data.
[Edit] Also, see this StackOverflow question: Remove sensitive files and their commits from Git history.
(Commands copied from natacado
's answer in the question linked above.) If you have already removed the files from the working copy, the following should work. Find out the hash for the commit that added the unwanted files. Then do:
git filter-branch --index-filter \
'git update-index --remove filename' <introduction-revision-sha1>..HEAD
git push --force --verbose --dry-run
git push --force
这篇关于在GitHub上完全删除Git仓库中的文件和远程文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!