Git merge on a branch that was previously merged

I ran into a situation where a branch was merged into the master branch at some point, and the changes from the branch are no longer in the master. This may have been due to incorrect matching of merge conflicts, but at the moment I'm not sure.

Changes to this previously merged branch are needed in the main branch, but now if I try to merge the branch into master Git, the message "Already updated" is returned. since this branch was previously merged. What's the best way to force a re-merge of this branch with master?

+3


source to share


3 answers


I think it will do ya

mkdir alreadyapplied.patches
git format-patch -o alreadyapplied.patches master..alreadyapplied

      



and then

git checkout -b wip master
git am alreadapplied.patches
# (do whatever necessary to deal with conflicts here)
# (rebase wip here if the conflict resolution has taken
# long enough that the wip branch has gotten behind master)
git checkout -B master wip
git branch -d wip    

      

+2


source


Depending on how many commits have been committed, you can simply cherry-pick each one in turn.



0


source


Another method would be to get the commit id of the branch before the merge and reset your HEAD to point to it, you could do any fixes needed to create and re-merge that branch into master

i.e.

git reset (--hard/--soft/--mixed) _commit_ # where the _commit_ is the commit ID of the old branch
<work and make changes>
git commit -m "Made changes to commit before merging into master"
git checkout master 
git merge (--no-ff) otherBranch

      

Resetting your HEAD will allow you to get back to how things are. Note that this can be dangerous using the --hard option as it is destructive and will make your index and workspace look exactly as it did during this commit (you will lose your other work).

0


source







All Articles