git - How can I remove merged branch which is already push to origin -
for example, have 1 defect issue ,which developer create new branch, , fixed in branch name "fix_#1_backyard_data_displayed". then, merge branch "beta" test it. after while, tester merged branchs "fix_2" , "fix_3" "fix_20" "beta" , test it. after that, found first merged "fix_#1_backyard_data_displayed" branch buggy , make our application unstable.
now, how can remove merged branch push origin without disturbing "fix_2" , "fix_3" "fix_20"?
short answer
in beta
branch:
- find sha1 of commit corresponds merge.
- run
git revert <sha1> -m 1
there caveat: git still think feature branch merged beta
branch, , merge branch again you'll need revert (again) commit introduced git revert
before merging.
longer version
the command in git undo commit revert
. merge commits, need specify "mainline" branch -m
switch. in case, should 1:
usually cannot revert merge because not know side of merge should considered mainline. option specifies parent number (starting 1) of mainline , allows revert reverse change relative specified parent.
reverting merge commit declares never want tree changes brought in merge. result, later merges bring in tree changes introduced commits not ancestors of reverted merge. may or may not want.
see revert-a-faulty-merge how-to[1] more details.
(source: git revert
)
the following sh
script demonstrates this. first revert
command reverts commit merged fix1
branch, in case second-to-last commit, i.e., head^
. after reverting, before merging fix1
branch again, revert needs undone revert
command:
#!/bin/sh git init test cd test touch git add git commit -m git checkout -b fix1 touch b git add b git commit -m b git checkout -b fix2 master touch c git add c git commit -m c git checkout master git merge --no-ff --no-edit fix1 git merge --no-ff --no-edit fix2 git revert --no-edit head^ -m 1 git checkout fix1 echo "fix b" > b git add b git commit -m bb git checkout master # git merge fix1 # give error! # revert changes introduced revert before merging git revert --no-edit head git merge --no-ff --no-edit fix1
Comments
Post a Comment