Remove one merged branch from the master branch

My master branch has the following local branches that have been merged, but I would like to remove local_branch3

from master:

local_branch1
local_branch2
local_branch3
local_branch4

      

after removing local_branch3

from master, I would like it to remain a local branch (only removed from master).

I checked Steve Harman 's blog for the same issue, but this also deletes the local branch permanently.

Edit: to clarify what I meant, as I posted in one of the following comments:

I would like the master branch to revert the changes as a result of the local_branch3 merge, leaving local_branch3 untouched.

The reason is that I would like to keep the branch master

if I tune in local_branch3

.

+3


source to share


2 answers


Perhaps you mean the return local_branch3 from the master?

If so, first check the SHA1 value of the commit that local_branch3 merges. AND



git checkout master
git revert -m 1 <<SHA1 value>>

      

Then no local_branch3 codes in the main branch. And locah_branch3 will remain.

+3


source


If I read the question correctly, shirakia's answer (revert merge commit changes) is correct, it works as advertised and the OP should use it.

But it's worth noting what happens if further work on local3 makes all of this valid, and you naturally want to reapply the original work along with these later fixes.

Local 3 commits as this merge is now part of the merge commit history. Since the underlying content for any subsequent merges from local3 resides in the new merge base, this entire story is effectively marked as (indeed, it has been) applied correctly: any subsequent merge only sees the changes made since then. The checkout did not undo this part (in fact, it was the purpose of the checkout, so as not to remove this commit).



Here's a well-known discussion of how to reapply changes if further development to local3 causes things to merge again (you reverse, you reverse the changes) .

Another, arguably easier way of setting it, is the correct way to undo any commit you don't want to remove from your history is to revert it. This includes any subsequent decision to cancel the reversion.

+2


source







All Articles