0

So I am reading the Version Control with Git, 2nd Edition and I stumbled on this paragraph (page 51, section "Using git add")

Most of the day-to-day changes within your repository will likely be simple edits. After any edit and before you commit your changes, run git add to update the index with the absolute latest and greatest version of your file. If you don’t, you’ll have two different versions of the file: one captured in the object store and referenced from the index, and the other in your working directory.

What confuses me is the bolded sentence. So let's say I do the opposite, I change one file and then I run git add on it and now the file is staged. Well, it seems to me that now again I have two different version of the file: one captured in the object store and the other in my working directory and referenced the index. The difference is only that index now references the file in working directory rather than the one in repo.

Am I missing some insight here that author wanted to emphasize? How many different versions of the file can exist in "git"? The "git" is also not clear but I suppose it means on working directory + object store + index.

matori82
  • 3,669
  • 9
  • 42
  • 64

2 Answers2

1

If you edit a file and don't add it, git will have 2 versions of it because it's not managed in the object store. after you add it the version you had locally is now one from git object store

DelGiudice
  • 1,847
  • 1
  • 17
  • 14
  • The documentation clearly refers to making a "simple edit", not creating a new file, so a copy in the object store clearly *does* exist in the scenario, even pre-commit. (This is being pedantic, to be sure, but this question came up on account of the OP reading the documentation with an expectation of it being pedantically correct, as opposed to for its intended meaning). – Charles Duffy Mar 31 '15 at 21:53
1

The critical concept being conveyed is one you already understand: That the git add step is necessary to prevent the working tree and the index from differing from each other.

"Two different versions" is clearly not intended to mean only two versions can exist; it rather emphasizes that the content in the working tree is otherwise not included in the index, a concept which folks new to git often fail to grasp.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441