刚接触这东西,会使用GitHub for windows 之后,感觉挺好用的。
不过最近发现,代码库已经有90M大小了。想一想,除了把ttf字体文件提交了之外,图片素材,和编译后的class文件都提交了。
网上找一些方法,删除历史记录。综合一下,总算成功了。
官方教程:
https://help.github.com/articles/remove-sensitive-data
相关教程:
http://yihui.name/cn/2010/12/animation-update-1-1-5/
http://www.azhowto.com/removing-sensitive-data-from-git/
其中要填的是路径。官方教程里就位于根目录,所以直接写的文件名。
上面还提到了,windows下要用双引号。(其实后来发现单引号也行)
路径分隔符,要使用斜杠 /
可以这样,删除生成文件。
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch ./myproject/bins/*" --prune-empty --tag-name-filter cat HEAD -- --all
PS:
又试了几下,上面的命令好像有些问题了,也可以用这条命令
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch *.jar" HEAD -- --all
官方教程里的命令好像有点问题,在 cat 后面少了个 HEAD
参考网上的一些资料,最后我用的是这样的命令
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch *.class' --prune-empty --tag-name-filter cat HEAD -- --all
然后 按照Animation 文章里面的,运行后面几条命令,把改动push 到远端服务器上。
然后把本地历史文件也情况,这下 du -sh 就看到文件夹已经只有 100多K 了
git push origin master --force
rm -Force -R .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
PS: 某处看到的,添加到 .gitignore 之后,有些文件还是被跟踪了,因为这些文件已经被 add了。 只要 git rm 这些文件,ignore 列表就生效了。
git rm --cached git rm会本地删除文件,并取消git的跟踪。 用 git rm --cached 可以本地不删除,并取消git 的跟踪。然后 commit 就好啦
本人CSDN博客目录: