Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git抱怨未跟踪的文件_Git_Github - Fatal编程技术网

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

  • 如何摆脱它?我想返回到
    功能
    分支,而不更改
    主机

我尝试了git rm--缓存的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