Git - rm 相当于“add .”?
如果您从命令行使用 Git,是否有一种方法可以一次性删除“已更改但未更新”列表中所有要删除的文件?而不是使用通配符进行手动删除。
If you're using Git from the command line, is there a way to delete in one fell swoop all the files to be deleted in the Changed but not updated list? Rather than doing manual removes using wildcards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下内容应将所有文件(无论是否删除)暂存在索引中:
The following should stage all files, whether deleted or not, in the index:
嗯,已更改但未更新下列出的文件已在索引中。您可以使用 git checkout 放弃更改。
要删除新文件,但尚未添加到索引中,您可以使用 git clean 。
但是要删除已修改的文件和索引中的文件......没有简单的解决方案,您可能必须使用 git rm 和 git ls-files 的组合。
编辑:
git ls-files -m 应该列出您正在查找的文件。将其与 git rm 结合起来就完成了:
编辑:
我可能误解了你问题的一部分。我的解决方案将删除已更改但未更新下列出的所有文件。如果您想删除列为“已删除”的文件,则必须使用
git diff
,正如 Charles Bailey 在他的回答中所示。Well, the files listed under Changed but not updated are already in the index. You can discard their changes by using
git checkout .
To remove file that are new, but have not been added to the index you can use
git clean
.But for deleting files that are modified and in the index ... well there is no easy solution, you probably have to use a combination of
git rm
andgit ls-files
.EDIT:
git ls-files -m
should list the files you are looking for. Combine it withgit rm
and you are done:EDIT:
I probably misunderstood a part of your question. My solution will delete all files listed under Changed but not updated. If you want to remove the files listed as deleted, you have to use
git diff
as Charles Bailey shows in his answer.在状态的“已更改但未更新”部分中显示为已删除的文件将从工作树中删除,但不会从索引中删除。要在索引中暂存删除(即从索引中删除文件),您可以执行以下操作:
--diff-filter=D
仅显示已删除文件与索引的差异,- -name-only
仅打印文件名,-z
使用 NUL 分隔文件名,这样您就不必担心带有嵌入换行符的文件名。update-index
然后从索引中删除给定的文件。如果您有支持
-0
的xargs
版本,那么您可以做得稍微简单一些:Files shown as deleted in the "Changed but not updated" section of status are deleted from the work tree but not from the index. To stage the deletion in the index (i.e. remove the file from the index) you can do:
--diff-filter=D
shows only the differences to the index that are deleted files,--name-only
just prints their name and-z
uses NUL to separate file names so that you don't have to worry about filenames with embedded newlines.update-index
then removes the given files from the index.If you have a version of
xargs
that supports-0
then you could do the slightly simpler: