2

I'm currently reviewing Practical Git by Johan Abildskov in preparation for an upcoming job. The first example I came across seems to be impossible.

Here's how it starts:

$ ls
A B C D
$ git status
On branch master
nothing to commit, working tree clean
$ echo testing > A
$ git status
On branch master
nothing to commit, working tree clean

How did he get to this situation? If A is untracked, wouldn't git alert him about the untracked file? If A IS tracked, wouldn't git alert him that the file had changed?

I've been wracking my brain, but I can't figure out how your repository would get to this state.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
NaNCat
  • 119
  • 1
  • 6
  • 3
    Maybe he has `A` listed in the `.gitignore`? – Cory Kramer Dec 22 '21 at 20:14
  • 4
    What was the content of `A` before the change? If it already contained the single word "testing" `git` would not detect a change. `git` does not care for *change date* it only looks at the content of files. – Timothy Truckle Dec 22 '21 at 20:31

2 Answers2

2

I can think of a few ways this can happen.

First, you could have the configuration option status.showUntrackedFiles set to no (either locally for this repo, or globally).

Second, you could have a .gitignore entry configured to ignore A.

Third, as Timothy Truckle mentioned in the comments, echo testing > A overwrites the contents of A with the string testing. If that was its content before the echo command, from git's perspective there'd be no change (i.e., nothing to report about in git status), since the content of the file is unchanged.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • Odd that he doesn't mention either of those things. Maybe it's an error in the book. – NaNCat Dec 22 '21 at 20:31
  • @NaNCat: Maybe - or perhaps he's illustrating some other weird corner case, such as what happens when you use sparse checkout or some of the special flags with `git update-index` (one of which is meant for sparse checkout). Hard to say without looking at the book, which I don't have. :-) – torek Dec 22 '21 at 23:49
-2

Maybe, your A file is in the .gitignore file.