What happens to working copies during git reset?
sobes.tech AI
Answer from AI
When executing the git reset command, the state of the working copy and the index (staging area) changes depending on the type of reset:
-
git reset --soft <commit>— moves the HEAD pointer to the specified commit without changing the index and working copy. Changes remain staged. -
git reset --mixed <commit>(default) — moves the HEAD and updates the index, resetting staged changes to the state of the specified commit, but the working copy remains unchanged. That is, changes that were in the index become unstaged, but files on disk do not change. -
git reset --hard <commit>— moves the HEAD, updates the index and working copy, resetting them to the state of the specified commit. All unsaved changes in files will be lost.
Thus, the working copies during git reset can:
- Remain unchanged (soft, mixed)
- Be overwritten and lose unsaved changes (hard)
It is important to understand that git reset affects which changes are considered staged and which are not, and how the file states on disk correspond to the selected commit.