Git 切换分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4826779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:57:34  来源:igfitidea点击:

Git Switching branch

gitbranch

提问by mathk

There is somthing I don't get yet with git. It is branch. So let say that I have a local repository Awhich I clone from a remote one B. So now Ahave the master branch checked out.

我还没有用 git 搞定一些东西。是分行。所以假设我有一个本地存储库A,我从远程存储库克隆B。所以现在A检查主分支。

So when I push from Ait goes to Bmaster.

所以当我从A它推动去B掌握。

Bis just a clone on github, a clone of C.

B只是 github 上的一个克隆,是C.

From time to time in other to get in sync I pull from Cmaster branch.

不时在其他同步我从C主分支拉。

But now Cmaster branch is quite broken for the time being. Since from AI had pull from Cmy local Ais also bugy.

但是现在Cmaster 分支暂时很崩溃。因为从A我拉从C我的本地A也是错误的。

So I would like from Ato pull the Cstable branch. How do you guys usually do in this situation?

所以我想从AC稳定分支。在这种情况下,你们通常是怎么做的?

Do you create a new branch on Aand pull from C. But since Ahave the Cmaster change I need to revert it first...

您是否创建了一个新分支A并从C. 但既然AC主人改变,我需要先恢复它......

回答by poke

git fetch C
git checkout C/stable-branch
git checkout -b myCopy

Then myCopyis a local (copied) branch of C's stable one.

然后myCopy是 C 的稳定分支的本地(复制)分支。

回答by urschrei

In two lines:
git fetch C
git checkout -b myCopy -t C/stable-branch

在两行中:
git fetch C
git checkout -b myCopy -t C/stable-branch

myCopyis now a local branch of C/stable-branch, and is tracking it, so you can do git pushand git pullwithout a refspec.

myCopy现在是一个地方分支C /稳定分支,并跟踪它,这样你就可以做git pushgit pull没有的Refspec。