【问题标题】:Git: Local-tracking, add new branch?Git:本地跟踪,添加新分支?
【发布时间】:2016-02-20 11:42:36
【问题描述】:

我正在尝试清理我的 git 存储库和

  1. 创建一个反映我的生产(主)分支的新分支。
  2. 删除任何不必要的分支,远程或本地。
  3. 让我的本地分支机构成为本地跟踪分支机构(如果我需要这样做,好处是什么?)
  4. 我的工作流程的每个阶段都有一个分支,即一个用于本地和开发 (dev) 的分支、1 个用于暂存 (staging) 的分支和 1 个用于生产 (生产) 的分支。 Local 和 dev 可以共享同一个工作分支,但在暂存和生产时使用不同的分支。

从命令行你可以看到我的环境。

$ git remote
dev
origin
production
staging

$ git branch -r
dev/dev
origin/HEAD -> origin/master
origin/dev
origin/master
production/master
wpengine-findcra/master

$ git branch -vv
dev                   xxxxxxx <comment>
*master               xxxxxxx [origin/master] <comment>
production/staging    xxxxxxx [remotes/production/master] <comment>
staging/master        xxxxxxx <comment>

我有 4 个工作地点。代码从 1 流向 4。

  1. 我的本地机器
  2. 开发服务器
  3. 暂存服务器
  4. 生产服务器

我想为临时服务器添加一个新分支,现在我希望它镜像生产(主)分支。但是我遇到了这个错误,我不知道该怎么办。

$ git checkout master
$ git branch staging
error: there are still refs under 'refs/heads/staging'
fatal: Failed to lock ref for update: Is a directory

我的代码在 origin/master 和 dev/dev 下是最新的。

【问题讨论】:

标签: git github


【解决方案1】:

如果您有一个名称包含斜杠的分支,git 将创建(在.git/refs/heads 中)一个以您的分支名称命名的目录,直到斜杠为止。在该目录中,它将放置分支本身的 refs。所以目录.git/refs/heads/staging/ 存在,并且由于您的分支staging/master 而包含一个文件“master”。

当你尝试创建分支“staging”时,git 会尝试创建文件.git/refs/heads/staging。由于这已经存在但是是一个目录,这将失败。因此,您的存储库中不能有两个具有这些名称的分支。

在最新版本的 git 中,错误消息将如下所示:

fatal: cannot lock ref 'refs/heads/staging': 'refs/heads/staging/master' exists; cannot create 'refs/heads/staging'

【讨论】:

  • 谢谢,这为我指明了正确的方向!我最终删除了一个本地分支登台/master,并创建了一个远程链接到我的登台服务器的新分支登台/登台。我还将它推送到我在 origin/staging aka github 的原始服务器。我删除了 staging/master,但能够签出 origin/master 并将其分支到新的 staging/staging 中,因为我在同一个代码库中。
猜你喜欢
  • 2012-03-05
  • 1970-01-01
  • 2013-03-13
  • 1970-01-01
  • 2010-09-27
  • 2019-02-16
  • 2014-06-09
  • 2014-02-04
  • 2020-01-01
相关资源
最近更新 更多