gitgit-ls-tree

git ls-tree output of working directory?


I am looking for a way to have output in the same manner as ls-tree, but of my working directory. Whenever I run git ls-tree . it says fatal: Not a valid object name .


Solution

  • git ls-tree only works with git refs, e.g. ls-tree HEAD or ls-tree 1.9.1

    Try git ls-files. You probably want the -s and/or -m flags.


    As you point out, git ls-files -s will list the files in the index (i.e. files that have been staged).

    In theory, you could mess with the index, run git ls-files -s, then try restore it, e.g.

    git commit
    git add .
    git ls-files -s
    git reset .
    git reset --soft HEAD^
    

    Seems right, and worked in a simple test, but could eat all your files.