Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move a branch backwards in git?

Tags:

git

github

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.

like image 703
user89021 Avatar asked May 27 '10 16:05

user89021


People also ask

How do I go backwards in git?

Use git checkout & the ID (in the same way you would checkout a branch) to go back: $ git checkout <commit-id> .

How do I undo a push to the wrong branch?

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.


1 Answers

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.

like image 194
Bram Schoenmakers Avatar answered Sep 26 '22 22:09

Bram Schoenmakers