git抱怨未跟踪的文件
我有两个分支机构:git抱怨未跟踪的文件,git,github,Git,Github,我有两个分支机构: -- feature -- master 我曾经在功能分支上工作。然后,我通过git checkout master切换到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) # # C
-- feature
-- master
我曾经在功能分支上工作。然后,我通过git checkout master
切换到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
- 当我切换到另一个分支时,为什么git抱怨未跟踪的文件
MyProject/other/proj.properties
- 如何摆脱它?我想返回到
分支,而不更改功能
主机
fatal: pathspec 'MyProject/other/proj.properties' did not match any files
原因是,文件是在
功能
分支中跟踪的,而不是在主文件
中跟踪的。
因此,签出时,master
中的文件将被feature
中的文件覆盖,您将丢失更改
Git认识到这一点,并防止您丢失未跟踪文件中的更改
编辑:如果可以删除该文件中的更改,只需删除该文件。您不需要
git rm
,因为该文件未被跟踪。是的,您是对的。那么,我怎样才能恢复到切换到主分支之前的状态呢?我的意思是,我想返回到feature branch,而不更改master上的任何内容……我理解,您不想提交proj.properties
文件。如果这是正确的,只需删除该文件。由于没有跟踪,您必须使用rm
(而不是git-rm
)。
fatal: pathspec 'MyProject/other/proj.properties' did not match any files