文件出现在 "unstaged files",但无法暂存(红色阻止图标)

Files appearing in "unstaged files", but can't stage (red blocking icon)

我的文件没有任何变化,但似乎卡在暂存区。

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

我尝试在 cli 中手动暂存和推送这些 "ghost changes",并得到以下输出:

➜  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>
....

但是,这些文件仍然出现在 "unstaged files" 区域。

如果有人知道这里发生了什么,将不胜感激。谢谢 :)

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

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

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

所以最初,更改只是在您的工作目录中。在 git add <files> 之后,它们在索引中暂存,但未提交。在 git commitgit commit -m "<message>" 之后,它们将被移动到您本地仓库中的新提交中。只有在这一点上 push 才会做任何事情,因为 push 只会将提交(和引用)从本地移动到远程 repos,它不会触及工作目录或索引。