In my master branch, there're following local branches that have been merged, but I would like to remove the local_branch3
from master:
local_branch1
local_branch2
local_branch3
local_branch4
after removing the local_branch3
from master, I would like it to remain a local branch (only deleted from master).
I've check Steve Harman's blog on this similar issue, but that seems also deleting the local branch for ever.
Edit: to clarify what I meant, as I posted in one of the below comments:
I would like the master branch to undo the changes resulting from local_branch3 merging, while leaving local_branch3 untouched.
The reason being that I would like to keep the master
branch deliverable while I tweak on local_branch3
.
Maybe you mean reverting local_branch3 from master?
If so, first check SHA1 value of the commit which merges local_branch3.
And
git checkout master
git revert -m 1 <<SHA1 value>>
Then no local_branch3 codes in master branch. And locah_branch3 will remain.
If I'm reading the question right, shirakia's answer (revert the merge commit's changes) is the right one, it works as advertised and OP should use it.
But it's worth pointing out what happens if further work on local3 makes the whole of it valid, and you naturally want to reapply the original work along with those later corrections.
The local3 commits as of that merge are now part of the merge commit's history. Because the base content for any further merges from local3 is at the new merge base, all of that history is effectively marked as (really, it has been) already correctly applied: any later merge sees only changes made since then. The revert didn't undo that part (in fact, that was the whole point of the revert, to not remove that commit).
Here's a well-known discussion of how to reapply the changes if further development on local3 makes the whole thing mergeable again (you revert the revert, you put the changes back yourself).
Another perhaps simpler way of putting it is, the right way to undo any commit you don't want to remove from your history is to revert it. That includes any later decision to undo the reversion.