【问题标题】:git commit problemsgit提交问题
【发布时间】:2010-12-17 06:11:14
【问题描述】:

我刚刚提交了我的工作树,首先添加到索引中,使用“$git commit -m 'test'”我将 stdout-put 从这里保存到一个文件中,我在它的顶部看到它说

# On branch master  
# Changed but not updated:  
# (use "git add/rm ..." to update what will be commited)  
# (use "git checkout -- ..." to discard changes in working directory)"  

问题是我的工作树没有被提交到 repo,我觉得这与它有关

谢谢

【问题讨论】:

  • 您使用的是什么操作系统?具体来说,您是否在 Windows 上使用 Git,如果是,在哪个环境下使用?
  • Ubuntu 服务器,git 1.5.6
  • 我可能建议的第一件事是升级你的 Git 版本,最新版本是 1.6.5.3。我很确定您引用的那些特定消息自 1.5.x 以来已得到改进。
  • 啊抱歉,我的版本是1.6.3.3
  • 是的,我建议升级到 ubuntu 的存储库版本之外,因为以后的版本似乎使处理空格更简单:我只是在这里添加了 PPA:launchpad.net/~git-core/+archive/ppa 和升级的。

标签: git


【解决方案1】:

简答:

git push -u origin master

更长的答案:

您很可能尝试将提交推送到尚未创建的分支 - 例如,在没有自动创建 README 文件的新创建的 Github 存储库上。通过调用git push -u origin master,您可以指定需要推送到的远程(原点,通常是 git 默认值)和分支(主,在典型情况下也是默认值)。根据 git 文档:

-u, --set-upstream 对于每个最新或成功推送的分支,添加上游(跟踪)引用,由无参数 git-pull(1) 和 其他命令。更多 信息,请参阅 git-config(1) 中的 branch..merge。

这意味着在成功运行此命令后,从那时起您将能够只使用git push 和git pull,并且默认为origin master(还有一些exceptions)。

【讨论】:

    【解决方案2】:

    在提交更改之前,必须先将其添加到索引中:

    git add myfile
    git commit -m "test"
    

    或者,您可以使用更类似于 SVN 的样式并提交所有更改的内容:

    git commit -a -m "test"
    

    或者您可以只添加并提交一个文件:

    git commit myfile -m "test"
    

    【讨论】:

    • 做了所有这些。正如我在对 Jed 的回答的评论中提到的那样,我移动了很多文件,所以我认为 commit -a 在这种情况下不会起作用,因为文件正在被删除并重新引入......我认为 git 将它们视为新文件然后文件
    • 我只能建议您没有将文件添加到存储库中,而您认为您已经这样做了;你的消息正是我在没有git add 的情况下运行git commit 时看到的。
    • 很奇怪。我做了一个'git add'。每次。这应该可以解决问题。嗯。感谢您指出这一点
    • 显式添加所需文件是否有效? git add foo bar baz?
    • 这是一个很大的变化,正如我所说,我重新组织了整个项目的文件夹结构,因此手动完成的文件移动/删除太多
    【解决方案3】:

    你在提交之前有git add .吗?

    在git add 或git commit 之前执行git status 总是明智的,以查看发生了什么变化和上演。

    git diff 查看您即将提交的具体更改也非常方便。

    这是git status 显示的内容(如果您已添加文件然后重命名)。

    me@home:~$ git status
    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #   new file:   foo.txt
    #
    # Changed but not updated:
    #   (use "git add/rm <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working directory)
    #
    #   deleted:    foo.txt
    #
    # Untracked files:
    #   (use "git add <file>..." to include in what will be committed)
    #
    #   bar.txt
    

    此时你可以只做git add . 然后git status will give you more information, perhaps pointing out that you still have a new file and a deleted file calledfoo.txt. To fix this you need to manuallygit rm foo.txtbefore doinggit commit`

    如果您将来在 git 存储库中有想要移动的文件,您应该使用 git mv。

    【讨论】:

    • 是的,'git status' 很酷。它也在报告我在问题中提出的信息。那些该死的改变只是没有被提交。我花了一整天的时间阅读教程和文档,试图找到一些可以尝试的东西。
    • 如果您做出任何想要包含在提交中的更改,您需要重做git add。如果您执行git status 然后git add . 然后再次git status,您应该会看到不同。
    • 通过“进行任何更改”,我包括对文件的更改、重命名文件、删除文件、添加文件......任何可能混淆 git 的内容。
    【解决方案4】:

    还有一点需要注意, git add 会在您运行时将这些文件的内容添加到索引中。如果您运行 git add 然后更改文件,新的更改将不会显示在索引中。

    【讨论】:

    • 在 'add' 和 'commit' 调用之间没有做额外的工作
    【解决方案5】:

    你真的必须阅读文档。

    git add yourfile
    git commit -m "test"
    

    或者,提交所有更改的文件 --

    git commit -a -m "test"
    

    【讨论】:

    • 当然,我首先将工作树添加到索引中($git add .),然后运行($git commit -m 'test' > view_file)。我从上次提交中对我的工作树进行了相当多的重组,因此有很多已删除的文件旧位置并将这些文件重新插入到新位置......这就是为什么我将输出保存到文件中以便我可以查看 git 所说的内容
    【解决方案6】:

    如果你移动文件并在之后使用git add,git 只会添加新副本,但不会删除旧副本:

    $ git status
    # On branch master
    nothing to commit (working directory clean)
    $ mv from to
    $ git add .
    $ git status
    # On branch master
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #   new file:   to
    #
    # Changed but not updated:
    #   (use "git add/rm <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working directory)
    #
    #   deleted:    from
    #
    $ git commit -m "..."
    $ git status
    # On branch master
    # Changed but not updated:
    #   (use "git add/rm <file>..." to update what will be committed)
    #   (use "git checkout -- <file>..." to discard changes in working directory)
    #
    #   deleted:    from
    #
    no changes added to commit (use "git add" and/or "git commit -a")
    

    要删除旧副本,您还应该使用git rm:

    $ git rm from
    rm 'from'
    $ git commit -m "..."
    $ git status
    # On branch master
    nothing to commit (working directory clean)
    

    但我不明白为什么它不允许您提交这些更改。

    【讨论】:

      【解决方案7】:

      伙计们,我在 Git 上遇到了同样的问题。
      我在 Windows 8 上运行 Cygwin。

      1. 检查您是否有要提交到的存储库。
      2. 检查路径

      $ git remote -v # 这就是你可以看到你的路径的方式

      $ git remote set-url origin git@github.com:username/repos.git # 这是远程设置新路径以将文件推送到正确存储库的方式。 $ git remote -v # 检查是否设置了正确的路径。

      1. $ git add .

      4.

       $ git push origin master
      

      希望这会有所帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-10-20
        • 2015-01-13
        • 1970-01-01
        • 2011-10-05
        • 2012-09-13
        • 1970-01-01
        • 2017-09-02
        • 2012-04-16
        相关资源
        最近更新 更多