从“已更改但未更新”中删除所有已删除的文件在Git中 [英] Remove all deleted files from "changed but not updated" in Git
问题描述
当我运行 git status
时,我有一堆行
deleted:dir / file.js
我可以用 git checkout - dir / file.js
,但是这样做一定不那么费力。 (是的,我知道我应该首先使用 git rm
...)
[ 更新:正如Mark指出的那样, git checkout -
实际上会恢复一个被删除的文件,而我认为它会将它从git中删除指数。我有点困惑,因为当你运行 git status
时,它说:
使用git checkout - < file> ...放弃工作目录中的更改
<对我来说,放弃更改并不意味着恢复你删除的文件,但在git术语中,我认为这是有道理的。] 解决方案
当rampion指出,你仍然可以使用 git rm
来删除已在工作副本中删除的文件(例如, code> git rm dir / file.js )。如果你有很多这些文件被列为已删除:,在已更改但未更新下,我会先检查 git ls-files --deleted
会生成这些文件的列表,如果是这样,请将它们删除:
git ls-files --deleted -z | xargs -0 git rm
When I run git status
, I have a bunch of lines of the form
deleted: dir/file.js
I can remove each of these individually with git checkout -- dir/file.js
, but there must be a less painstaking way to do so. (And yes, I know I should've used git rm
in the first place...)
[Update: As Mark points out below, git checkout --
actually restores a deleted file, whereas I'd thought that it deleted it from the git index. I was a little baffled, because when you run git status
, it says:
use "git checkout -- <file>..." to discard changes in working directory
To me, "discard changes" doesn't mean "restore a file you deleted," but in git terminology I suppose this makes sense.]
As rampion points out, you can still use git rm
to stage the deletion of files that have already been deleted in your working copy (e.g. just git rm dir/file.js
in your case.) If you have a lot of these files listed as "deleted:" under "Changed but not updated", I would first check that git ls-files --deleted
produces a list of these files, and, if so, delete them with:
git ls-files --deleted -z | xargs -0 git rm
这篇关于从“已更改但未更新”中删除所有已删除的文件在Git中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!