Git pull - 以下未跟踪的工作树文件将被合并覆盖

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

Git pull -The following untracked working tree files would be overwritten by merge

gitbitbucketgit-pull

提问by baig772

I am trying to do git pullin master branch and I see this message with a long list of files

我正在尝试git pull在 master 分支中执行此操作,并且看到此消息包含一长串文件

The following untracked working tree files would be overwritten by merge:

I really don't care if these files are over written or not, as I need to get the latest form remote. I have looked into it and I cannot do git fetch, git add *and git reset HARD

我真的不在乎这些文件是否被覆盖,因为我需要远程获取最新的表单。我已经调查过了,但我做不到git fetchgit add *而且git reset HARD

When I do git status, it shows me the list of only untracked files. I don't want to commit these files

当我这样做时git status,它只显示未跟踪文件的列表。我不想提交这些文件

回答by Mathews

you may delete the untracked files before getting a pull from remote

您可以在从远程拉取之前删除未跟踪的文件

git clean -f

add the flag nto see a dry run of the files that would be deleted.

添加标志n以查看将被删除的文件的试运行。

git clean -f -n

回答by octopusgrabbus

I just conducted a test to see what produces this error.

我刚刚进行了一个测试,看看是什么导致了这个错误。

1) I created test.txt in my master git development directory, and added it to git.

1)我在我的主git开发目录中创建了test.txt,并将其添加到git中。

2) I created test.txt as an untracked file in the git directory on our production system. From development (master branch) I usually push to a bare git repository remote, and on the development system (master branch) pull from the same bare git repository.

2) 我在我们的生产系统的 git 目录中创建了 test.txt 作为未跟踪的文件。从开发(主分支)我通常推送到一个裸 git 存储库远程,并在开发系统(主分支)上从同一个裸 git 存储库中拉取。

3) I got your error:

3)我收到了你的错误:

[ics@bucky ics_client]$ git pull origin
gituser@h2oamr's password: 
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From h2oamr:ics_client
   193ac65..a6da6b2  master     -> origin/master
Updating 193ac65..a6da6b2
error: Untracked working tree file 'test.txt' would be overwritten by merge.  Aborting
[ics@bucky ics_client]$ 

You could move these files away to a safe place, but be very careful after performing the pull. If you move the untracked files you previously moved back to your git directory, you'll overwrite what came over.

您可以将这些文件移到安全的地方,但在执行拉取操作后要非常小心。如果将之前移回 git 目录的未跟踪文件移回 git 目录,则会覆盖过来的内容。

You could also add these files to git and then pull.

您也可以将这些文件添加到 git 然后拉取。

Or, you can delete these same files from the git repository from which you're pulling, not something I would do.

或者,您可以从从中提取的 git 存储库中删除这些相同的文件,而不是我会做的事情。

Responding to your comment

回应你的评论

These files are the part of my git repo but I want them to be overwritten in master – baig772

These files are the part of my git repo but I want them to be overwritten in master – baig772

and because I am not completely comfortable with git, I would ftp these to your master directory and update these files there. You probably could also do this, by moving these files to a safe place, bringing them back after the pull, and then updating from the satellite git directory, and pulling from the satellite git repository into the master directory.

并且因为我对 git 并不完全满意,我会将这些 ftp 传输到您的主目录并在那里更新这些文件。您可能也可以通过将这些文件移动到安全位置,在拉取后将它们带回来,然后从卫星 git 目录更新,并从卫星 git 存储库拉入主目录来执行此操作。

Personally, I would do it the long way -- take changed files to master directory -- update there, and re-pull into satellite.

就个人而言,我会做很长的路要走 - 将更改的文件带到主目录 - 在那里更新,然后重新拉入卫星。