2

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).

Charles
  • 988
  • 1
  • 11
  • 28
  • 2
    Your question is already tagged with `git-ls-tree`, a command that seems to be sufficient for your requirement. Just wondering, isn't `git-ls-tree` what you're looking for? Additionally, I believe tools like `tig` may be more convenient to peek deeper down to the history. – terrorrussia-keeps-killing Apr 11 '22 at 09:34
  • I just don't know how to use `ls-tree` properly it seems, I get errors in some cases. And it doesn't have to be that anyways, that's more of a suggestion, and I am open to more. – Charles Apr 11 '22 at 13:01
  • Also `tig` (which I am discovering as I speak is 1. slow in git bash on Windows and 2. Shows me a tree of the history on one half the screen and diffs with parent on the other. Could expand on how `tig` could help me with my original question ? – Charles Apr 11 '22 at 13:04
  • `git-ls-tree` allows you inspecting commit/tree content. Say, you do `git ls-tree `, get a list of hashes for trees and blobs (= directories and files at _that_commit), and then use `git ls-tree ` to walk through trees untill you find the file you're interested in, and then do `git cat-file -p ` to get the file content. I'm not sure how it works with LFS (have never worked with it, but I guess it's relevant to big blobs only), but if your commit is still reachable, then you can inspect the folder structure of the commits of your interest. – terrorrussia-keeps-killing Apr 11 '22 at 15:42
  • If you find `git-ls-tree` too tedious, `tig` (or any other appropriate tools, not necessarily `tig`, doing the same as I described above) allows you walking through trees. You see a two-pane log/diff view because you pressed `Enter`. Try pressing `t` at a certain commit (and `h` for quick help). – terrorrussia-keeps-killing Apr 11 '22 at 15:44

1 Answers1

0

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250