Git在远程显示两个分支

时间:2022-09-04 11:08:42

I cloned a git repo and created a branch A using git checkout -b A . After that I did some changes and committed in branch A and pushed it to the remote branch using

我克隆了一个git repo并使用git checkout -b A创建了一个分支A.之后,我做了一些更改并在分支A中提交并使用它将其推送到远程分支

    git push -u origin/A

Meanwhile,I have deleted my local workarea . Now I have to make changes in A. So I cloned the repo again. Now I have two branches origin/A and A . Should I do

与此同时,我删除了我当地的工作区。现在我必须在A中进行更改。所以我再次克隆了回购。现在我有两个分支来源/ A和A.我应该这样做

     git checkout A 
       (or)
     git checkout -b branchname origin/A  

Question: 1) why two branches of the same name when both are same?

问题:1)为什么两个同名的分支都相同?

2 个解决方案

#1


origin/A is the remote, A is your local, so they can be different if remote or local is not up to date. But you do not need to clone again to get a branch, you just have to do git fetch --all

origin / A是远程,A是您的本地,因此如果远程或本地不是最新的,它们可以是不同的。但是你不需要再次克隆来获得分支,你只需要进行git fetch --all

#2


Perhaps the word branch is poorly chosen here. You might say it is a reference point: it is a reference to a commit in the commit graph.

也许在这里选择分支这个词很糟糕。您可能会说它是一个参考点:它是对提交图中提交的引用。

The reason is that git is distributed: every peer stores a (part) of the commit graph. There is no guarantee that the graph on your machine is exactly the same as the one on the remote machine (origin), or on the machine of a friend that collaborates on the project as well.

原因是git是分布式的:每个对等体都存储提交图的(部分)。无法保证您机器上的图形与远程机器(原点)上的图形完全相同,也不能保证在项目上协作的朋友的机器上。

It is for instance possible that the local graph looks like:

例如,本地图可能如下所示:

master    abc----ghi---mno
             \      \
              \      \
A              def----jkl

That means that there are two pointers master pointing to mno and A pointing to jkl. Now the remote can not have been updated recently and only contain:

这意味着有两个指针指向mno和指向jkl的指针。现在远程最近无法更新,只包含:

master    abc----ghi---mno
             \
              \
A              def

It is also possible that another developer made contribution xyz in the remote resulting in a graph:

另一个开发人员也可能在遥控器中创建了xyz,从而生成了一个图表:

master    abc----ghi---mno
             \
              \
A              def---xyz

In that case the union looks like:

在这种情况下,联盟看起来像:

master    abc----ghi---mno
             \      \
              \      \
A              def----jkl
                  \
                   \
origin/A            xyz

In that case origin/A points to def and A points to jkl.

在那种情况下,origin / A指向def,A指向jkl。

So both are the same if the remote is completely in sync with the local repository.

因此,如果远程数据库与本地存储库完全同步,则两者都是相同的。

A git checkout means you are setting the active branch, it means that active state of the project now switches to where the reference is pointing to. If you thus do checkout A, the system will modify files such that it looks like the state stored in commit jkl, furthermore jkl will be marked as the "current" state.

git checkout意味着您正在设置活动分支,这意味着项目的活动状态现在切换到引用指向的位置。如果这样做结帐A,系统将修改文件,使其看起来像存储在commit jkl中的状态,此外jkl将被标记为“当前”状态。

If you would run git checkout -b B A (mind, not origin/A). You simply create a new branch. From now on, both A and B point to jkl. Thus:

如果你要运行git checkout -b B A(介意,不是原点/ A)。您只需创建一个新分支。从现在开始,A和B都指向jkl。从而:

master    abc----ghi---mno
             \      \
              \      \
               def----jkl
                     / |
                   <A> |
                       /
                    <B>

If you run git checkout -b B A: and as said before the origin is not fully synchronized (or is synchronized further), it will result in:

如果你运行git checkout -b B A:并且在原始未完全同步(或进一步同步)之前如上所述,它将导致:

master    abc----ghi---mno
             \      \
              \      \
               def----jkl
              /      /
           <B>    <A>

You can run git fetch --all or git pull --all origin to synchronize the graphs.

您可以运行git fetch --all或git pull --all origin来同步图形。

#1


origin/A is the remote, A is your local, so they can be different if remote or local is not up to date. But you do not need to clone again to get a branch, you just have to do git fetch --all

origin / A是远程,A是您的本地,因此如果远程或本地不是最新的,它们可以是不同的。但是你不需要再次克隆来获得分支,你只需要进行git fetch --all

#2


Perhaps the word branch is poorly chosen here. You might say it is a reference point: it is a reference to a commit in the commit graph.

也许在这里选择分支这个词很糟糕。您可能会说它是一个参考点:它是对提交图中提交的引用。

The reason is that git is distributed: every peer stores a (part) of the commit graph. There is no guarantee that the graph on your machine is exactly the same as the one on the remote machine (origin), or on the machine of a friend that collaborates on the project as well.

原因是git是分布式的:每个对等体都存储提交图的(部分)。无法保证您机器上的图形与远程机器(原点)上的图形完全相同,也不能保证在项目上协作的朋友的机器上。

It is for instance possible that the local graph looks like:

例如,本地图可能如下所示:

master    abc----ghi---mno
             \      \
              \      \
A              def----jkl

That means that there are two pointers master pointing to mno and A pointing to jkl. Now the remote can not have been updated recently and only contain:

这意味着有两个指针指向mno和指向jkl的指针。现在远程最近无法更新,只包含:

master    abc----ghi---mno
             \
              \
A              def

It is also possible that another developer made contribution xyz in the remote resulting in a graph:

另一个开发人员也可能在遥控器中创建了xyz,从而生成了一个图表:

master    abc----ghi---mno
             \
              \
A              def---xyz

In that case the union looks like:

在这种情况下,联盟看起来像:

master    abc----ghi---mno
             \      \
              \      \
A              def----jkl
                  \
                   \
origin/A            xyz

In that case origin/A points to def and A points to jkl.

在那种情况下,origin / A指向def,A指向jkl。

So both are the same if the remote is completely in sync with the local repository.

因此,如果远程数据库与本地存储库完全同步,则两者都是相同的。

A git checkout means you are setting the active branch, it means that active state of the project now switches to where the reference is pointing to. If you thus do checkout A, the system will modify files such that it looks like the state stored in commit jkl, furthermore jkl will be marked as the "current" state.

git checkout意味着您正在设置活动分支,这意味着项目的活动状态现在切换到引用指向的位置。如果这样做结帐A,系统将修改文件,使其看起来像存储在commit jkl中的状态,此外jkl将被标记为“当前”状态。

If you would run git checkout -b B A (mind, not origin/A). You simply create a new branch. From now on, both A and B point to jkl. Thus:

如果你要运行git checkout -b B A(介意,不是原点/ A)。您只需创建一个新分支。从现在开始,A和B都指向jkl。从而:

master    abc----ghi---mno
             \      \
              \      \
               def----jkl
                     / |
                   <A> |
                       /
                    <B>

If you run git checkout -b B A: and as said before the origin is not fully synchronized (or is synchronized further), it will result in:

如果你运行git checkout -b B A:并且在原始未完全同步(或进一步同步)之前如上所述,它将导致:

master    abc----ghi---mno
             \      \
              \      \
               def----jkl
              /      /
           <B>    <A>

You can run git fetch --all or git pull --all origin to synchronize the graphs.

您可以运行git fetch --all或git pull --all origin来同步图形。