gpt4 book ai didi

git - 由于与本地排除文件冲突,无法 git pull

转载 作者:太空狗 更新时间:2023-10-29 14:41:16 24 4
gpt4 key购买 nike

我有一个我在本地排除的配置文件。我没有使用 .gitignore 因为其他团队成员更新了文件,但我的本地更改只适用于我的机器。我用这个问题作为如何排除文件的引用:How do I configure git to ignore some files locally?

团队成员更新了文件,我现在无法执行 git pull。我收到错误:

error: Your local changes to the following files would be overwritten by merge:
config/td_config.php
Please commit your changes or stash them before you merge.

但我的本地显示 td_config.php 没有任何变化,因为它被排除在外。我无法提交或 stash 它。

我的问题是:

  1. 为什么远程会看到我已排除的文件的本地更改,而我的预期是远程不会知道对已排除文件的更改?

  2. 我该如何解决这个问题?

我试过了git update-index --no-assume-unchanged config/td_config.php无济于事。

最佳答案

Why does the remote see local changes to a file I've excluded when my expectation is that the remote will not be aware of changes to an excluded file?

因为 that's not what assume-unchanged does ;事实上,它的目的恰恰相反(粗体添加):

Assume-unchanged should not be abused for an ignore mechanism. It is "I know my filesystem operations are slow. I'll promise Git that I won't change these paths by making them with that bit---that way, Git does not have to check if I changed things in there every time I ask for 'git status' output". It does not mean anything other than that. Especially, it is not a promise by Git that Git will always consider these paths are unmodified---if Git can determine a path that is marked as assume-unchanged has changed without incurring extra lstat(2) cost, it reserves the right to report that the path has been modified (as a result, "git commit -a" is free to commit that change).

是的,有很多资源建议assume-unchanged 忽略对跟踪文件的本地更改。他们几乎全错了,而您所问的问题是失败的原因之一。

不幸的是,assume-unchanged 通常看起来像是忽略了对文件的更改,因此人们继续使用它并推荐它。

How do I get around this problem?

skip-worktree is a better option , 但它也不是完美的搭配。更好的解决方案是与您的团队协调 rename the tracked file to td_config.template.php or similar and properly ignore td_config.php .

不要与 Git 作对;按照应有的方式使用它。它不提供忽略跟踪文件的机制,并且所有当前的解决方法都存在这样或那样的缺陷。

(如果你真的想忽略这个建议,你应该能够 git update-index --no-assume-unchanged 文件,然后存储你的更改,然后 pull ,然后应用你的更改,然后重新应用钻头。但这样做时要知道它不会按照您的意愿行事。)

编辑:

OP 评论说

When I originally set this up, I tried update-index, skip-worktree, and the exclude file… so at this point it's pretty hard to understand how exactly git is or isn't tracking the file.

运行 git ls-files -v config/td_config.php 帮助我们找出哪些设置在该文件上处于事件状态。在这种情况下,我们得到了

S config/td_config.php

大写字母 S 向我们展示了 skip-worktree is set ,那 assume-unchanged在文件上未设置。运行 git update-index --no-skip-worktree config/td_config.php 应将其返回到“正常状态”,此时可以使用上述任何建议。

关于git - 由于与本地排除文件冲突,无法 git pull,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55600570/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com