代码之家  ›  专栏  ›  技术社区  ›  lampShadesDrifter

文件出现在“未暂存文件”中,但无法暂存(红色阻塞图标)

  •  1
  • lampShadesDrifter  · 技术社区  · 8 年前

    我有一些文件没有更改,但似乎卡在临时区域。

    $ git remote add origin https://myusername@bitbucket.org/username/myrepo.git 在我的本地项目文件夹中。然后从命令行执行did和初始提交 $ git push -u origin master eclipse 使用IDE命令的IDE File>Import Project From File System . 这样做之后,我发现我的项目中的一些文件位于暂存区域,但没有对它们进行任何更改,在gitkraken中单击它们也报告说它们没有更改(但我无法找到从未暂存文件区域删除它们的方法)。尝试暂存这些文件会使点击手图标闪烁为红色阻塞符号,而不会发生其他任何事情。

    ➜  myproject git:(master) git status
    On branch master
    Your branch is up-to-date with 'origin/master'.
    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:   .classpath
            modified:   .project
            modified:   some-query.sql
    
    no changes added to commit (use "git add" and/or "git commit -a")
    ➜  myproject git:(master) git add .classpath .project some-query.sql
    ➜  myproject git:(master) git commit .classpath .project some-query.sql
    ...
    <some git commit text>
    ...
    ➜  myproject git:(master) git push -u origin master
    Password for 'https://myusername@bitbucket.org':
    ....
    <some git push success text>
    ....
    

    但是,这些文件仍显示在“未老化文件”区域。

    1 回复  |  直到 8 年前
        1
  •  1
  •   LightCC    8 年前

    我相信你只需要提交文件。

    git commit -m "adding .classpath, .project, and some-query.sql modifications"
    

    查找有关工作目录、索引和回购之间差异的信息(还有第四个区域,也称为隐藏)。暂存时,您只是将文件和更改从工作目录移动到索引中。要将这些更改实际放入您的repo中,您需要提交它们,这只会提交索引中的内容,而不仅仅是工作目录中的更改。

    因此,最初,更改只是在您的工作目录中。之后 git add <files> ,它们被放在索引中,但没有提交。之后 git commit git commit -m "<message>" 然后,他们被转移到您的本地回购中的新提交中。只有在这一点上,push才能做任何事情,因为push只将提交(和引用)从本地repo移动到远程repo,它不涉及工作目录或索引。