I am new to git. I have mistakenly done a commit in a wrong branch B. It should be in branch A.
Is there any way I can move the commit from B to A.
Please suggest. Any help is highly appreciated.
I am new to git. I have mistakenly done a commit in a wrong branch B. It should be in branch A.
Is there any way I can move the commit from B to A.
Please suggest. Any help is highly appreciated.
1.- The first thing will be list the commits with :
git log --oneline
2.- You must find the commit (from branch B) and select the ID of the commit to change
3.- Change the branch
git checkout A
4.- And from there you must execute the following commit
git cherry-pick c8dc73f
Where c8dc73f
is the number or ID of the commit that I selected in the second step.
You can use cherry-pick:
Let say you have two branch A and B and mistakenly done a commit in a wrong branch B
Take commit it from the branch B using
git log
Got to branch A using
git checkout <branch-name>
git checkout A
Now do cherry-pick using:
git cherry-pick <commit-id>
If you get conflicts resolve it and do git add
and then commit.If you want to abort cherry-pick use
git cherry-pick --abort