0

In an attempt to rebase my development branch with master, I ended up pushing commits that shouldn't have. Then in an awful attempt to revert the push, I performed a hard reset, and force pushed again. However, when creating a new pull request, I notice all the commits I didn't want still showing.

Here's what I did:

$ git checkout my_dev_branch
$ git rebase origin/master
$ resolved all conflicts
$ git add --all
$ git rebase --continue
$ git push origin my_dev_branch

I went to create a new pull request and saw a bunch of commits I didn't want. So, I did:

$ git revert -m 1 commit_hash <- did nothing
$ git reset --hard commit_hash_before_merge <- this worked
$ git push origin my_dev_branch

I went back to make a pull request, and still see all the commits I didn't want. Is there any way to remove those unwanted commits, or is it possible to get local my_dev_branch sync with a different local branch that I know don't have the unwanted commits?

alyus
  • 987
  • 4
  • 20
  • 39
  • `git reset --hard other_local_branch` – Cory Kramer May 08 '20 at 20:25
  • @corykramer after the reset, I would `git push origin my_dev_branch`? – alyus May 08 '20 at 20:29
  • Correct me if I am wrong but having read the description I assume you already have the my_dev_branch rebased on top of master and have the unwanted commits in your feature branch. If this is correct then how about rebasing interactively again and dropping the unwanted commits? https://til.hashrocket.com/posts/iw7diudcph-dropping-commits-with-git-rebase – dawid gdanski May 08 '20 at 20:32
  • Sorry but how is this different from your earlier https://stackoverflow.com/questions/61670197/undo-git-push-that-hasnt-merged ? – matt May 08 '20 at 20:39
  • Also, what does "see all the commits I don't want" even mean? You cannot — well, you should not — attempt to rewrite the history that's on the server. You pushed the commits, they are on the server. And since commits are never destroyed unless the whole branch is deleted, on the server they will stay. Next case. – matt May 08 '20 at 20:41
  • @matt I guess the difference from my earlier question was that I `git push` and it didn't show any commits when viewing on Github. This time when I `git push origin my_dev_branch`, there were a lot of commits. Git is pretty confusing, and I'm asking questions as I go. Thanks for your input. – alyus May 08 '20 at 21:07
  • @dawidgdanski would I do `git rebase -i master` on my `my_dev_branch`? – alyus May 08 '20 at 21:09
  • 1
    Correct. 1. `git checkout my_dev_branch` 2. `git rebase -i master` 3. For each unwanted commit starting with `pick` replace the `pick` word with `drop` or 'd' letter 4. save the changes: type `:wq` The interactive session will be opened in vi text editor by default so make sure you know how to modify text using vi. Let me know if it helps. – dawid gdanski May 08 '20 at 21:17
  • @dawidgdanski thank you so much for the explanation. much appreciated. – alyus May 08 '20 at 21:25
  • Well, not to beat a dead horse, but you asked the wrong question on the other question, in my opinion. That's called an x-y question. The premise was: "While checking to perform a pull request, I noticed there were commits I didn't recognize and want to undo the push". But you had just rebased. That is what a rebase _is_: it makes all new commits. There was no reason to undo the push. So you went down a terrible rabbit hole, all because you failed to state the question fairly. The question should have been whether anything bad had happened. It hadn't. – matt May 08 '20 at 22:07
  • @matt I understood what you were saying from your first comment. When you ref my first question, I realized my written skills suck. Especially when trying to describe a problem. Moving forward I'll make the effort to ensure I'm asking the right question by being more clear and concise. Again, thank you! P.S. Ain't nothing wrong with beating a dead horse. – alyus May 08 '20 at 22:40

0 Answers0