使用 Git/GitHub 删除文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1983346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Deleting Files using Git/GitHub
提问by Zack
First off, I'm new to Git.
首先,我是 Git 的新手。
I deleted a bunch of files locally on my Mac using Finder. I want the files that I deleted to no longer show in the current branch, but they do.
我使用 Finder 在 Mac 本地删除了一堆文件。我希望我删除的文件不再显示在当前分支中,但它们确实如此。
Any Git users know a command to update the index?
任何 Git 用户都知道更新索引的命令吗?
回答by Samuel Mikel Bowles
I think this would be a simpler way to do what you want:
我认为这将是一种更简单的方法来做你想做的事:
git add . -A
Then you would just do:
然后你会这样做:
git commit -m "removed some files"
As noted above.
如上所述。
回答by miku
You can see deleted files, which are still 'tracked' with:
您可以看到已删除的文件,这些文件仍被“跟踪”:
git ls-files --deleted
To delete files from a branch, you can do something like this:
要从分支中删除文件,您可以执行以下操作:
git ls-files --deleted -z | xargs -0 git rm
From man git-rm
:
来自man git-rm
:
Remove files from the index, or from the working tree and the index. git-rm will not remove a file from just your working directory. (There is no option to remove a file 13 only from the work tree and yet keep it in the index; use /bin/rm if you want to do that.)
从索引或从工作树和索引中删除文件。git-rm 不会仅从您的工作目录中删除文件。(没有选择仅从工作树中删除文件 13 并将其保留在索引中;如果您想这样做,请使用 /bin/rm。)
Finally, to commit the "removal" do something like:
最后,要提交“删除”,请执行以下操作:
git commit -m "removed some files"
回答by Gareth
I don't know if this has been added to git since the previous answers, but I just used
我不知道自上一个答案以来是否已将其添加到 git 中,但我只是使用了
git add -u
git commit -m "Removed some files"
to achieve the same thing.
达到同样的目的。
回答by Chawathe Vipul S
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch deletefile.name' --prune-empty --tag-name-filter cat -- --all
git commit -m "Removed deletefile.name"
git push origin master --force
Replace deletefile.name with the file to remove. For in-depth detailed explanation go through the nice article https://help.github.com/articles/remove-sensitive-data
将 deletefile.name 替换为要删除的文件。如需深入详细的解释,请阅读这篇不错的文章https://help.github.com/articles/remove-sensitive-data