[英]Git: How to checkout all deleted files through whole history
我想通过整个历史记录恢复所有已删除的文件,这意味着在删除它的提交之前将文件签出到提交?
Within a bash context*, you can get a sorted list of all deleted files from your repo with 在bash context *中,您可以从repo中获取所有已删除文件的排序列表
git log --all --diff-filter=D --name-only --pretty=format:'' | sort | uniq
where 哪里
--all
means log all commits, regardless of the current position of HEAD
--all
表示记录所有提交,无论HEAD
的当前位置如何
--diff-filter=D
filters displayed commits along this condition : " D
", meaning "deleted" --diff-filter=D
过滤器显示沿此条件的提交:“ D
”,表示“已删除”
--name-only
outputs the names of the files --name-only
输出文件的名称
--pretty=format:''
shuts down any other output than file names --pretty=format:''
关闭除文件名之外的任何其他输出
and the git command then formed returns a list which is sent to 然后形成的git命令返回一个发送给的列表
| sort
| sort
to sort the list alphabetically, and then | sort
按字母顺序对列表进行排序,然后
| uniq
| uniq
to keep only one instance for each doubled line (or else a file deleted then re-created then re-deleted would appear twice in the list) | uniq
只为每个doubled行保留一个实例(否则删除文件然后重新创建然后重新删除将在列表中出现两次)
Of course, you might also want to restrict the range to take into account for the history traversal. 当然,您可能还希望限制范围以考虑历史遍历。 If you need only commits which were deleted from, let's say, branch
super-feature
, add that as the <revision range>
for log (see doc ) which, when omitted, falls back to HEAD
: 如果您只需要从中删除的提交,比如分支
super-feature
,请将其添加为log的<revision range>
(请参阅doc ),当省略时,将返回HEAD
:
git log --all --diff-filter=D --name-only --pretty=format:'' master..super-feature | sort | uniq
* (either natively on linux-based systems, or for Windows users in GitBash for example) * (本机在基于Linux的系统上,或者用于GitBash中的Windows用户)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.