将它们添加到.gitignore后,从远程存储库中删除目录 [英] Remove directory from remote repository after adding them to .gitignore
问题描述
.gitignore
文件,添加了一个应该忽略的目录。一切正常,但(现在忽略)目录留在github上。 如何从github和版本库历史中删除该目录?
git rm -r --cached some-directory
git commit -m'删除现在被忽略的目录some-directory'
git push origin master
如果没有重写存储库的历史记录,则无法从历史记录中删除文件 - 如果其他人正在处理您的存储库,或者您从多台计算机使用它。如果你仍然想这样做,你可以使用 另外,请注意 I committed and pushed some directory to github. After that, I altered the How do I delete that directory from github and the repository history? The rules in your You can't delete the file from your history without rewriting the history of your repository - you shouldn't do this if anyone else is working with your repository, or you're using it from multiple computers. If you still want to do that, you can use Additionally, note the output from The 这篇关于将它们添加到.gitignore后,从远程存储库中删除目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! git filter-branch
来重写历史 -
git rm -r --cached some-directory
会是这样的:
rm'some -b目录/ product / cache / 1 / small_image / 130x130 / small_image.jpg'
rm'some-directory / product / cache / 1 / small_image / 135x / small_image.jpg'
rm'some-directory /.htaccess'
rm'some-directory / logo.jpg'
rm
是git关于存储库的反馈;这些文件仍然在工作目录中。.gitignore
file adding a directory that should be ignored. Everything works fine, but the (now ignored) directory stays on github..gitignore
file only apply to untracked files. Since the files under that directory were already committed in your repository, you have to unstage them, create a commit, and push that to GitHub:git rm -r --cached some-directory
git commit -m 'Remove the now ignored directory "some-directory"'
git push origin master
git filter-branch
to rewrite the history - there is a helpful guide to that here.git rm -r --cached some-directory
will be something like:rm 'some-directory/product/cache/1/small_image/130x130/small_image.jpg'
rm 'some-directory/product/cache/1/small_image/135x/small_image.jpg'
rm 'some-directory/.htaccess'
rm 'some-directory/logo.jpg'
rm
is feedback from git about the repository; the files are still in the working directory.