git 错误:未跟踪的工作树文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9274528/
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 12:58:52  来源:igfitidea点击:

error: Untracked working tree file

gitgithubgit-svn

提问by Leem.fin

When I git pull origin development, I got error:

当我git pull origin development,我得到错误:

error: Untracked working tree file '<path-to-file>' would be overwritten by merge

The reason is because one file which is in the remote development branchis not put to git in my local project (I don't want that file in version control, so did git rm). But on remote development, that file is exit for version control

原因是因为 中的一个文件remote development branch没有放入我本地项目中的 git(我不希望该文件处于版本控制中,也是如此git rm)。但是remote development,该文件退出以进行版本控制

How to resolve this problem? Basically, I want the remote branch also remove the file from version control.

如何解决这个问题?基本上,我希望远程分支也从版本控制中删除文件。

回答by Peter Bratton

To resolve your immediate problem, you should make a backup of the local file, remove the original, pull from the remote branch, and then git rm (followed by a push, to make sure the remote repo deletes the file as well). Then you can put the backup file back locally, and add a line to your .gitignore file.

要解决您眼前的问题,您应该备份本地文件,删除原始文件,从远程分支中拉取,然后 git rm (随后进行推送,以确保远程存储库也删除该文件)。然后您可以将备份文件放回本地,并在您的 .gitignore 文件中添加一行。

回答by dannio

This is happening due to an untracked file will be overwritten by a new file coming in from the pull request

这是因为未跟踪的文件将被来自拉取请求的新文件覆盖

My suggestion would be to:

我的建议是:

git add .
git stash
git pull

Basically adding the files that aren't tracked into your git repo and stashing them away and pulling in the new version.

基本上将未跟踪的文件添加到您的 git 存储库中并将它们藏起来并拉入新版本。

回答by monkey intern

As @vpatil linked, and I found on this somewhat related git issue, @mtkumar82 over there suggest doing the following:

正如@vpatil链接的,我在这个有点相关的git 问题上发现,@mtkumar82 那边建议执行以下操作:

git fetch --all
git reset --hard origin/{{your branch name}}

This worked perfectly for me, since I had untracked files that were of no importance to the code itself, so they were untracked, and I did not care what version they were. I hope this helps people in the future that end in this thread and not the other, bigger one, as it happened to me (in fact google did not show even this one, I found it once I already had the solution).

这对我来说非常有效,因为我有未跟踪的文件,这些文件对代码本身并不重要,所以它们没有被跟踪,我不在乎它们是什么版本。我希望这可以帮助将来以这个线程结束的人,而不是另一个更大的线程,因为它发生在我身上(实际上,谷歌甚至没有显示这个线程,一旦我有了解决方案,我就找到了它)。

回答by vpatil

You can use gitignore option.
For details refere these -

您可以使用 gitignore 选项。
有关详细信息,请参阅这些 -

http://help.github.com/ignore-files/
http://linux.die.net/man/5/gitignore

http://help.github.com/ignore-files/
http://linux.die.net/man/5/gitignore