1

What happens to the state of a file after it has git add -u applied to it?

I had package.json under Changes not staged for commit. I did a git add -u package.json and basically the file disappeared from showing up in git status. What is the status of my package.json? What happened to the changes made to this file earlier?

This is my screen output, before:

enter image description here

and after:

AFTER: git status doesn't show package.json

(I wonder if the git add --refresh did any damage.)

Dear all: I am not asking for the difference between -A and -u. I would like to know what happened to the changes that were earlier made to the file after -u is applied.

Old Geezer
  • 14,854
  • 31
  • 111
  • 198
  • 1
    Have a look at this https://stackoverflow.com/questions/28146646/what-is-the-difference-between-git-add-a-and-git-add-update-for-github?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Aeseir May 03 '18 at 03:12
  • @Aeseir I had studied that earlier, but couldn't understand what it meant by removed from the working tree. – Old Geezer May 03 '18 at 03:14
  • Possible duplicate of [What is the difference between git add -A and git add --update :/ for github?](https://stackoverflow.com/questions/28146646/what-is-the-difference-between-git-add-a-and-git-add-update-for-github) – Obsidian Age May 03 '18 at 03:14
  • @OldGeezer have a look at this page for explanation on working trees, it is the basis of GIT structures. It will help you out as it did me. https://backlog.com/git-tutorial/intro/intro1_4.html – Aeseir May 03 '18 at 03:15
  • @ObsidianAge I had read that earlier. What does "removed from the entire working tree" mean? What happened to the changes in the file? Do you mean same as `checkout` has happened? – Old Geezer May 03 '18 at 03:15

1 Answers1

0

but couldn't understand what it meant by removed from the working tree.

Since git add -u records only modifications to the existing index, that includes deletion as well.
That is what update or remove previously tracked files from the entire working tree.

In your case, the file is not removed, but adding it make it somehow identical to HEAD (the current checked out commit), which means it is not listed as being committed.

That can be possible for instance if you have a:

  • clean content driver (which restore its content to what it was originally in HEAD when checked out)
  • or a core.eol .gitattributes directive (which restore the eol to what it was in HEAD)
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250