Query git reflog for all commits to a specific file

GitReflog

Git Problem Overview


Is it possible to check the git reflog for all commits to a specific file.

I made a commit to file foo.txt and now it no longer shows in the git history via

git log foo.txt

I want to search the reflog to find all commits to this file so I can find my "lost" commit.

Git Solutions


Solution 1 - Git

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)

Solution 2 - Git

Try:

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

This will give you a list of all commits containing foo.txt.

Solution 3 - Git

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.

Solution 4 - Git

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncpjolicoeurView Question on Stackoverflow
Solution 1 - GitArkadiy KukarkinView Answer on Stackoverflow
Solution 2 - GitralphtheninjaView Answer on Stackoverflow
Solution 3 - GitwdevView Answer on Stackoverflow
Solution 4 - GitglevandView Answer on Stackoverflow