DJ180
DJ180

Reputation: 19874

Git: Remove changes from Git commit that is in middle of branch

I have 3 commits: a, b & c

I need to remove the changes introduced by b, such that just a & c are left

What I've done so far is create a new branch from a, and then cherry picked in c

However, when I merged with the master it merged back in b

How do I avoid this merge?

Upvotes: 1

Views: 3476

Answers (1)

manojlds
manojlds

Reputation: 301587

If you want to remove B in A --> B --> C, do :

git rebase -i HEAD~ A

You will get the interactive rebase text. Just remove the line representing B and continue the rebase and B will be removed.

Note that this will change your history, and should generally be done only when you have not pushed these commits to remote.

If pushed, do git revert B to make a new commit B' which removes the changes done by.

Upvotes: 7

Related Questions