I commit and push my code three times, they are Submit 1, Submit 2 and Submit 3.
I hope to rollback my code to the point Submit 2 and push them to remote repository.
So I do Revert operation on the point Submit 2 (See the image Do Revert), a Files Merged with Conflicts dialog box display (See the image Files Merged), and child dialog box of Merge display just like the image Child of Merge.
A: I can't understand why the following code is displayed when I do Revert operation? It seem that the system ready all history commit records to let me merge.
Code
<<<<<<< HEAD
//Submit 3
=======
//Submit 1
>>>>>>> parent of 86821fc... Submit 2
B: And more, I can't get the correct result (rollback my code to the point Submit 2) no matter I choice Accept Yours, Accept Theirs or Merge... command, why?
C: What will the system do if I launch Merge... operation?
Submit 1
Submit 2
Submit 3
Do Revert
Files Merged
Child of Merge
1) Why did this happen?
You've confused revert
and reset
here.
Resetting gets the current branch to a previous point in commit history.
Reverting a specific commit creates a new one, containing the exact reverse of the one you picked. This does not modify the old commit nor gets you back to that past point.
This is also why you got a merge that you didn't expect.
2) How to fix the situation at hand?
Now try resetting to the point before all this mess and it should be all right again.
First of all, if the merge is still ongoing, abort it
git merge --abort
Then check your log
and spot the commit you initially wanted to "revert to" (and I suggest changing your colloquial use of the term here, like you saw it hurts) and reset it :
git reset --hard <commitHash>
(Since you've (I guess?) not pushed yet to the remote, no harm is to be expected. If you in fact have pushed anything during the process, comment and I'll edit my answer to address it.)
3) How to avoid the same problem in the future?
Look at your screenshot named "Do revert", this is where you should have chosen just above "Reset current branch to here" rather than "Revert".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With