Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
814 views
in Technique[技术] by (71.8m points)

github - How to move a branch backwards in git?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...