使用Git,如何一次性提交大量已删除的文件?

时间:2010-01-23 00:20:37

标签: git

我想要提交一大堆已删除的文件。

但我不想为每一个输入git rm。

如果我输入git rm。 -r它会尝试删除所有内容。

我可以输入什么来一次性提交所有这些删除?

请参阅下面的git状态  已更改但未更新:    (使用“git add / rm ...”来更新将要提交的内容)    (使用“git checkout - ...”放弃工作目录中的更改)

   deleted:    ProjectX/ProjectX/Content/Site.css
   deleted:    ProjectX/ProjectX/Controllers/HomeController.cs
   deleted:    ProjectX/ProjectX/Global.asax
   deleted:    ProjectX/ProjectX/Global.asax.cs
   deleted:    ProjectX/ProjectX/Models/HomeIndexView.cs
   deleted:    ProjectX/ProjectX/ProjectX.csproj
   deleted:    ProjectX/ProjectX/Properties/AssemblyInfo.cs
   deleted:    ProjectX/ProjectX/Scripts/MicrosoftAjax.debug.js
   deleted:    ProjectX/ProjectX/Scripts/MicrosoftAjax.js
   deleted:    ProjectX/ProjectX/Scripts/MicrosoftMvcAjax.debug.js
   deleted:    ProjectX/ProjectX/Scripts/MicrosoftMvcAjax.js
   deleted:    ProjectX/ProjectX/Scripts/MicrosoftMvcValidation.debug.js
   deleted:    ProjectX/ProjectX/Scripts/MicrosoftMvcValidation.js
   deleted:    ProjectX/ProjectX/Scripts/jquery-1.3.2-vsdoc.js
   deleted:    ProjectX/ProjectX/Scripts/jquery-1.3.2.js
   deleted:    ProjectX/ProjectX/Scripts/jquery-1.3.2.min-vsdoc.js
   deleted:    ProjectX/ProjectX/Scripts/jquery-1.3.2.min.js
   deleted:    ProjectX/ProjectX/Scripts/jquery.validate-vsdoc.js
   deleted:    ProjectX/ProjectX/Scripts/jquery.validate.js
   deleted:    ProjectX/ProjectX/Scripts/jquery.validate.min-vsdoc.js
   deleted:    ProjectX/ProjectX/Scripts/jquery.validate.min.js
   deleted:    ProjectX/ProjectX/Views/Home/Index.aspx
   deleted:    ProjectX/ProjectX/Views/Shared/Error.aspx
   deleted:    ProjectX/ProjectX/Views/Shared/Site.Master
   deleted:    ProjectX/ProjectX/Views/Web.config
   deleted:    ProjectX/ProjectX/Web.config

2 个答案:

答案 0 :(得分:7)

git add -u

将进行所有更改,包括删除。这通常是最简单的前进方式。如果这更合适,您可以将其限制为某些路径。

e.g。

git add -u ProjectX

执行其中任一操作后,您可以使用重置的路径形式“取消”您不想要的任何更改。

git reset -- dontcommitme.txt

要绝对确定您只是暂存删除,您必须执行以下操作:

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

或者,如果您有权访问GNU xargs并且需要使用文件名中的空格进行复制:

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

答案 1 :(得分:2)

git commit -a

应该工作,只要这些是您唯一的更改(它将添加所有未暂存的文件并提交)。