Git push origin master 返回“致命:未指定路径”。

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

Git push origin master returns "fatal: No path specified."

gitgithub

提问by user306472

I recently set up a new account with github. I'm following a Rails tutorial from Michael Hartl online ( http://www.railstutorial.org/book#fig:github_first_page) and followed his instructions to set up my git which were also inline with the setup instructions at github. Anyways, the "Next Steps" section on github were:

我最近在 github 上建立了一个新帐户。我正在关注 Michael Hartl 在线 ( http://www.railstutorial.org/book#fig:github_first_page)的 Rails 教程,并按照他的说明设置我的 git,这也与 github 上的设置说明一致。无论如何,github 上的“下一步”部分是:

  mkdir sample_app
  cd sample_app
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin [email protected]:rosdabos55/sample_app.git
  git push origin master

I got all the way to the last instruction (git push origin master) without any problem. When I entered that last line into my terminal, however, I got this error message:

我一直到最后一条指令(git push origin master)没有任何问题。但是,当我在终端中输入最后一行时,收到以下错误消息:

fatal: No path specified. See 'man git-pull' for valid url syntax.

致命:未指定路径。有关man git-pull有效的 url 语法,请参阅“ ”。

What might I be doing wrong?

我可能做错了什么?

Here are the contents of .git/config (reconstructed by Jefromi from the output of git config -lpasted into a comment below):

以下是 .git/config 的内容(由 Jefromi 从git config -l粘贴到下面注释的输出中重建):

[user]
    name = Ross
    email = [REDACTED]
[core]
    editor = gvim -f
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = [email protected]:
    fetch = +refs/heads/*:refs/remotes/origin/*

回答by Cascabel

I've stated this in the comments to another answer, but it's really the answer (and I've edited the appropriate section of the comments into the question where it belongs).

我已经在另一个答案的评论中说明了这一点,但这确实是答案(并且我已将评论的相应部分编辑到它所属的问题中)。

The URL for the remote was not configured correctly, for whatever reason. It's set to "[email protected]:", which is clearly missing the path, producing precisely the error you see. You need to reconfigure it correctly. You could simply edit .git/config, changing the appropriate line to contain the path. Or you could do this:

无论出于何种原因,遥控器的 URL 都没有正确配置。它设置为“[email protected]:”,这显然缺少路径,准确地产生了您看到的错误。您需要正确地重新配置它。您可以简单地编辑.git/config,更改适当的行以包含路径。或者你可以这样做:

git remote rm origin
git remote add origin '[email protected]:rosdabos55/sample_app.git'

You almost certainly made some small typo or careless mistake when you added the remote the first time - perhaps you hit enter in the middle of it, perhaps you typed a space after the colon. (For some reason, git does not appear to throw an error when you provide an extra argument after remote add <name> <url>- it just ignores it.) The upshot is that you didn't actually run that command, and you added a remote with an incomplete URL.

当您第一次添加遥控器时,您几乎肯定会犯一些小的错字或粗心的错误 - 也许您在其中按了 Enter 键,也许您在冒号后输入了一个空格。(出于某种原因,当您在之后提供额外参数时,git 似乎不会抛出错误remote add <name> <url>- 它只是忽略它。)结果是您实际上没有运行该命令,并且您添加了一个带有不完整 URL 的遥控器。

回答by Tim Snowhite

You may need to git pull originbefore you git push origin master.

你可能需要git pull origin在你之前git push origin master

回答by Benjamin Manns

Can you post the output of git remote show?

你能发布输出git remote show吗?

It looks like something went wrong when you added your remote repository (git remote add origin [email protected]:rosdabos55/sample_app.git).

添加远程存储库 ( git remote add origin [email protected]:rosdabos55/sample_app.git)时似乎出了点问题。

回答by Sachin Shetti

edit the git config in your home directory

编辑主目录中的 git 配置

vi ~/.gitconfig

comment the below

在下面评论

#[remote "origin"]
#   url = git@#######D########################.git
# fetch = +refs/heads/*:refs/remotes/origin/*

save it.

保存。

The conflict happens between the git config in global the local [individual project level].

冲突发生在全局和本地[个人项目级别]的git config之间。

This solved the issue for me.

这为我解决了这个问题。