Why is it not a commit and a branch cannot be created from it?

邮差的信 提交于 2019-12-21 09:37:45

问题


I need to work with an intricate configuration of repositories. I have 5 of them:

  1. A remote central repository on machine 1.
  2. My local repository on my notebook (machine 2).
  3. A bare repository on machine 3.
  4. A repository on machine 3.
  5. A repository on machine 4 where we do code review.

So, my understanding that it works this way:

  1. On my laptop (machine 2) I clone / pull from the central repository located on machine 1.
  2. I push the local repo to the machine 3 (using the bare repository as a "intermediate").

Now I did some changes on the machine 3 and I want to push these changes to machine 4. Here are the instructions that I need to follow:

  1. On machine 3 do all work in your test-branch, commit.
  2. Push to your bare repo on machine 3: git push origin test-branch
  3. On your laptop: fetch new commits from the machine-3 repo: git fetch machine3
  4. Check out your branch from machine 3: git checkout -b test-branch machine-3/test-branch
  5. Fetch commits from machine-4: git fetch origin
  6. git rebase origin/master
  7. git push origin HEAD:refs/for/master

I have problems with step 4. I get the following error:

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

ADDED

When I execute

git rev-parse machine3/test-branch

On my laptop (machine 2) I get:

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>...]'

回答1:


For those who found this searching for an answer to fatal: 'origin/branch' is not a commit and a branch 'branch' cannot be created from it, you may also want to try git fetch first.

If you run git checkout -b local-branch-name origin/different-branch-name without fetching first, you'll run into that error.

Also, if you have multiple remotes (e.g. origin, then buildserver, joespc, etc.), you must specify the remote from which you're attempting to branch in your git fetch command, as it defaults to your first remote, usually origin (i.e. git fetch origin). So, for example, git fetch buildserver will fetch all the branches from the buildserver remote.




回答2:


The question is complex / convolute, the answer is simple. There was a mismatch between the alias and machine3. The alias for the remote that has been used, was not for machine3. The machine3 had another alias.




回答3:


If you're checking out a branch from a tag (like git checkout -b XXXX v0.1.1) , you can try git fetch --tags first.



来源:https://stackoverflow.com/questions/49297153/why-is-it-not-a-commit-and-a-branch-cannot-be-created-from-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!