Question

As a newcomer to git, I'm investigating the various resets I can do.

I was under the impression that git reset --soft does not alter the index or the working directory, it only changes the head of the repo.

So I have performed a soft reset to a commit in the past.

Since neither my index or working directory are supposed to change, I would now expect a git status to say that I have untracked changes, because the files in my working directory would be more up-to-date than those in the repo which I've just gone back to.

However it tells me that my modified files are in the index? How can this be? I haven't committed them. Does a soft reset alter the index after all?

Was it helpful?

Solution

git reset --soft doesn't change the index, so unless the commit that you are moving to has the same content as what was actually in your index before the reset, your index will be different to the new HEAD commit. Difference between HEAD and your index are staged changes, by definition.

As your index hasn't changed, if you didn't have any unstaged changes you still will have no unstaged changes. There difference between your working tree and the index will be the same as before; neither has changed.

(It sounds like what you are expected is actually what a standard reset - or reset --mixed does: move your HEAD and then update your index to match the new HEAD.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top