【问题标题】:GIT: Can't stage changes to commit, Can't pull until I commit the changesGIT:无法暂存更改以提交,在我提交更改之前无法拉取
【发布时间】:2018-11-22 09:36:24
【问题描述】:

我通过 git status 得到这个:

git status
On branch master
Your branch and 'origin/master' have diverged,
and have 3 and 1 different commits each, respectively.
    (use "git pull" to merge the remote branch into yours)
Changes not staged for commit:
    (use "git add <file>..." to update what will be committed)
    (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   application/models/Usuario_model.php
    modified:   application/views/Autor/listar.php
    modified:   application/views/Libro/modificar.php
    modified:   application/views/Libro/perfil.php
    modified:   application/views/ListaLibros/listar.php
    modified:   application/views/Valoracion/crearOk.php

no changes added to commit (use "git add" and/or "git commit -a")

git add &lt;file&gt; 什么都不做

git pull 产生这个:

git pull
: Your local changes to the following files would be overwritten by merge:
    application/models/Usuario_model.php
    application/views/Autor/listar.php
    application/views/Libro/perfil.php
    application/views/ListaLibros/listar.php
    application/views/Valoracion/crearOk.php
commit your changes or stash them before you merge.
Aborting

我无法推送,因为“我当前分支的尖端位于其远程对应分支之后”。

所以我不能先推再拉,我不能先拉再提交,我也不能提交,因为我无法暂存更改。

发生了什么,我该如何解决?

【问题讨论】:

  • 你可以在执行git commit -m "Your Message"之前尝试git add *
  • 运行git add application 然后git status 会发生什么?这两个命令之后的输出是什么?
  • @Code-Apprentice 在git add applicationgit status 显示之前的一切之后什么都没有发生
  • 这很奇怪。检查您的 .gitignore 文件以查看是否有任何规则与这些文件匹配。确保您位于正确的目录中。最后,如果所有其他方法都失败了,您可以按照我的回答中所述使用git stash 来拉取更改。不幸的是,无论如何,您仍然必须解决提交更改的问题。

标签: git github push commit pull


【解决方案1】:

您需要使用git add 指定要添加的内容。使用 git add --all 或指定确切的文件 e.q. git add application/models/Usuario_model.php(支持通配符)。

或者您可以使用 git commit -a 同时进行阶段 + 提交。

请参阅 git addgit commit

【讨论】:

  • 我试过 git add -A 并指定像“git add application/models/Usuario_model.php”这样的文件,但它没有用。我尝试了 git add --all 并且它有效!不是和 git add -A 一样吗?
  • @JuanAntonioRodríguezGabriel 我认为他们是一样的。你在 'git add -A' 上遇到什么错误?
  • 完全没有错误。按下回车后,控制台只显示并清空提示
【解决方案2】:

如果这些文件是第一次提交,你可以试试

git add *git add .

接下来您可以提交更改,

git commit -m "Your Message"

(如果文件之前已提交,您可以将以上两个命令组合在一个命令中,将它们暂存为git commit -a -m "Your Message"

稍后,您可以使用拉动

git pull &lt;remote_name&gt; &lt;branch_name&gt;.

这应该可行。

【讨论】:

    【解决方案3】:

    在这种情况下,听起来您想要提交,但由于某种原因您无法提交。如果您可以稍后再放弃提交,您可以运行 git stash 以暂时将您的更改提交到“stash”。这也会清理您的本地副本。在执行 git pull 并解决任何合并冲突之后,您可以执行 git stash apply 将隐藏的更改应用到您的本地副本或 git stash pop 也从存储中删除更改。

    【讨论】:

      猜你喜欢
      • 2020-12-15
      • 2016-05-08
      • 2018-01-20
      • 2016-01-25
      • 2023-01-08
      • 2011-12-30
      • 2020-12-27
      • 2016-07-05
      • 1970-01-01
      相关资源
      最近更新 更多