查询 git reflog 以获取对特定文件的所有提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6311226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Query git reflog for all commits to a specific file
提问by cpjolicoeur
Is it possible to check the git reflog for all commits to a specific file.
是否可以检查 git reflog 以获取对特定文件的所有提交。
I made a commit to file foo.txt and now it no longer shows in the git history via
我提交了 foo.txt 文件,现在它不再通过以下方式显示在 git 历史记录中
git log foo.txt
I want to search the reflog to find all commits to this file so I can find my "lost" commit.
我想搜索 reflog 以找到对该文件的所有提交,以便我可以找到我的“丢失”提交。
回答by ralphtheninja
Try:
尝试:
git rev-list --all -- foo.txt
This will give you a list of all commits containing foo.txt.
这将为您提供包含 foo.txt 的所有提交的列表。
回答by Arkadiy Kukarkin
Came across this while searching for an answer, which is simple: git reflog -- $PATH
, which will include amends and other actions that will not be visible otherwise (though beware, reflog will be pruned by gc)
在搜索答案时遇到了这个问题,这很简单: git reflog -- $PATH
,其中将包括修改和其他不可见的操作(尽管要注意,reflog 将被 gc 修剪)
回答by wdev
I'd use:
我会用:
git rev-list --all --remotes --pretty=oneline foo.txt
The --remotes option lets you use also your remotes, the --pretty=oneline makes it display also the commit message. Very useful when you're looking for a modification pushed to remote in a branch you don't know the name of.
--remotes 选项还允许您使用遥控器, --pretty=oneline 使其还显示提交消息。当您在不知道其名称的分支中寻找推送到远程的修改时非常有用。
回答by glevand
I lost a change when I was cleaning up my history with rebase. I used something like this to search the reflogs:
当我使用 rebase 清理历史记录时,我丢失了一个更改。我用这样的东西来搜索引用:
for r in $(git reflog -- ${file} | cut -d ' ' -f1); do git show ${r}:${file}; done