Git:你如何检出所有被删除的文件? [英] Git: How do you checkout all deleted files?

查看:432
本文介绍了Git:你如何检出所有被删除的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在git中,我熟悉如何使用 git checkout - [< paths> ...] 语法来检出已删除的单个文件(这是推荐当你做 git status



要获得所有文件,你可以创建一个列表并且列表为上面的命令的参数。

然而,当你只想要所有已被删除的文件(即rw -rf在你的cwd中,然后你想恢复所有文件)
$ b

= h2_lin>解决方案

生成列表不是 hard:

  git diff --no-renames --name-only --diff-filter = D 

使它适用于 git checkout ,使用 -z xargs -0
pre $ g $ git diff - 不重命名 - 仅限名称--diff-filter = D -z |
xargs -0 git chec kout -

请注意,使用 git checkout -f - code>与上面的完全不同,因为 git checkout -f - 。会覆盖已修改但尚未添加到索引的文件,而上述将 从索引中提取仍在索引中的文件,但不再位于工作树中。



(如果你没有这样的修改文件, git checkout -f - 。可以工作,但是也可以这样做 git checkout - 。。)


In git I am familiar with how to checkout individual files that have been deleted using the git checkout -- [<paths>...] syntax (which is recommended when you do git status.

To get all the files you could create a list and give the list as the argument to the above command.

However when you just want all the files that have been deleted (i.e. rm -rf in your cwd and then you want to restore all files) generating that list is inelegant.

How do you checkout all deleted files?

解决方案

Generating the list is not that hard:

git diff --no-renames --name-only --diff-filter=D

To make it suitable for git checkout, use -z and xargs -0:

git diff --no-renames --name-only --diff-filter=D -z |
    xargs -0 git checkout --

Note that using git checkout -f -- . is quite different from the above, as git checkout -f -- . will overwrite files that are modified but not yet added to the index, while the above will only extract, from the index, files that are still in the index but are no longer in the work-tree.

(If you have no such modified files, git checkout -f -- . will work, but then so will git checkout -- ..)

这篇关于Git:你如何检出所有被删除的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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