Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print current files on git index?

Tags:

git

I can print the currently committed tree with:

git cat-file -p master^{tree}

100644 blob 8fe01e69e28f7c6997c0f5372c015363947582d8    .angular-cli.json
100644 blob 6975847ed5aa229532141a971337caca0a401451    .dockerignore
100644 blob 1f354482f8681a1b017bc4fdde17a4802e84b06a    .editorconfig
100644 blob 9c4b02c9bd7338416bcb4037c5d5fac4c116bca5    .env.example
040000 tree d9e02522647d4f28dc40f62dca564afa48fba019    .github

I'm now looking to know how to print files in my current index, staged files? I'm looking for a low-level command like git cat-file and not for a high-level command.

I see there is this index file:

ls .git/index 
.git/index

But what is the command to print its content (again low-level command, with an argument to this file)?

like image 357
Jas Avatar asked Oct 15 '25 06:10

Jas


1 Answers

git cat-file only prints the contents of objects (trees, blobs, etc). If you want to display the contents of the index, you need the similarly named - but different - git ls-files. Use the --stage command to show the stage:

$ git ls-files --stage
100644 234d33c1e3554c5f3428f0d7d5c508e4cec6d148 0   README.md
100644 efdf34514e7d7f71ef1a53c441fabbcef39c7087 0   src/foo.h
100644 a2d78b7702b46a25dd1fe86ec230a7911ed18e36 0   src/foo.c
100644 7807599d8d4971566e3b92e474ee88ad9f0217aa 0   test.c

This shows you the contents of the index with the stage information, including the object ID, stage level and file mode. You could also show the contents of the disk cache information instead: metadata like the timestamp and filesize, which git uses to determine if a file may have changed on disk and needs to be examined. To view that information, then you can use the --debug flag:

$ git ls-files --debug
README.md
  ctime: 1523823765:79574029
  mtime: 1523823765:79245702
  dev: 16777221 ino: 34669602
  uid: 501      gid: 20
  size: 8253    flags: 0
src/foo.c
  ctime: 1523830223:524847547
  mtime: 1523830223:524623074
  dev: 16777221 ino: 34676974
  uid: 501      gid: 20
  size: 4071    flags: 0
src/foo.h
  ctime: 1523752084:2627730
  mtime: 1523752084:2060254
  dev: 16777221 ino: 34621108
  uid: 501      gid: 20
  size: 36809   flags: 0
tests/response.c
  ctime: 1523826062:78659995
  mtime: 1523826062:78659995
  dev: 16777221 ino: 34672776
  uid: 501      gid: 20
  size: 30615   flags: 0
like image 65
Edward Thomson Avatar answered Oct 17 '25 21:10

Edward Thomson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!