The title is not very clear. What I actually need to do often is the following:
Let's say I have a development going on with several commits c1,c2,... and 3 branches A,B,C
c1--c2--c3--(B)--c4--(A,C)
Branch A and C are at the same commit.
Now I want branch A to go back where B is, so that it looks like this:
c1--c2--c3--(A,B)--c4--(C)
Important is that this has to happen locally and on GitHub.
Use git checkout & the ID (in the same way you would checkout a branch) to go back: $ git checkout <commit-id> .
switch to that branch, check the git log and git revert those commits individually. Once you have done that, switch back to the desired branch and there you can then use git cherry-pick to pick specific commits from the git refs and merge it into the right branch.
Use the reset subcommand:
git checkout A git reset --hard B git push --force github
As a sidenote, you should be careful when using git reset
while a branch has been pushed elsewhere already. This may cause trouble to those who have already checked out your changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With