开发者

With Git, how do I commit a load of deleted files in one go?

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 commit -a

should work as long as those are your only changes (it will add all unstaged files and commit).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜