git 错误:以下未跟踪的工作树文件将被合并覆盖:.gitignore

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

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

git

提问by user3333901

I am working on a web app with Angular JS. After Commit, I am trying to Pull the latest version of the other web developer to merge it with mine before I Push my latest changes. I am getting this error and don't know why is this happening because I had no problem on the previous pull / push.

我正在使用 Angular JS 开发一个网络应用程序。在提交之后,我试图在推送我的最新更改之前拉取其他 Web 开发人员的最新版本以将其与我的合并。我收到这个错误,不知道为什么会发生这种情况,因为我在之前的拉/推上没有问题。

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

回答by bnjmn

It appears you have created a local .gitignorefile but have not commited it to the repository and the remote you are attempting to interact with (pull/push) now has a .gitignore. This would be the case for any file in your repo when this happens

看来您已经创建了一个本地.gitignore文件,但尚未将其提交到存储库,并且您尝试与之交互(拉/推)的远程现在有一个.gitignore. 发生这种情况时,您的存储库中的任何文件都会出现这种情况

Since .gitignoreis not just any file, it affects the way git behaves, I would compare the two manually, create a file that is a union of the two, commit it and then merge, fixing any formatting issues that might exist.

由于.gitignore不仅仅是任何文件,它会影响 git 的行为方式,我会手动比较两者,创建一个是两者联合的文件,提交它然后合并,修复可能存在的任何格式问题。

These could be the exact same file, but gitwouldn't know because you haven't added it locally. This isn't a file you want to be changing often because it can make checkouts behave differently.

这些可能是完全相同的文件,但git不知道,因为您没有在本地添加它。这不是您想要经常更改的文件,因为它可以使结帐行为不同。

Github maintains a list of useful .gitignoretemplatesfor most languages.

Github为大多数语言维护了一个有用的.gitignore模板列表