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
Git Switching branch
提问by mathk
There is somthing I don't get yet with git. It is branch.
So let say that I have a local repository A
which I clone from a remote one B
.
So now A
have the master branch checked out.
我还没有用 git 搞定一些东西。是分行。所以假设我有一个本地存储库A
,我从远程存储库克隆B
。所以现在A
检查主分支。
So when I push from A
it goes to B
master.
所以当我从A
它推动去B
掌握。
B
is 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 C
master branch.
不时在其他同步我从C
主分支拉。
But now C
master branch is quite broken for the time being.
Since from A
I had pull from C
my local A
is also bugy.
但是现在C
master 分支暂时很崩溃。因为从A
我拉从C
我的本地A
也是错误的。
So I would like from A
to pull the C
stable branch.
How do you guys usually do in this situation?
所以我想从A
拉C
稳定分支。在这种情况下,你们通常是怎么做的?
Do you create a new branch on A
and pull from C
. But since A
have the C
master change I need to revert it first...
您是否创建了一个新分支A
并从C
. 但既然A
有C
主人改变,我需要先恢复它......
回答by poke
git fetch C
git checkout C/stable-branch
git checkout -b myCopy
Then myCopy
is 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 push
and git pull
without a refspec.
myCopy现在是一个地方分支C /稳定分支,并跟踪它,这样你就可以做git push
并git pull
没有的Refspec。