0

While I am learning about git checkout -- file1.txt, I came across this link related to argument disambiguation. In this manual, what does "Checking out files out of the index" mean?

dgor
  • 704
  • 6
  • 19
  • For that, you need to understand what index is. The index is a single, large, binary file in `/.git/index`, which lists all files in the current branch. Check [this](https://stackoverflow.com/questions/3689838/whats-the-difference-between-head-working-tree-and-index-in-git) SO question out. – Parth Shah Jul 09 '20 at 18:47
  • Does this answer your question? [What's the difference between HEAD, working tree and index, in Git?](https://stackoverflow.com/questions/3689838/whats-the-difference-between-head-working-tree-and-index-in-git) – LeGEC Jul 09 '20 at 21:00

2 Answers2

0

Don't forget the new git restore command, available from Git 2.23 (August 2019), and which replaces the old confusing git checkout command.

With git restore --staged, you would explicitly restore a file content from the index (see also "What does the git index contain EXACTLY?")

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

The index lists the repo content for a work tree path (it's an index after all, names and pointers to related content), and it's got a timestamp so Git can quickly check whether the work tree content has changed.

So when you git add, Git adds what you added to the repo (you can do this directly with git hash-object -w) and updates the index entry to point to the added content (you can do this directly with git update-index --cacheinfo or --index-info).

Checkout from the index reads the index entry, then reads that content from the repo's object db into the work tree.

jthill
  • 55,082
  • 5
  • 77
  • 137