Git: Unable to remove a "revert' commit

587 views Asked by At

We are using git work flow with a develop branch for integration and feature branches for individual features.

  1. Created a feature branch via:

    git fetch
    git checkout -b new-branch origin/develop
    

(develop is our working integration branch)

  1. worked on new branch and when ready created pull request back into develop and created a pull request on github and merged.

    there were no merge conflicts and now our feature branch lives on develop

  2. Had to do another pull request for tweaks to code

  3. at the end of the sprint we reverted the new-branch out of develop via github - using the revert button on the pull request page.

  4. when we tried to revert the second pull request github was unable to do it, so we reverted this commit manually via:

    git checkout develop
    git fetch
    git merge --ff-only origin/develop
    git revert -m 1 commit ##the commit that was the pull request
    git push
    
  5. when we did the above step we (unexpectedly) got merge conflicts; which we solved; and now YAY! new-branch is no longer on develop, our commits were reverted.

  6. Now that we have released, we want to continue to work on new-branch and remove the revert which as we understand it there are two different ways to do so.

    1. revert the commit that removed the pull request
    2. find out the commit prior to where we forked the new-branch and run

      git rebase -i --no-ff commit
      
  7. nether of these are allowing us to re-introduce new-branch into our develop branch.

1

There are 1 answers

3
Ben Glasser On

if you have all the code you want on your release branch you should either:

  • branch of of that if it has all the changes you need and work on that branch

  • merge it to develop and then branch off develop if there is code on develop you want to keep

then you can just delete the old branch

I you are wanting to remove the reverted commit, don't. Generally, removing or changing commit history in git is a considered a bad idea https://sethrobertson.github.io/GitBestPractices/#pubonce

finally Git Choose Your Own Adventure is an amazing resource for fixing git follies...