Say there are two branches master and branchA.
I work on master, a friend on branchA. Once things are finalized, we merge branchA with master.
After several commits on the merged master, the client wants the work done on branchA removed, but NOT the commits done after the merge.
How can we do it?
You can undo a Git merge using the git reset –merge command. This command changes all files that are different between your current repository and a particular commit. There is no “git undo merge” command but the git reset command works well to undo a merge.
In case you are using the Tower Git client, undoing a merge is really simple: just press CMD+Z afterwards and Tower will undo the merge for you!
Some people keep a merge commit, even for a fast forward, because it keeps a very good record of when a branch was completed. These people prefer "complete and accurate" history over a "clean" history. Some people avoid merge commits, even rebasing their branches, because it keeps the history easier to read.
In a good workflow, the feature branch is deleted once its merged back into master. New branches should be created for each new feature(s) that you work on.
Read through Pro Git - Undoing Merges.
Basically, you git revert the merge commit:
git revert -m 1 hash_of_merge_commit You may end up with some conflicts that you'll have to manually unmerge, just like when merging normally.
Additional links:
Git SCM - Undoing Merges
Git Ready - Rolling back changes with revert
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