Git : explore folders tructure of old commit without checking it out

326 Views Asked by At

I want to look at the folder structure of an old commit that I cannot checkout anymore (it had some Git LFS stuff which is now broken beyond my power to repair it).

I can already diff it to its parent and learn a lot, but I also want to see the contents of other folders and files (even if they weren't modified by that commit).

1

There are 1 best solutions below

0
On

You could combine git ls-tree and git cat-file to quickly show any file with part of a pattern.

In a Windows CMD:

git ls-tree --full-tree -r @ | awk '/comm/ { cmd="git cat-file blob " $3; print "\n\n"$4"\n-------"; while ((cmd^|getline result)^>0) { print result }; close(cmd) }'

In a git bash:

git ls-tree --full-tree -r @ | awk '/comm/ { cmd="git cat-file blob " $3; print "\n\n"$4"\n-------"; while ((cmd|getline result)>0) { print result }; close(cmd) }'

Replace 'comm' with any part of the files you want to see.

Or use awk '// ...' to list all the files and display their content.