git抱怨未跟踪的文件

时间:2014-07-02 13:15:37

标签: git github

我有两个分支:

-- feature
-- master

我曾经在功能分支上工作。然后,我通过git checkout master更改为分支。在我为master工作之后,我运行了git status,它向我展示了以下内容:

# On branch master
# Your branch is ahead of 'origin/master' by 38 commits.
#   (use "git push" to publish your local commits)
#
# 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:   MyProject/school.java
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   MyProject/other/proj.properties

我决定省略我在MyProject/school.java上所做的更改,所以我运行:

git checkout MyProject/school.java,效果很好。

此时,我运行git checkout feature返回feature分支,但是收到以下错误消息:

error: The following untracked working tree files would be overwritten by checkout:
    MyProject/other/proj.properties
  • 当我切换到另一个分支时,为什么git会抱怨未跟踪文件MyProject/other/proj.properties

  • 如何摆脱它?我想回到feature分支而不更改任何内容master

我试过git rm --cached MyProject / other / proj.properties但是我收到了以下错误:

fatal: pathspec 'MyProject/other/proj.properties' did not match any files

1 个答案:

答案 0 :(得分:2)

原因是,该文件在feature分支中被跟踪,但在master中没有。 因此,结帐时master中的文件会被feature中的文件覆盖,您将失去更改。

Git会识别并阻止您丢失未跟踪文件中的更改。

编辑:如果可以删除该文件中的更改,只需删除该文件即可。您不需要git rm,因为未跟踪该文件。