I agree that the documentation is not very clear. From testing, I found three differences related to what happens to files that:
- made changes
- lack of unspecified changes
In short:
reset --merge always discards the index (incremental changes); interrupted if uninstalled and phased changes are present in any filereset --keep stores, but non-stationary, an index; interrupted if the reset target touches the same file
Test scenario:
echo First > file.txt git add file.txt git commit -m 'first' git tag v1 echo Second >> file.txt git commit -am 'second' git tag v2 echo New > newfile.txt git add newfile.txt git commit -m 'third' git tag v3 echo 'More stuff' >> file.txt git add file.txt
Now we have three commits, and 'file.txt' changes between v1 and v2, but does not change between commits v2 and v3.
No change between index and new HEAD
In this situation:
git reset --merge v2 cancels these changes.git reset --keep v2 stores them, but disables them.
Changes between the index and the new HEAD
If we try reset to v1 instead:
Changes between the index and the new HEAD, as well as unspecified changes
git echo "Even more things" >> file.txt
Now both fail, but with slightly different error messages:
git reset --merge v1
error: Entry 'file.txt' not uptodate. Cannot merge. fatal: Could not reset index file to revision 'v1'.
git reset --keep v1
error: Entry 'file.txt' would be overwritten by merge. Cannot merge. fatal: Could not reset index file to revision 'v1'.
Phased and uninstalled changes to an unrelated file
echo Unrelated > unrelated.txt git add unrelated.txt echo Stuff >> unrelated.txt
Now this is somewhat strange:
No incremental changes but unspecified changes
For completeness, they both behave the same: reset succeeds, and the file remains uninstalled.
source share