CamelCase
CamelCase

Reputation: 233

GIT: Move changes from one branch to other

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?

Upvotes: 1

Views: 76

Answers (2)

VonC
VonC

Reputation: 1329092

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.

Upvotes: 1

Zenima
Zenima

Reputation: 390

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

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

Regards, Zenima

Upvotes: 0

Related Questions