I have our commit log from my repo. You can see the "Merge branch...into..." commits. After these commits, the branch was merged.
I need to delete the merge commits, but not discard the changes. Default rebasing doesn't show merge commits.
If you want to apply the changes of the commits without including the merge commit (which as Roland Smith pointed out is generally considered bad practice) you can use git rebase
with the following workflow:
git checkout master
git reset --hard <hash of prior commit>
. Make sure there are no uncommitted changes on the branch you were working on or this command will wipe them out.dev
): git checkout dev
.dev
onto master. This will put the HEAD
commit of dev to be upstream to the most recent commit that master points to: git rebase master
(see the docs for more information).git checkout master
) and merge the new branch git merge dev
. This will pull the changes onto master without adding a merge commit.master
branch looks okay, you'll have to update the branch on any remote repositories too. Because you're undoing prior history, when you push the branch you'll have to use the --force
(or -f
) flag for the remote repo to accept the changes i.e.: git push origin master --force
.That's all there is to it. After you do this, the commits on dev
that were branched off of master should now be upstream to the pre-merge commit above.
NOTE: Running rebase will permanently update the commit history for the changed branches. For safety, I recommend taking 1 of 2 methods:
git reset --hard <original_commit_hash>
to put the branch back on the original commit.Make backup copies of both branches before you rebase that are pointing at the original commit:
git checkout -b master_bk git checkout -b dev_bk
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