未跟踪和更改的文件是相同的

时间:2016-01-07 15:32:54

标签: git

如果没有跟踪,git如何告诉我某些内容已发生变化?当它被发现为未跟踪时,如何将其删除?:

$ git status
On branch updated-code-foundation
Your branch is ahead of 'origin/updated-code-foundation' by 16 commits.
  (use "git push" to publish your local commits)
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    deleted:    component/portal/src/Joppli/Acl/AclInterface.php
    deleted:    container/php-apache/config/apache/default.conf
    deleted:    container/php-apache/config/php/php.ini

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    component/portal/src/Joppli/Acl/AclInterface.php
    container/php-apache/config/

我通过git add . 解决了这个问题(无需提交......)

  1. 为什么会发生这种情况?
  2. 如何防止这种情况发生?

2 个答案:

答案 0 :(得分:3)

1。该方案如下:

  • 您有一个已跟踪并先前已提交到存储库的文件
  • git rm文件
  • 再次创建文件

示例:

git add myfile
git commit -m "myfile"
git rm myfile
echo test > myfile
git status

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    deleted:    myfile

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    myfile

2. 我不知道如何防止它,因为它取决于文件是什么。 可能是文件是自动生成的,有人错误地提交了文件,然后试图删除它们。

他们可能属于.gitignore

答案 1 :(得分:1)

如果您要添加hunks,也可能出现这种情况。

添加带有-p标记的文件并拆分更改。

您将在工作目录(如果之前未添加未跟踪)中以及您刚添加的帅哥的暂存区域中拥有它。

正如您在图像中看到的那样,您可以拆分已更改的内容,只将少数几个添加到暂存区域。

enter image description here