使用git add暂存仅已删除的文件 [英] Stage only deleted files with git add

查看:61
本文介绍了使用git add暂存仅已删除的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经运行了 git status ,看到了几个修改过的文件和几个删除过的文件. 是否可以仅暂存已删除或已修改的文件?

I have run git status and see several modified files and several deleted files. Is it possible to stage only deleted or only modified files?

推荐答案

如果混合使用已修改和已删除的文件,并且只想将已删除的文件暂存到索引中,则可以使用git ls-files作为过滤器.

If you have a mix of modified and deleted files and only want to stage deleted files to the index, you can use git ls-files as a filter.

git ls-files --deleted | xargs git add

如果仅希望将其应用于文件树的一部分,请提供一个或多个子目录作为ls-files的参数:

If you only want this to apply to part of the file tree, give one or more subdirectories as arguments to ls-files:

git ls-files --deleted -- lib/foo | xargs git add

要仅对修改后的文件执行相同操作,请使用--modified(-m)选项而不是--deleted(-d).

To do the same for only modified files, use the --modified (-m) option instead of --deleted (-d).

这篇关于使用git add暂存仅已删除的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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