【问题标题】:Upload files in GitHub在 GitHub 中上传文件
【发布时间】:2015-04-23 09:46:57
【问题描述】:

我安装了 Git Bash 1.9.5。我在 www.github.com 创建了一个仓库。我想从本地计算机上传一个名为 test.txt 的文件到远程 github。我查看了几个旧问题,但找不到解决方法。请帮忙。

我尝试了git add test.txt,然后尝试了git push,但并没有真正奏效。任何帮助将不胜感激。

谢谢

【问题讨论】:

  • 您是否完整阅读了 GitHub 教程?如果您这样做了,请提供更多信息,包括您遇到的任何错误。另外:您需要在推送之前提交。
  • “没有真正工作”并不能真正传达命令的输出。
  • 在我的电脑中,GitBash 存储库位于 "C:/Users/Sambit/localrepo" 中,我在其中创建了一个名为 "test.txt" 的文本文件。现在来到 GitBash 控制台,我写 cd ~/localrepo 来指定我的本地存储库。然后我写git remote add origin "https://github.com/remoteusername/remoterepo",然后我写git add.,然后写git commit -m "add test.txt",上面写着Changes not staged for commit....no changes added to commit",然后git push写着updates were rejected because the remote contains work that you do not have locally...",但我已经克隆了
  • @user3096833 你确定你做了git clone https://github.com/remoteusername/remoterepo C:/Users/Sambit/localrepo 吗?因为如果你做了git clone,你不需要添加遥控器。按照我在下面提到的第二种方法,它会起作用。
  • 仍然抛出错误。克隆语句给出错误destination path already exists and is not an empty directory 然后添加语句显示很多警告,最后给出错误:unable to index file... 然后fatal : adding files failed

标签: git github git-bash


【解决方案1】:

在您的本地仓库中,您可以添加远程 GitHub 仓库的远程 url

git remote add origin https://<yourAccount>@github.com/<yourAccount>/<yourRepo)
git commit -m "Add test.txt"
git push -u origin master

另一种方法是先克隆你的仓库,然后在其中添加你的文件(然后git add .; git commit -m "add test.txt"; git push

【讨论】:

    【解决方案2】:

    git add 将文件添加到索引中,但不会创建提交。

    要从索引创建新提交,请使用git commit

    当您有提交时,使用 git push 推送它。

    查看您对gitk 所做的事情(例如)。

    有关更多信息,请参阅任何关于 git 的教程。例如:http://www.gitguys.com/topics/whats-the-deal-with-the-git-index/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-01
      • 2020-07-17
      • 2012-03-23
      • 2018-04-26
      • 1970-01-01
      • 2017-04-04
      • 2019-11-23
      • 2017-03-13
      相关资源
      最近更新 更多