Say there are three branches master, branch-A and branch-B.
I work on branch-A, a friend on branch-B. Once things are finalized, we merge branch-A and branch-B with the master.
After several commits on the merged master, the client wants the work done on branch-B removed, but NOT the commits done By branch-A after the merge.
Checkout to the master branch
git checkout origin master
View the commit history
$ git log commit ca82a6dff817ec66f44342007202690a93763949 Author: Sahil <email@example.com> Date: Mon Mar 17 21:52:11 2021 -0700 Commit by Branch-A commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 Author: Sahil <firstname.lastname@example.org> Date: Sat Mar 15 16:40:33 2021 -0700 Commit by Brach-B commit a11bef06a3f659402fe7563abf99ad00de2209e6 Author: Sahil <email@example.com> Date: Sat Mar 15 10:31:28 2021 -0700 Initial commit
The commit we need to unmerge is
git revert <hashOfMergeCommit>
in our case
git revert 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
If you need to reference numerous commits in the revert command, eg:
git revert <hashOfMergeCommit1> <hashOfMergeCommit2> <hashOfMergeCommit3>...
You've segregated the code you need, but don't stop there. Continue exploring and see what you can commit.