I have 2 branches A and B. I made some changes to A and committed them. I then made more changes to A (by mistake). I pushed them to B and committed them.
But now I see changes from A (old) and B (new) being committed. How do I revert this?
If you have pushed commits, that means the remote branch is impacted (not just your local branch)
You will need to cherry-pick the commit from B to A (assuming only one commit was done on B by mistake):
git switch A git cherry-pick B git switch B git reset --hard B~ git push --force That would override the B history, which can be problematic if several collaborators are working from the remote repo.
Another option is to revert B HEAD, to add an additional commit which cancels the content of the last one.
git switch B git revert @ git push No --force needed there.
git rebaseandgit reset