0

Whether we use checkout or reset, when we jump from commit to commit, the index keeps matching the now-current commit.

When I ask people how to see what files are staged in the index for the now-current commit, they tell me: git ls-files -s

But git ls-files -s does not seem to be what I am looking for.
This command just lists the tracked files of a sub-tree with the current directory being the root of it. If I move to another directory, the output of git ls-files -s changes!

Really, is there a command out there that will solidly give me the tracked files for a commit after I jump from some other commit to it?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • What is the importance of "after I jump from some other commit to it"? I mean, the list of tracked files for a particular commit does not change whether you jump from a commit to it or whether you just cloned a repository, or whatever reason lets you check out a certain commit. – j6t Mar 15 '17 at 22:40

1 Answers1

0

If you want to do this a lot you could put something like this in a shell function or script.

git ls-files --full-name -s "$(git rev-parse --show-cdup)"
CB Bailey
  • 755,051
  • 104
  • 632
  • 656
  • From your description, listing files staged in the index, `ls-files` is the correct command but it is, by design, context sensitive like `diff`. if you want the behavior where the output doesn't depend on the particular subdirectory then you need to script around this. – CB Bailey Mar 15 '17 at 22:59
  • Or, use `git -C $(git rev-parse --show-toplevel) ls-files -s`: same basic idea, we run the command at the top level (instead of "as if at the top level"). – torek Mar 16 '17 at 00:37