为什么Git允许我创建两个同名的分支? [英] Why has Git allowed me to create two branches with the same name?

查看:519
本文介绍了为什么Git允许我创建两个同名的分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Git还比较陌生,并且对仓库做了一些处理。我希望有一种方法可以解决它,而无需重新克隆。

我有一个我从Github克隆的版本库。该存储库有几个分支。我在master分支上工作了一段时间,但后来需要切换到其他分支之一。



所以,我有:

  $ git branch --all 
* master
遥控器/原点/ abc
遥控器/原点/ def
遥控器/ origin / HEAD - >原产地/主产地
遥控器/原产地/ ghi

问题:我想切换到'abc'分支,而不是做 git checkout remotes / origin / abc 我意外地做了 git branch remotes / origin / abc



  $ git branch --all 
* master
遥控器/原点/ abc
遥控器/原点/ abc
遥控器/原点/ def
遥控器/原点/ HEAD - >原产地/主人
遥控器/原产地/ ghi

我的问题是: strong>




  • 为什么Git允许您创建两个具有相同
    名称的分支?

  • 如何识别哪个是真正的遥控器/原点/ abc分支?

  • 如何删除不需要的遥控器/原点/ abc由
    意外创建?



非常感谢任何帮助。

解决方案

您无法创建两个本地分支或两个具有相同名称的远程分支。


  • 这里有一个名为 remotes / origin / abc 的本地分支和一个名为 abc 的遥远分支来源。它们名称不一样,但是当你使用 git branch --all 命令时似乎是这样。


  • 要确定哪个分支是哪个分支,你可以使用 git branch 显示本地分支,或者使用显示远程分支> git branch --remote 。即使在使用 git branch --all 时使用分支语法着色( git config --global color.branch auto

  • 要移除意外创建的本地分支 abc ,您必须做 git branch -d abc (或 git branch -D abc 强制删除,参见 man git-branch )。



I'm still relatively new to Git and I have made a bit of a mess of my repository. I'm hoping there is a way to fix it without re-cloning.

I have a repository which I have cloned from Github. The repository has several branches. I worked on the master branch for a while but then needed to switch to one of the other branches.

So, I had:

$ git branch --all
* master
  remotes/origin/abc
  remotes/origin/def
  remotes/origin/HEAD -> origin/master
  remotes/origin/ghi

Problem: I wanted to switch to the 'abc' branch but instead of doing git checkout remotes/origin/abc I accidentally did git branch remotes/origin/abc which leaves me with the following:

$ git branch --all
* master
  remotes/origin/abc
  remotes/origin/abc
  remotes/origin/def
  remotes/origin/HEAD -> origin/master
  remotes/origin/ghi

My questions are:

  • Why on Earth does Git allow you to create two branches with the same name?
  • How do I identify which is the real remotes/origin/abc branch?
  • How do I remove the unwanted remotes/origin/abc that I created by accident?

Any help much appreciated.

解决方案

You can't create two local branches or two distant branches with the same name.

  • Here you have a local branch named remotes/origin/abc and a distant branch named abc on the remote origin. They have not the same name, but it seems to when you use the git branch --all command.

  • To identify which branch is which, you can show local branches with git branch, or show remote branches with git branch --remote. You could also easily differentiate them even while using git branch --all with the branch syntax coloration (git config --global color.branch auto).

  • To remove the accidentally created local branch abc, you have to do git branch -d abc (or git branch -D abc to force deletion, see man git-branch).

这篇关于为什么Git允许我创建两个同名的分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆