Remove an unwanted merge commit and rebase instead with Git -
Remove an unwanted merge commit and rebase instead with Git -
i have feature branch off develop. started using practice of rebasing feature branch develop instead of merging benefits of linear commit history appropriate project had few upstream , downstream repositories.
i'm in situation merged develop feature branch , did more commits pushed remote. able point remove merge commit , cherry pick subsequent commits on branch. knowledge other people working on branch have delete local ones , pull downwards revised one. work in little team , manageable.
is best method interactive rebase selecting commit bar merge commit?
so git rebase -i commit-sha-before-merge
i know result in broken build commits occurred after merge relied on code in merge. resolve rebasing feature branch develop.
as torek points out in comments, there more 1 way in git. say, example, have commit graph this:
develop *-------* \ \ feature *---*---*---*---* x m^ m y^ y x first commit on feature branch, m merge commit develop, , y lastly commit on feature branch.
solution 1: rebasesthis relies on fact rebasing branch b onto branch equivalent merging branch b. in case, we'll utilize 2 rebases, 1 rebase feature branch commits before merge commit, , other rebase commits after merge:
class="lang-bash prettyprint-override"># create temporary branch @ commit right before merge commit m git checkout -b temp m^ # rebase onto develop branch git rebase develop # rebase remaining commits after m onto temp branch git rebase --onto temp m feature this produce next commit graph
x m^ y^ y *---*---*---*---*---* ^ ^ ^ develop temp feature so can delete temp branch git branch --delete temp.
here how can accomplish same result using cherry-picks, torek suggested:
class="lang-bash prettyprint-override"># temporarily hard reset feature develop branch git checkout feature git reset --hard develop # cherry-pick commits between x m^. # start of cherry-pick range exclusive, i.e. doesn't include # starting point x^. git cherry-pick x^..m^ # cherry-pick commits between m y git cherry-pick m..y documentation git-rebase(1) manual page git-cherry-pick(1) manual page git git-merge rebase
Comments
Post a Comment