0

Lets suppose we have a branch A with the labeled commits C1 C2 C3 and C4. My need is to remove C2 and keep all the changes made by any other commit.

In a trivial way lets think to a single code file where in a commit C1 I have introduced the functionOne, in C2 the functionTwo and so on ... till C4.

My idea was to use cherry picking with C1 C3 and C4 but seems not working or not to be the best solution.

Does someone have an idea of how I could reach what I would like do? What could be the best solution to avoid/remove a commit from a branch keeping the ahead and behind commits changes?

Anthony Geoghegan
  • 11,533
  • 5
  • 49
  • 56
Simone Salvo
  • 343
  • 1
  • 2
  • 11
  • `git revert` command - https://git-scm.com/docs/git-revert. `git revert` creates another commit that reverts changes. – dNitro Jul 05 '16 at 11:04

1 Answers1

2

You can use an interactive rebase : git rebase -i <origin-commit>.

In the list of commits, you just have to remove the line containing the one you want to remove and it will be removed from the rebased branch.

Note that it actually creates new commits (as often with git) and you'll have to do a forced push if the branch is already shared.

Matt
  • 3,422
  • 1
  • 23
  • 28