Remove a merge/commit in git


Using git I merged a branch to master and now after a few weeks and many commits I'd like to remove that feature/branch. How do I do it? it doesn't seem trivial

Best Answer

If you want to completely remove it from you history, you could do the following:

  1. git rebase -i <commit to remove>^

  2. This will open your default editor (usually vi) with a list of commits, with the one you want to remove first. Remove it from the list, save, and quit. This should no rebase your branch without the commit you want to remove.

A "safer" approach is to leave the history in tact, so you can show that this feature used to exist, and was purposely removed. Just use git revert <commit to remove>. This will create an additional patch that undoes the commit you want to get rid of. The main advantage is that you can edit the commit message, and explain why this feature is being removed.

Related Question