We have a git history that looks like this. This is already pushed to remote but can I possibly merge the branches at certain commits? Or am I limited to only merging the commit at the very top?
where blue is origin/master and magenta is a feature branch that has been physically copied into the master branch.
You can use the Git reset command to undo a merge. Firstly, you need to check for the commit hash (or id) so you can use it to go back to the previous commit. To check for the hash, run git log or git reflog . git reflog is a better option because things are more readable with it.
Merge upto commitgit checkout src git branch temp commitId # create temporary branch at commitId git switch dst git merge temp # merge temp branch to dst branch git branch -d temp # remove temp branch as we dont need it anymore.
Just run git reset --soft HEAD~10 , where 10 is the number of commits you want to merge. This can be used if you don't have a remote origin set, and you only have two commits.
Assume the commit history as below, and you want to merge feature
branch into commit B
:
...---A---B---C---D master
...---E---F---G---H feature
Then you can execute below commands:
git checkout commitB
git merge feature --allow-unrelated-histories
Assume the merge commit id commit M
as below commit history:
C---D master
/
...---A---B---M
/
...---E---F---G---H feature
Then you can execute the commands:
git rebase --onto commitM commitB master
git push origin master -f
And now the commit history will be:
...---A---B---M---C'---D' master
/
...---E---F---G---H feature
Being in the master branch then git merge "commit-id" This should do it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With