1

How to read git index file and extract all paths to text file?

except

git ls-files > out.txt

I mean using other things like regex or something else?

DilithiumMatrix
  • 17,795
  • 22
  • 77
  • 119
Dmitrij Holkin
  • 1,995
  • 3
  • 39
  • 86
  • Depends on Operating System, but you can pipe output on linux and mac http://stackoverflow.com/questions/6674327/redirect-all-output-to-file – online Thomas Nov 29 '15 at 17:29
  • _"I mean using other things like regex or something else?"_ The index file itself is a binary file; before regex can be applied to filter the data, the file's contents must first be parsed into readable format, and the `git ls-files` command does exactly that. What exactly speaks against using the git command? – Matthias Fischer Nov 29 '15 at 19:02
  • Unless I'm misunderstanding what you're trying to do, `git ls-files > out.txt` should do exactly what you want - it reads the contents of the index file in the current git branch and saves them into a text file, in this case `out.txt`. Have you tried using that command, and if so, can you explain how the command's output differs from what you're trying to obtain? – Matthias Fischer Nov 29 '15 at 19:59
  • Do you have git installed on your machine? Without git, it's likely a hassle to try to convert the index file into readable format (according to [this thread](http://stackoverflow.com/q/1532405/2191154)). If you do have git installed, simply create a new repository, then copy your index file into the repository and overwrite the existing one. After you've done that, you can read the file using `git ls-files` - I just tried it myself. – Matthias Fischer Nov 29 '15 at 20:37

1 Answers1

1

To see the content of the index file, use the command git ls-files.
Assuming you're on either Windows, Linux, or Mac, you can reroute the command's output into a text file by using git ls-files > out.txt.

See: What does the git index contain EXACTLY?

Community
  • 1
  • 1
Matthias Fischer
  • 553
  • 4
  • 18