git 未知修订版或路径不在工作树错误中,首次推送到空远程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43842239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:44:40  来源:igfitidea点击:

Unknown revision or path not in the the working tree error for first push to empty remote

git

提问by devnull

I have a local git repo with many commits. I created an empty repo in github (not initialized with any files).

我有一个有很多提交的本地 git 仓库。我在 github 中创建了一个空的 repo(没有用任何文件初始化)。

$ git remote add origin https://github.com/bar/foo.git
$ git push -u origin master
Counting objects: 35, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (35/35), 1.95 KiB | 0 bytes/s, done.
Total 35 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), done.
remote: bar/foo
remote: fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
remote: Use '--' to separate paths from revisions, like this:
remote: 'git <command> [<revision>...] -- [<file>...]'
remote: master
To https://github.com/bar/foo.git
 * [new branch]      master -> master

My changes are in remote and things seem to have worked fine. Still, why do I get a "fatal" error ?

我的更改是远程的,事情似乎运行良好。不过,为什么我会收到“致命”错误?

remote: fatal: ambiguous argument 'master': unknown revision or path not in the the working tree.

远程:致命:模棱两可的参数“主”:未知修订版或不在工作树中的路径。

回答by quetzalcoatl

Part of the push -ucommand failed, but it shouldn't be a problem, it's a separate task. You can now try running:

该部分push -u命令失败,但它不应该是一个问题,这是一个独立的任务。您现在可以尝试运行:

git branch --set-upstream- master origin/master

or, in newer git versions:

或者,在较新的 git 版本中:

git branch --set-upstream-to master origin/master

to set it manually. Be sure to adjust branch namesto those you really used. The first argument here is the name of local branch that will be configured, and the second is the target that pushwill now point to by default.

手动设置。请务必将分支名称调整为您真正使用过的名称。这里的第一个参数是将要配置的本地分支的名称,第二个参数是push现在默认指向的目标。

So, in the example above, we're setting local masterto push by default to origin/master. This is what push -u origin masterwould do. If your local repo is OK and if it has 'master' branch, then this command should simply succeed with no errors (and by the way, push-u should have as well back then).

因此,在上面的示例中,我们将 local 设置master为默认推送到origin/master. 这是push -u origin master会做的。如果您的本地存储库没有问题并且它有“master”分支,那么这个命令应该简单地成功而没有错误(顺便说一下,push-u 应该也有)。

If this command fails, you should review what branches and tracking references and upstreams etc you have configured in your local repo - something will be not right!

如果此命令失败,您应该查看您在本地存储库中配置的分支、跟踪引用和上游等 - 有什么不对的!

Maybe i.e. you don't have 'master' branch locally?

也许即您在本地没有“master”分支?