I ran merge command in wrong branch how to undo

In my project contains 2 branch a work and a master, today after a long time I went to upload the version of the project, but at the time of running the merge i ended up doing in the wrong branch, only realized after that I had performed the push when I opened the project was with the old files, there is

Follows below command sequence I used: insert the description of the image here

Please help me, I'm pretty desperate with this mistake of mine: /

Author: Vinicius VAz, 2015-12-07

2 answers

You can return this using the command:

git reset --hard commit_sha

There is another form

git reset --hard HEAD~6

You will return 6 commits.

See if this solves for you.

 6
Author: RBoschini, 2015-12-07 13:04:55

First of all, check the last commit you made with the secure version of your branch. Make sure you are in the right branch and use the command:

git log

Take the hash of the latest secure version. Example:

commit 85f8oouy7c05faxiskbfcd17fcc7cfppoocca02e
Author: Guilherme Iazzetta <[email protected]>
Date:   Wed Feb 5 14:05:12 2020 -0300

Now reset:

git reset --hard 85f8oouy7c05faxiskbfcd17fcc7cfppoocca02e

Remembering that the hash used in the above command is an example, you need replace with yours.

For more information, see the documentation .


There is also the command git reset --hard HEAD~1, being the number 1 the index in the commit list. You can view the list of commits using git log.

 2
Author: Guilherme IA, 2020-02-05 18:08:44