Git - rm 相当于“add .”?

发布于 2024-08-29 13:49:34 字数 71 浏览 13 评论 0原文

如果您从命令行使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谁把谁当真 2024-09-05 13:49:34

以下内容应将所有文件(无论是否删除)暂存在索引中:

git add -A

The following should stage all files, whether deleted or not, in the index:

git add -A
北城半夏 2024-09-05 13:49:34

嗯,已更改但未更新下列出的文件已在索引中。您可以使用 git checkout 放弃更改。
要删除新文件,但尚未添加到索引中,您可以使用 git clean 。
但是要删除已修改的文件和索引中的文件......没有简单的解决方案,您可能必须使用 git rm 和 git ls-files 的组合。

编辑:
git ls-files -m 应该列出您正在查找的文件。将其与 git rm 结合起来就完成了:

git-ls files -m | xargs git rm // NOT TESTED

编辑:
我可能误解了你问题的一部分。我的解决方案将删除已更改但未更新下列出的所有文件。如果您想删除列为“已删除”的文件,则必须使用 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 and git ls-files.

EDIT:
git ls-files -m should list the files you are looking for. Combine it with git rm and you are done:

git-ls files -m | xargs git rm // NOT TESTED

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.

放赐 2024-09-05 13:49:34

在状态的“已更改但未更新”部分中显示为已删除的文件将从工作树中删除,但不会从索引中删除。要在索引中暂存删除(即从索引中删除文件),您可以执行以下操作:

git diff -z --name-only --diff-filter=D | git update-index --remove -z --stdin

--diff-filter=D 仅显示已删除文件与索引的差异,- -name-only 仅打印文件名,-z 使用 NUL 分隔文件名,这样您就不必担心带有嵌入换行符的文件名。 update-index 然后从索引中删除给定的文件。

如果您有支持 -0xargs 版本,那么您可以做得稍微简单一些:

git diff -z --name-only --diff-filter=D | xargs -0 git rm

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:

git diff -z --name-only --diff-filter=D | git update-index --remove -z --stdin

--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:

git diff -z --name-only --diff-filter=D | xargs -0 git rm
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文