git pull origin master 返回致命:无效的refspec

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19439501/
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-10 17:09:04  来源:igfitidea点击:

git pull origin master returns fatal: invalid refspec

macosgitgithubterminalrefspec

提问by jhndlntylr

Here is the problem:

这是问题所在:

Whenever I do

每当我做

$ git pull 'https://github.com/username/reponame.github.io.git'

$ git pull 'https://github.com/username/reponame.github.io.git'

followed by the url I get no problems but when I do

后跟网址我没有问题,但是当我这样做时

git pull origin master 'https://github.com/username/reponame.github.io.git'

git pull origin master 'https://github.com/username/reponame.github.io.git'

followed by the url it returns

后跟它返回的网址

fatal: Invalid refspec 'https://github.com/username/reponame.github.io.git'

fatal: Invalid refspec 'https://github.com/username/reponame.github.io.git'

What does this mean and how should I go about fixing it?

这是什么意思,我应该如何修复它?

采纳答案by miqh

If you have already established remote-tracking branches (i.e. git clonedoes this automatically) and want to use git pullwith the intention of grabbing and merging the latest commits for the current branch off the remote repository, I believe that executing the following will suffice:

如果您已经建立了远程跟踪分支(即git clone自动执行此操作)并希望使用git pull它来抓取和合并远程存储库中当前分支的最新提交,我相信执行以下操作就足够了:

git pull

To achieve the same effect with the inclusion of a refspec (unnecessarily long-winded):

为了通过包含 refspec(不必要的冗长)实现相同的效果:

// Pulls the remote 'master' branch down to the local 'master' branch
git pull origin master:refs/remotes/origin/master

You are receiving that error because the provision of a URL is not how the refspec is formatted.

您收到该错误是因为提供的 URL 不是 refspec 的格式。

For further details on how the refspec works and its syntax, consult this chapterfrom the wonderful Pro Git book. Hope that helps!

有关 refspec 如何工作及其语法的更多详细信息,请参阅精彩的Pro Git 书籍中的本章。希望有帮助!

回答by kostix

Please explain what your git pull origin master 'https://github.com/username/reponame.github.io.git'call is supposedto do (in your own mind)?

请解释您的git pull origin master 'https://github.com/username/reponame.github.io.git'电话该做什么(在您自己的脑海中)?

If you'd like to pull the branch "master" from a repo using its explicit URL, then the command to call would be

如果您想使用其显式 URL 从存储库中提取分支“master”,则调用的命令将是

git pull https://github.com/username/reponame.github.io.git master

because "origin" is just a name of a so-called "named remote" which is sort of a configured alias for a repository which allows you to not type that repo's URL each time you access it.

因为“来源”只是所谓的“命名远程”的名称,它是存储库的配置别名,允许您每次访问该存储库时都不必键入该存储库的 URL。

The canonical call to git pullis

对的规范调用git pull

git pull [<repo> [<refspec> ...]]

where parts in [...]are optional — see the manual page.

其中部分[...]是可选的 - 请参阅手册页