0

I have a situation, where some pull-request is released on dev branch by mistake. I want now only that pull-request (merge commit) to remove from origin/dev Here is the picture: enter image description here

So, commit with a number 89e231f1 Branch name is called: dev

I tired to get one commit earl;ier and to create separate branch, then to merge all other commits to that branch, but somehow it takes also a commit from this merge 89e231f1

Stefan0309
  • 1,602
  • 5
  • 23
  • 61
  • Does this answer your question? [How to permanently remove few commits from remote branch](https://stackoverflow.com/questions/3293531/how-to-permanently-remove-few-commits-from-remote-branch) – Matt Jun 17 '21 at 11:39

1 Answers1

0

You can use interactive rebase and remove this commit. Trigger rebase by doing:

git rebase -i 89e231f1^

Delete the merge commit by removing lines corresponding to it.

If you don't want to force push, you can revert the commit instead:

git revert -m 1 89e231f1
git push -u origin dev

This will add an another commit reverting all the changes.

deepakchethan
  • 5,240
  • 1
  • 23
  • 33
  • thanks! then should I have all commits that have been added after `89e231f1` ? – Stefan0309 Jun 16 '21 at 16:18
  • Yes, retain all commits outside of that merge commit – deepakchethan Jun 16 '21 at 16:21
  • just a question, it opens git-rebase-todo https://i.imgur.com/tiebxwn.png Im not really sure what to do, I need all of these commits. – Stefan0309 Jun 16 '21 at 16:24
  • when I close the file, I have 12 changes to pull and 7 changes (correct changes) to push. So if I pull, I will again get those changes that I dont want. How to avoid pull command? (I cant push before pull) https://i.imgur.com/Fzqkk40.png Obviously, I'm doing it locally, and for some reason it tells me that are 12 changes to be pulled. – Stefan0309 Jun 16 '21 at 16:30
  • Whenever you change the commit history, you can't do a normal push. You need to do a force push instead. If you don't want that you can revert the commit in the dev branch instead (updated the answer) – deepakchethan Jun 16 '21 at 16:33
  • Pushing a rebased dev branch will put it the expected state, but has some bad impacts on anyone that has working changes on the existing commit history? – Matt Jun 16 '21 at 19:37