Having read through Mark Dominus's article and Scott Chanon's article I assumed that git reset abcd --soft
would not affect the index, however, the following shows that it does.
c1.txt
, c2.txt
, c3.txt
in the repo, c4.txt
in the index. All in the working directory:
$ git log --oneline --decorate
b91d91b (HEAD, master) C3
231a5df C2
7e7b2d7 C1
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: c4.txt
$ ls
c1.txt c2.txt c3.txt c4.txt
$ git reset 231a --soft
$ git log --oneline --decorate
231a5df (HEAD, master) C2
7e7b2d7 C1
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: c3.txt
new file: c4.txt
$ ls
c1.txt c2.txt c3.txt c4.txt
From Scott's article, he says:
The first thing reset will do is move what HEAD points to.... If you add the flag --soft, this is the only thing it will do. With --soft, reset will simply stop there.
So, I thought that the index (which I hope I've understood to be what's shown in the git status
outputs above) would not change, that being, it would still contain c4.txt
. The output above shows that it actually contains c3.txt
and c4.txt
.
It appears that c3.txt
has been moved into the index alongside c4.txt
.
The fundamental misunderstanding seems to be about what the index is. The index isn't a set of differences, it's a set of files. What git status
shows is not the index, but the difference between the last commit and the index.
Before your git reset --soft
, the index contained files c1.txt
, c2.txt
, c3.txt
and c4.txt
. So after your git reset --soft
, the index still contains those same files. git status
will report this differently, but that isn't because the index changed, that's because the commit changed.