Home > Software engineering >  How to remove a removed commit from a feature branch based of develop?
How to remove a removed commit from a feature branch based of develop?

Time:10-18

So we have a develop branch which we base our feature branches from.

Two days ago someone pushed a bad commit to develop, but I based my feature branch of it and already have few commits pushed into it. They removed the unnecessary commit from the develop branch but it still stays in my feature branch commits. It looks something like this:

   bad commit
       \
o---o---X develop
         \
          X---o---o---o feature
           \
        bad commit

What I need to do is to remove the commit that I based my branch of and instead rebase to the commit before it. Do i use git rebase --i or git rebase --onto, I'm not really sure. Thank you in advance!

CodePudding user response:

To remove a single commit with commit ID (hash) X from branch feature:

git rebase X feature --onto X~1

Side Note: what just happened to you is the reason force pushing a shared branch is frowned upon. (Someone force pushed develop to create this issue.) The usual course of action when you have a bad commit on a shared branch is to revert that commit instead of rewriting and force pushing. Had it been reverted, you could have updated your branch the same way you always do, perhaps:

git fetch
# then either:
git rebase origin/develop
# or
git merge origin/develop
  • Related