忽略特定文件的合并冲突
我有一个位于存储库中的文件并添加到 .gitignore
中。当我构建项目时,此文件会被修改,但更改是特意在本地进行的,不应最终出现在存储库中。存储库中也需要文件存在,因此我无法删除它。
问题是,每当我执行 git pull 时,都会遇到冲突,因为文件已在本地更改,我需要删除此文件才能成功完成拉取。是否可以忽略此文件中的合并冲突并始终将其替换为存储库中的版本?
I have a file that is in a repository and added to .gitignore
. When I build the project, this file gets modified, but changes are purposely local and shouldn't end up in the repo. The file presence is also required in the repo so I can't remove it.
The problem is that whenever I do git pull
I get conflict, due to a fact that the file has been changed locally, and I need to remove this file for pull to finish successfully. Is it possible to ignore merge conflicts in this file and always replace it with a version from the repository?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Git 没有提供一种方法来完成您想要的操作。 Git 提供了显式执行合并而无需更改任何内容的选项(
-X thoses
)以及使用自定义合并驱动程序来执行合并的选项,但是这些选项都不会执行您想要的操作这个案例。Git 无意用于存储任何类型的构建工件,因此 Git 开发人员通常对此作为用例不感兴趣,之前关于此主题的列表中的帖子已经说了这么多。最好的选择是将预构建的工件存储在服务器上,并在检查强加密哈希(例如 SHA-256)后下载并使用它。在 Perl 社区中,构建包含所有资产和依赖项的自包含单个脚本称为“fatpacking”,类似的方法可能对您也有用。
Git doesn't provide a way to do what you want. Git provides options which explicitly perform a merge without changing anything at all (
-X theirs
) and options which use a custom merge driver to perform a merge, but neither of those is going to do what you want in this case.Git is not intended to be used to store any sort of build artifact, so the Git developers typically aren't interested in this as a use case, and previous posts to the list on this topic have said as much. Your best bet is to store a pre-built artifact on a server and download and use that after checking a strong cryptographic hash (e.g., SHA-256). In the Perl community, building a self-contained single script with all assets and dependencies is called "fatpacking", and a similar approach may be useful for you here as well.
我认为您可以使用 git pull -X 他们的文件的存储库版本来解决冲突。
I think you can use git pull -X theirs to resolve conflicts using the repo version of the file.