我几个月前不小心将一个约100MB的目录提交到了我的代码库中。
现在,我想将该代码库迁移到Github,但由于存在大小限制,无法完成迁移。
通过以下帖子删除了该目录:彻底从Git版本控制中删除文件
看起来已经生效,但整个项目仍然有100M的大小。运行du .
命令后输出如下:98M ./.git/objects
。
我尝试过一些解决方案,但似乎都不可行,不确定该怎么办。
编辑:我通过上面链接中的Darren的回答成功解决了问题。
我几个月前不小心将一个约100MB的目录提交到了我的代码库中。
现在,我想将该代码库迁移到Github,但由于存在大小限制,无法完成迁移。
通过以下帖子删除了该目录:彻底从Git版本控制中删除文件
看起来已经生效,但整个项目仍然有100M的大小。运行du .
命令后输出如下:98M ./.git/objects
。
我尝试过一些解决方案,但似乎都不可行,不确定该怎么办。
编辑:我通过上面链接中的Darren的回答成功解决了问题。
我通过上面链接的帖子解决了这个问题。具体来说,我做了类似于Darren答案中的操作。以下是为您提供方便所做的操作:
简而言之:我筛选了分支,创建了一个新的裸仓库,将主分支推送到其中,克隆到一个新的目录中,并用克隆的git目录替换了我的项目的git目录。This is the best way:
http://github.com/guides/completely-remove-a-file-from-all-revisionsJust be sure to backup the copies of the files first.
EDIT
The edit by [Neon][1] got unfortunately rejected during review. See Neons post below, it might contain useful information!
[1]: https://stackoverflow.com/users/309261/neon
E.g. to remove all
*.gz
files accidentally committed into git repository:
$ du -sh .git ==> e.g. 100M $ git filter-branch --index-filter 'git rm --cached --ignore-unmatch *.gz' HEAD $ git push origin master --force $ rm -rf .git/refs/original/ $ git reflog expire --expire=now --all $ git gc --prune=now $ git gc --aggressive --prune=now
That still didn't work for me? (I am currently at git version 1.7.6.1)
$ du -sh .git ==> e.g. 100M
Not sure why, since I only had ONE master branch. Anyways, I finally got my git repo truely cleaned up by pushing into a new empty and bare git repository, e.g.
$ git init --bare /path/to/newcleanrepo.git $ git push /path/to/newcleanrepo.git master $ du -sh /path/to/newcleanrepo.git ==> e.g. 5M
(yes!)
Then I clone that to a new directory and moved over it's .git folder into this one. e.g.
$ mv .git ../large_dot_git $ git clone /path/to/newcleanrepo.git ../tmpdir $ mv ../tmpdir/.git . $ du -sh .git ==> e.g. 5M
(yeah! finally cleaned up!)
After verifying that all is well, then you can delete the
../large_dot_git
and../tmpdir
directories (maybe in a couple weeks or month from now, just in case...)
git reflog expire --expire=now --all
git gc --prune=now --aggressive
如果那不起作用,请尝试使用BFG工具来清理您的存储库。按照他们的建议,首先复制存储库。
git gc --prune=now
。 - Gergo Erdosimaster
以外的任何分支。无论如何,我已经修复了它并将解决方案添加到我的问题中。 - matanc1