使用Git,我该如何一次性提交一大堆被删除的文件? [英] With Git, how do I commit a load of deleted files in one go?

查看:156
本文介绍了使用Git,我该如何一次性提交一大堆被删除的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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



如果我输入git rm。



如果我一次性提交所有这些删除操作,我应该输入什么内容?



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

 已删除:ProjectX / ProjectX / Content / Site.css 
已删除: ProjectX / ProjectX / Controllers / HomeController.cs
已删除:ProjectX / ProjectX / Global.asax
已删除:ProjectX / ProjectX / Global.asax.cs
已删除:ProjectX / ProjectX / Models / HomeIndexView .cs
已删除:ProjectX / ProjectX / ProjectX.csproj
已删除:ProjectX / ProjectX / Properties / AssemblyInfo.cs
已删除:ProjectX / ProjectX / Scripts / MicrosoftAjax.debug.js
已删除:ProjectX / ProjectX / Scripts / MicrosoftAjax.js
已删除:ProjectX / ProjectX / Scripts / MicrosoftMvcAjax.debug.js
已删除:ProjectX / ProjectX / Scripts / M icrosoftMvcAjax.js
已删除:ProjectX / ProjectX / Scripts / MicrosoftMvcValidation.debug.js
已删除:ProjectX / ProjectX / Scripts / MicrosoftMvcValidation.js
已删除:ProjectX / ProjectX / Scripts / jquery-1.3 .2-vsdoc.js
已删除:ProjectX / ProjectX / Scripts / jquery-1.3.2.js
已删除:ProjectX / ProjectX / Scripts / jquery-1.3.2.min-vsdoc.js
已删除:ProjectX / ProjectX / Scripts / jquery-1.3.2.min.js
已删除:ProjectX / ProjectX / Scripts / jquery.validate-vsdoc.js
已删除:ProjectX / ProjectX / Scripts / jquery.validate.js
已删除:ProjectX / ProjectX / Scripts / jquery.validate.min-vsdoc.js
已删除:ProjectX / ProjectX / Scripts / jquery.validate.min.js
已删除:ProjectX / ProjectX / Views / Home / Index.aspx
已删除:ProjectX / ProjectX / Views / Shared / Error.aspx
已删除:ProjectX / ProjectX / Views / Shared / Site.Master
已删除:ProjectX / ProjectX / Views / Web.config
已删除:ProjectX / ProjectX / Web.c onfig


解决方案

  git添加-u 

将暂存所有更改,包括删除操作。这通常是最简单的方式。你可以限制它到某些路径,如果这是更合适的。



例如

  git add -u ProjectX 

完成后,您可以使用路径形式重置为'您不需要任何更改。

  git reset  -  dontcommitme.txt 
$ b

为了确保您只是暂存删除,您必须执行下列操作:

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

或者如果您有权访问GNU xargs并需要用空格文件名:

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


I have a load of deleted files I want to commit.

But I don't want to type git rm for each one.

If i type git rm . -r it will try and delete everything.

What do I type to commit all these deletes in one go?

See git status below Changed but not updated: (use "git add/rm ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory)

   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

解决方案

git add -u

Will stage all changes including deletions. This is usually the simplest way forward. You can restrict it to certain paths if this is more suitable.

e.g.

git add -u ProjectX

After doing either you can use the path form of reset to 'unstage' any changes that you didn't want.

git reset -- dontcommitme.txt

To be absolutely sure that you are only staging deletions, you would have to do something like this:

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

Or if you have access to a GNU xargs and need to copy with whitespace in filenames:

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

这篇关于使用Git,我该如何一次性提交一大堆被删除的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆