Recover lost commit by known folder name

I accidentally lost a branch. I think this is in the reflog list, but it is too difficult to check everyone in it. I remember that a folder with some files was created in this branch, so it can be found by finding all the lost commits that affect the folder. So the question is: how can I find these commits?

+3
source share
2 answers

I just need to specify the path in the reflog command. It is important to use a '-' in front of the path if the working tree is missing

git reflog -- path/to/the/affected/folder
+2
source

You can run grep output git lstreeto find out about commits in a branch:

for ID in `git reflog | cut -d' ' -f1` # filter out the commit ID
do
  # show the tree for each commit and grep for the file there
  git ls-tree -r $ID | grep file/name && echo "File is on $ID"
done
0
source

Source: https://habr.com/ru/post/1775636/


All Articles