For educational purposes, I am looking for a method to visually demonstrate how a git reset
modifies HEAD
and the Staging index. In the case of --mixed
and maybe --hard
I would like to get a before and after view of the Staging Index, to show how it has been modified. The case of --soft
should demonstrate that it remains the same.
I had been using git status
to demonstrate the git reset
processes and found it confusing to say "the staging index is unchanged" when git status
shows pending updates in the "Changes to be committed" section. I came to learn that git status
is not representative of the state of the Staging Index, but the diff between Head and the index.
I have been using the following example to demonstrate so far:
git init .
touch reset_lifecycle_file
git add reset_lifecycle_file
git commit -am"initial commit"
echo 'hello git reset' >> reset_lifecycle_file
git commit -am"update content of reset_lifecycle_file"
git log
commit be4aaa98d6976531fdd28aeff52e233087066049
Author: kevzettler <kevzettler@gmail.com>
Date: Thu Nov 30 15:31:16 2017 -0800
update content of reset_lifecycle_file
commit 5e2d74b369f57929673d873302eb7ebd752c2a95
Author: kevzettler <kevzettler@gmail.com>
Date: Thu Nov 30 15:20:43 2017 -0800
initial commit
git status
On branch master
nothing to commit, working tree clean
At this point in the repos life if I execute a git reset to the first commit 5e2d74b369f57929673d873302eb7ebd752c2a95
git reset --soft 5e2d74b369f57929673d873302eb7ebd752c2a95
git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: reset_lifecycle_file
Here is where the confusion has stemmed from. I had been assuming the "Changes to be committed" output was reflective of the state of the index, and was then assuming the --soft
had been modifying the Index which all Git documentation states does not happen.
I have recently discovered the git show
and git ls-files
commands. I am wondering if these can be better used to visualize the process here.
git show --full-index commit 5e2d74b369f57929673d873302eb7ebd752c2a95
Author: kevzettler <kevzettler@gmail.com> Date: Thu Nov 30 15:20:43
2017 -0800
initial commit
diff --git a/reset_lifecycle_file b/reset_lifecycle_file new file mode
100644 index
0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
git show --full-index
appears to append some index Object SHA to the end of the output. Can I use that to indicate reset changes to the index?
git ls-files -s
100644 d7d77c1b04b5edd5acfc85de0b592449e5303770 0 reset_lifecycle_file
git lis-files-s
has another Object SHA Can I use that to indicate changes to the index?
At this point in the example it differs from the SHA in the output from git show
does that indicate the HEAD is at a new index SHA?