In my experiments I haven't been able to find any functional difference between
git reset --hard
and
git reset --merge
The usage instructions don't give any hint either
--hard reset HEAD, index and working tree
--merge reset HEAD, index and working tree
I regularly use the --hard
option so understand how that works. What's the difference between the --merge
and the --hard
options?
Cheers,
Olly
Perhaps an example would help here, let's use the following sequence:
cd git_repo
touch file_one
git add file_one
git commit -m "commit one" # sha1 of 123abc
echo "one" >> ./file_one
git commit -a -m "commit two" # sha1 of 234bcd
echo "two" >> ./file_one
git add . # populate index with a change
echo "three" >> ./file_one # populate working area with a change
Now if I try
git reset --merge 123abc
I get
error: Entry 'file_one' not uptodate. Cannot merge.
fatal: Could not reset index file to revision '123abc'
the reason being that file_one has changes in both the working area and the index
To remedy this I do
git add .
git reset --merge 123abc
This time it works, however, I get the same result as git reset --hard
. The index is empty, working area is empty, file_one is empty, as it was after first commit.
Can someone come up with the steps that illustrate the difference?
question from:
https://stackoverflow.com/questions/1634115/whats-the-difference-between-git-reset-hard-and-git-reset-merge 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…