我有一个Git repo,我用rm(不是Git rm)删除了四个文件,我的Git状态是这样的:

#    deleted:    file1.txt
#    deleted:    file2.txt
#    deleted:    file3.txt
#    deleted:    file4.txt

我如何从Git中删除这些文件,而不需要手动查看并添加每个文件,就像这样:

git rm file1 file2 file3 file4

理想情况下,我正在寻找与git添加的方式相同的东西。是的,如果可能的话。


当前回答

如果你想把它添加到你的.gitconfig中,这样做:

[alias]
  rma = !git ls-files --deleted -z | xargs -0 git rm

然后你要做的就是跑:

git rma

其他回答

git commit -m 'commit msg' $(git ls-files --deleted)

在我已经删除了文件之后,这个方法对我有用。

类似的

git status | sed -s "s/^.*deleted: //" | xargs git rm 

也许吧。

你可以使用

git add -u

要将删除的文件添加到暂存区域,然后提交它们

git commit -m "Deleted files manually"
git ls-files --deleted -z | xargs -0 git rm 

也许这就是你正在寻找的。这对我有用。

仅仅

git add . && git commit -m "the message for commit" && git push