【问题标题】:Push a newly created file into git repository将新创建的文件推送到 git 存储库
【发布时间】:2016-07-06 07:44:00
【问题描述】:

我创建了一个 linux 目录的 git 存储库并将所有文件推送到其中。我最近将一个新文件移动到该 linux 目录中,现在想将这个新文件推送到它的 git 存储库中。我正在尝试通过键入来做到这一点

 git push origin master

在命令行中,但出现错误:

fatal: 'origin' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

有谁知道如何将新文件推送到该文件所在文件夹的现有 git 存储库中?我是 git 新手,所以不胜感激。

【问题讨论】:

  • 您只有本地仓库还是远程仓库?

标签: linux git push


【解决方案1】:

如果您的文件已经在您创建的 git 存储库中,添加和提交就足够了:无需推送。

myrepo      <== "I have created a git repository of a linux directory"
  .git           (the .git folder is the git repo referential)
  myNewfile <== "I have recently moved a new file into that linux directory"

即。本地 git repo 没有可推送到的远程“来源”。

Git Basics - Recording Changes to the Repository”章节是一个很好的起点。

git add myNewFile
git commit -m "Add a new file"

【讨论】:

  • 我明白了!那我需要做: git commit -m "somemessage" 和 git add "filename" 来推送我在文件夹中添加的新文件吗?
  • @zsha no: git add,然后 git commit。更多信息请访问git-scm.com/book/en/v2/…
【解决方案2】:
  1. 验证您是否已签出存储库分支(您正在处理的分支)。
  2. 确保先提取更新

  3. 在推送之前执行 'git add newfileNameWithPath' 并提交。

【讨论】:

    【解决方案3】:

    看来你对git push命令的理解有误,请看下图,让你概念更清晰。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-12
      • 1970-01-01
      • 2011-12-09
      • 2012-02-16
      • 2023-02-09
      • 1970-01-01
      • 2017-01-10
      • 2011-05-05
      相关资源
      最近更新 更多