Git: Adding files and resetting

CommandNew filesChanged filesDeleted files

Alice creates a new repository.

Alice/> git init --template=""
Initialized empty Git repository in /home/rene/github/github/git-internals/repos/add-and-reset/Alice/.git/
snap no: 1
.git/HEAD
.git/config

She creates a file whose content is simply: foo

Alice/> echo foo > a.file
snap no: 2

Then, she adds the file to the index.

Alice/> git add a.file

This creates a blob object.

snap no: 3

She adds another line (bar) to the file:

Alice/> echo bar >> a.file
snap no: 4

Alice commits the newly added file

Alice/> git commit -m "+ a.file"
[master (root-commit) 74f3684] + a.file
 1 file changed, 1 insertion(+)
 create mode 100644 a.file

Note: this commits the content of the file that was added (blob object 257cc56…), not the content of the file as it is in the working directory. Note also that the content of the working directory would be commited if Alice executed the commit with a dot: git commit . -m …

snap no: 5
.git/COMMIT_EDITMSG
.git/logs/HEAD
.git/logs/refs/heads/master
.git/objects/74/f368428d95727df902bbed18193f8d015157de [commit]
.git/objects/8c/2d63ef60a3c32bd1dd3b88ebdae3e25fa66119 [tree]
.git/refs/heads/master

Because the commit didn't commit the file in the working directory, the file's status is modified:

Alice/> git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   a.file

no changes added to commit (use "git add" and/or "git commit -a")
snap no: 6

Showing the content of the file as stored in the repository:

Alice/> git show HEAD:a.file
foo
snap no: 7

Alice resets the working tree so that it matches HEAD:

Alice/> git reset --hard
HEAD is now at 74f3684 + a.file

Note: it creates .git/ORIG_HEAD

snap no: 8
.git/logs/HEAD
a.file

Thus, the content of a.file is foo again:

Alice/> cat a.file
foo
snap no: 9