58

是否可以检查 git reflog 是否有对特定文件的所有提交。

我对文件 foo.txt 进行了提交,现在它不再显示在 git 历史记录中

git log foo.txt

我想搜索 reflog 以找到对该文件的所有提交,以便找到我的“丢失”提交。

4

4 回答 4

60

在寻找答案时遇到了这个问题,这很简单:git reflog -- $PATH,其中将包括修改和其他不可见的操作(但要注意,reflog 将被 gc 修剪)

于 2015-03-12T21:14:12.367 回答
59

尝试:

git rev-list --all -- foo.txt

这将为您提供包含 foo.txt 的所有提交的列表。

于 2011-06-10T19:43:09.633 回答
19

我会使用:

git rev-list --all --remotes --pretty=oneline foo.txt

--remotes 选项让你也可以使用你的遥控器, --pretty=oneline 让它也显示提交消息。当您在不知道名称的分支中寻找推送到远程的修改时非常有用。

于 2012-07-05T13:13:34.057 回答
1

I lost a change when I was cleaning up my history with rebase. I used something like this to search the reflogs:

for r in $(git reflog -- ${file} | cut -d ' ' -f1); do git show ${r}:${file}; done
于 2020-03-15T18:11:29.090 回答