2

I have accidentally merged pull request into master branch from my feature branch, which i should not have. I am using gogs . I cannot use revert button as there is not any functionality available. How can i revert back the master to the position before my pull request so that master branch will be clean again.

Also master branch is protected and commits should be pushed only through pull request. So git push -f is not working for me.

I have read other questions but they were about a specific incidents. I am not sure how can i achieve this.

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
programmer
  • 115
  • 1
  • 2
  • 12

2 Answers2

4

If you have not added any other commit after the wrong merge I suggest you tu rely on the command line as follow:

git checkout master
git pull

git log --oneline --graph --decorate # Write down the hash of the last good commit

git reset --hard {{last-good-commit-hash}}

# Review your commits, and if it all right...

git push --force # Rewrite branch history, be carefully!!!
Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
0

I have had the same problem before. Going to the commit you want to revert to and hitting the revert button in Gogs is what you are supposed to do.

If that doesn't work: Every commit with Git has a commit hash connected to it. This should be listed in the history of commits on the Gogs page. There should be a button to easily copy any hash, so you don't have to type it out. If you can use a command line console, you can use "git revert [code]" where code is the commit hash linked to the earlier commit. After that, "git push".

  • I think there is no revert button in gogs. – programmer Jun 15 '21 at 13:35
  • There is not. It was planned but not added yet. Command line is your only option. Get a good older commit, and `git revert` or `git reset --hard` with the commit hash. Revert will create a new commit, while reset just deletes any commits in between the old and current. The `git push --force`. – leoleosuper Jun 15 '21 at 13:49
  • I edited my question. I try but the master branch is protected so i cannot push directly to master branch. – programmer Jun 15 '21 at 13:57
  • You should unprotect it, push, then protected again. – Antonio Petricca Jun 15 '21 at 13:58