Git:如何使用“??”删除 git status -s 中列出的文件,这些是我添加到本地存储库的文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7559985/
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
Git: How do I remove files listed in git status -s with "??", these are files I added to local repo?
提问by KRB
I have a few files in my git status -s listed as,
我的 git status -s 中有几个文件列为,
?? file1
?? filepath/file2
?? file3
?? filepath/file4
?? 文件 1
?? 文件路径/文件 2
?? 文件 3
?? 文件路径/文件 4
I have been ignoring these and going along committing, pushing, pulling, and I am at the point where there are too many of these in my status report.
我一直忽略这些并继续提交,推动,拉动,而我的状态报告中有太多这些。
I tried git rm file1. It doesn't work. It says fatal path doesn't match any files.
我试过 git rm file1。它不起作用。它说致命路径与任何文件都不匹配。
Thanks!
谢谢!
回答by dmedvinsky
These are untracked files, i.e. the files which are present in your file system, but you've never added them to your repository by git add
.
这些是未跟踪的文件,即文件系统中存在的文件,但您从未通过git add
.
If you don't need them, you can just rm
them. Or simply git clean -fd
if you want to delete them all. If you want to do some filtering before removing them, you can do:
如果你不需要它们,你可以只需要rm
它们。或者只是git clean -fd
如果你想全部删除它们。如果您想在删除它们之前进行一些过滤,您可以执行以下操作:
git ls-files -o --exclude-standard | grep 'my custom filter' | xargs rm
If you want to keep those files, but want git status
to ignore them, add them to .gitignore
file. Read man gitignore
for the details.
如果您想保留这些文件,但又想git status
忽略它们,请将它们添加到.gitignore
文件中。阅读man gitignore
详情。
回答by klaustopher
You can temporarily add those to your .gitignore
file so they won't show up in your git status
and you don't accidentally add them.
您可以暂时将这些添加到您的.gitignore
文件中,这样它们就不会出现在您的文件中git status
,也不会意外添加它们。
That git rm file
doesn't work because those files have not been added to your repository so there is nothing to delete
这git rm file
不起作用,因为这些文件尚未添加到您的存储库中,因此无法删除任何内容
回答by Matthieu Moy
These files are untracked, hence git rm
does not work (it is the command to remove files from Git's control). You essentially have two options:
这些文件未被跟踪,因此git rm
不起作用(这是从 Git 控制中删除文件的命令)。您基本上有两个选择:
Ignore these files. Read gitignore. You can either add the ignore patterns to a
.gitignore
file that you can commit and share with your co-workers, or in a per-repo.git/info/exclude
, or in a per-user.config/git/ignore
file.Delete these files. Any tool you use to delete files when you're not using Git would work. Additionally, Git provides you git cleanto help you in this task.