1

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?

1
  • Check out git rebase and git reset Commented Feb 19, 2020 at 1:35

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0
git checkout <branchname> git reset --hard <commitid> 

This restores everything to it's original state. If you meant something else, please elaborate.

Regards, Zenima

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.