Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I rollback to a point when I use Revert in Github in Android Studio 3.3.1?

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 enter image description here

Submit 2 enter image description here

Submit 3 enter image description here

Do Revert enter image description here

Files Merged enter image description here

Child of Merge enter image description here

like image 562
HelloCW Avatar asked Mar 02 '19 02:03

HelloCW


1 Answers

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".

like image 90
Romain Valeri Avatar answered Sep 28 '22 16:09

Romain Valeri