由于未跟踪的工作树文件,git 失败

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

git fails because of an untracked working tree file

gitmergebranchrepositorygithub

提问by Trip

I'm not an expert at google. Needless to say, I'm not even sure what this means or how to resolve it?

我不是谷歌专家。不用说,我什至不确定这意味着什么或如何解决它?

>> git merge admin_playground
error: Untracked working tree file 'vendor/gems/panda-1.0.0/.gitignore' would be overwritten by merge.
fatal: merging of trees 538b2824765956cc44c42a8ad628e4f4 and d5d4cda68518cd1c81bf70ba8c339fea6 failed

I am trying to perform a git merge and getting this failing statement.

我正在尝试执行 git merge 并得到这个失败的语句。

采纳答案by mipadi

It's because .gitignoreisn't in your current branch (it's untracked), but it's in the branch you're trying to merge. Add the .gitignorefile in question and commit, then try the merge again; or delete the .gitignorefile if you don't need it and are happy with the one in the other branch.

这是因为.gitignore它不在您当前的分支中(未跟踪),而是在您尝试合并的分支中。添加有.gitignore问题的文件并提交,然后再次尝试合并;或者,.gitignore如果您不需要该文件并且对另一个分支中的文件感到满意,则删除该文件。

回答by VonC

Note: mipadi(author of the accepted answer) also mentioned this error message in the context of case conflictsbetween filenames on different branches.

注意:mipadi(已接受答案的作者)也在不同分支上的文件名之间的大小写冲突的上下文中提到了此错误消息。

If cleaning the untracked files is a valid option, then the extreme solution is mentioned in this answer(a git clean -f -dwould remove alluntracked files and directories).
In your case, that could be overkill (or dangerous).

如果清理未跟踪的文件是一个有效的选项,则此答案中提到了极端的解决方案(agit clean -f -d将删除所有未跟踪的文件和目录)。
在您的情况下,这可能是矫枉过正(或危险)。

Another original solution:

另一个原始解决方案

git checkout -f admin_playground # will overwrite files
git checkout yourBranch # get back where you where when trying the merge
git merge admin_playground

This forced git to go ahead and overwrite the files.
I assume you could have used the '-f' option with mergealso, but switching to the other branch and then back fixed the issue and I was able to merge without any trouble the next time.

这迫使 git 继续并覆盖文件。
我假设您也可以使用 ' -f' 选项merge,但是切换到另一个分支然后返回修复了问题,下次我可以毫无问题地进行合并。

Note: there is actually no '-f' option on git merge.

注意:实际上没有 ' -f' 选项git merge

回答by kintu david

Try running below commands :

尝试运行以下命令:

git add *

git stash

git pull