为什么它不是一个提交,并且不能从它创建一个分支?

时间:2018-03-15 10:33:31

标签: git git-non-bare-repository

我需要使用复杂的存储库配置。我有5个:

  1. 计算机1上的远程中央存储库。
  2. 我笔记本上的本地存储库(机器2)。
  3. 计算机3上的裸存储库。
  4. 机器3上的存储库。
  5. 我们进行代码审查的机器4上的存储库。
  6. 所以,我理解它的工作原理如下:

    1. 在我的笔记本电脑(机器2)上,我从机器1上的中央存储库克隆/拉出。
    2. 我将本地存储库推送到机器3(使用裸存储库作为“中间”)。
    3. 现在我在机器3上做了一些更改,我想将这些更改推送到机器4.以下是我需要遵循的说明:

      1. 在机器3上,所有工作都在您的测试分支中提交。
      2. 推送到机器3上的裸仓库:git push origin test-branch
      3. 在你的笔记本电脑上:从机器上获取新的提交3个回购:git fetch machine3
      4. 从机器3检查你的分支:git checkout -b test-branch machine-3 / test-branch
      5. 从机器4获取提交:git fetch origin
      6. git rebase origin / master
      7. git push origin HEAD:refs / for / master
      8. 我遇到第4步的问题。我收到以下错误:

        fatal: 'machine3/test-branch' is not a commit and a branch 'test-branch' cannot be created from it
        

        已添加

        执行时

        git rev-parse machine3/test-branch
        

        在我的笔记本电脑(机器2)上,我得到了:

        machine3/test-branch
        fatal: ambiguous argument 'machine3/test-branch': unknown revision or path not in the working tree.
        Use '--' to separate paths from revisions, like this:
        'git <command> [<revision>...] -- [<file>...]'
        

8 个答案:

答案 0 :(得分:4)

对于那些在此搜索fatal: 'origin/branch' is not a commit and a branch 'branch' cannot be created from it的人来说,您可能还想先尝试git fetch

如果您在没有先进行git checkout -b local-branch-name origin/different-branch-name的情况下运行fetch,则会遇到该错误。

答案 1 :(得分:1)

我设法通过此设置解决了这个问题,只需使用此命令更新配置

git config -e --global

并添加此配置。

[remote "origin"]
    url = https://git.example.com/example.git (you can omit this URL)
    fetch = +refs/heads/*:refs/remotes/origin/*

然后您可以git fetch --all

答案 2 :(得分:1)

我们遇到了这个错误:

fatal: 'origin/newbranch' is not a commit and a branch 'newbranch' cannot be created from it

因为我们做了一个极简的克隆:

git  clone  --depth 1  --branch 'oldbranch'  --single-branch  'git@github.com:user/repo.git'

对我们来说,最简单的修复是:

git  remote  set-branches  --add  'origin'  'newbranch'
git  fetch  'origin'
git  checkout  --track  'origin/newbranch'

假设远程名为“origin”,远程分支名为“newbranch”。

答案 3 :(得分:0)

问题是复杂/卷积,答案很简单。别名和机器3之间存在不匹配。已使用的远程别名不适用于machine3。机器3有另一个别名。

答案 4 :(得分:0)

如果您要从标记中检出分支(例如P),则可以先尝试git checkout -b XXXX v0.1.1

答案 5 :(得分:0)

我在Visual Studio代码中使用了git工作流,如下图所示来解决我的问题:

create a feature branch using git on vscode

答案 6 :(得分:0)

对于这个问题:

fatal: 'machine3/test-branch' is not a commit and a branch 'test-branch' cannot be created from it

对我来说,我应该先检查 test-branch,然后它工作正常并从 test-branch 创建一个新分支。

答案 7 :(得分:-1)

来自J.D. Mallen的解决方案涉及git fetch --all

从 VSCode 1.53(2021 年 1 月)开始,您将拥有(issue 110811PR 111090):

<块引用>

autofetch 更改为具有“current”、“all”和“off”的字符串配置。

这允许用户从所有遥控器中获取,而不仅仅是他们的 origin
对于在 Fork 上工作的开发人员来说,这应该会使扩展程序更直观地工作。

因此,如果您将 VSCode 设置 git.autofetch 设置为“all”,您甚至不必键入 git fetch --all