不能做 git pull

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16447690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:07:04  来源:igfitidea点击:

Can't do a git pull

git

提问by Todd

I'm trying to do a git pulland get the error message:

我正在尝试执行git pull并获取错误消息:

error: The following untracked working tree files would be overwritten by merge:
<myFileName>
Please move or remove them before you can merge.

So, I try to remove the file using the command git rm --cache which results in the error:

因此,我尝试使用命令git rm --cache删除文件,这会导致错误:

fatal: pathspec
<myFileName>
did not match any files

At this point I'm stuck. I can't pull until I remove the file. But, it tells me I can't remove the file.

在这一点上,我被困住了。在我删除文件之前我无法拉动。但是,它告诉我我无法删除该文件。

What can I do to fix this?

我能做些什么来解决这个问题?

采纳答案by Wolf

You have untracked files in the way of the pull. You can't remove them with git rm --cachedbecause they are untracked. They don't appear in the index. You need to remove them with plain old rm

您在拉取方式中有未跟踪的文件。您无法删除它们,git rm --cached因为它们未被跟踪。它们不会出现在索引中。你需要用普通的旧删除它们rm

回答by troyfolger

This is an opportunity for the 'git clean' command. If you don't care about the untracked files... git clean -nto see what will be removed, and git clean -fto go ahead and rm untracked files.

这是 'git clean' 命令的机会。如果您不关心未跟踪的文件...git clean -n查看将删除的内容,然后git clean -f继续并 rm 未跟踪的文件。

Add -d to the commands to also operate on directories:

在命令中添加 -d 也可以对目录进行操作:

  git clean -dn
  git clean -df

回答by Edward Dale

That file isn't in the current branch yet, so you can't remove it with git rm --cache. Just use rm.

该文件尚不在当前分支中,因此您无法使用git rm --cache. 只需使用rm.

回答by Xylarax

I agree with other posters, the issue is that the file isn't being tracked by git. the command git rmworks on files being tracked. rm will remove the file from your machine. Alternatively you could add the file to your list of ignored files, or file types if that is convenient. You could also use one of the GUI tools like tortoise git to quickly delete all untracked files.

我同意其他海报,问题是该文件没有被 git 跟踪。该命令git rm适用于正在跟踪的文件。rm 将从您的机器中删除该文件。或者,如果方便,您可以将文件添加到忽略文件或文件类型列表中。您还可以使用诸如 tortoise git 之类的 GUI 工具之一来快速删除所有未跟踪的文件。

回答by Carl Norum

As it says in the original error message, that file is untracked. That means gitdoesn't know anything about it. Just remove it from the filesystem using rm. If you care about the contents, just move it somewhere else.

正如原始错误消息中所说,该文件未跟踪。这意味着git对它一无所知。只需使用rm. 如果您关心内容,只需将其移到其他地方即可。