I executed merge command on wrong branch as undo

Asked

Viewed 21,812 times

3

In my project contain 2 branch a work and a master, today after a long time I went up the version of the project, but at the time of running the merge I ended up doing it in the wrong branch, only realized after I had performed the push when I opened the project was with the old files, there is how to undo this my error?

Below is the command sequence I used: inserir a descrição da imagem aqui

Please help me, I’m really desperate for this mistake of mine :/

  • calm, download a previous version to your merge and commit it again.

  • @Rboschini you could help me with the sequence of commands, because I’m not very familiar with using git. (remembering that the version that is on my server is well outdated)

  • 1

    Have you tested git merge --abort?

2 answers

7

You can turn this back using the command:

git reset --hard commit_sha

There is another way

git reset --hard HEAD~6

You will return 6 commits.

See if this settles it for you.

  • So partner I used the git reset --hard HEAD~1 however it went back to an older version yet, it was a while ago that I did not upload system updates.

  • Do you have any other suggestions? @Rboschini

  • takes the commit hash that is correct and does so git reset --hard "HASH_COMMIT_SEU"

  • i tried to use in this my last commit that is in print but gave this error PS F: Documents Projects Administration Administration> git reset --hard "Student Registration" fatal: ambiguous argument 'Student Registration': Unknown Revision or path not in the Working Tree. Use '-' to Separate paths from revisions, like this: 'git <command> [<Revision>...] -- [<file>...]'

  • is the hash and not the name "Student Registration" that you have to take.

  • Forgive my ignorance but I’m pretty layy when it comes to version control, like I do to see a commit hash?

  • git log, the hash is something like this commit ca82a6dff817ec66f44342007202690a93763949.

  • git rev-list origin

  • We can continue this conversation in chat?

Show 5 more comments

3

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

git log

Take the hash of the last secure version. Example:

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

Now do the reset:

git reset --hard 85f8oouy7c05faxiskbfcd17fcc7cfppoocca02e

Remembering that the hash used in the above command is an example, you need to replace by your.

For more information, see documentation.


There is also the command git reset --hard HEAD~1, being the number 1 the input in the commits list. You can see the commits list using the git log.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.