How to display git ls-file result in a tree-like format

git

Let's say I have a git repo which output with tree is:

.                                                                                                                                                                                  
├── .gitignore                                                                   
├── untracked-file                                                                                                  
├── rep1                                                                                                                                                                           
│   └── tracked-file1                                                                                                                                                                      
├── rep2                                                                                                                                                                           
│   └── repb                                                                                                                                                                       
│       └── tracked-file2                                                                                                                                                                  
└── rep3                                                                                                                                                                           
    └── ignored-file  

And .gitignore with rep3/ignored-file.

git ls-files output will be:

rep1/tracked-file1
rep2/repb/tracked-file2

How can I have:

.
├── .gitignore
├── rep1
│   └── file1
└── rep2
    └── repb
        └── file2

Instead ?

I think this is a good start:

tree -P <(git ls-files | tr '\n' '|')

Since -P means only list following pattern but I don't know how to add parenthesis to this one.

Best Answer

It sounds like the gitree utility (c/o creator jpwilliams) might fit the bill. (I concede that this does, however, require using another 3rd party tool.)

Similarly, this other answer points to using a different tool: tree-extended (c/o creator rulyotano).

Related Question