Git:在 gitattribute 中为整个文件夹指定 git merge 策略 "ours"(或者只是禁用特定文件夹的 merge 错误?)

标签 git git-merge git-bash

我需要从 merge 错误中排除 dist/ 文件夹,我不在乎它是 他们的我们的 还是其他策略但我需要将它保留在修订控制中,因为这是部署到 Heroku 的方式。 .gitattributes 脚本似乎是要走的路。但我似乎无法完成这项工作。

我读了这个canonical answer还有这个similiar answer但无法找出我做错了什么。

我的.gitattributes 配置:

* text=auto
dist/ merge=keepMine

我的 .git/config 的相关部分:

[merge "keepMine"]
    name = always keep mine dist during merge
    driver = keepMine.sh %O %A %B

keepMine.sh(在我的项目根文件夹中,没有文件夹不在路径中,但是复制到路径中的文件夹没有帮助,也不是一个好的解决方案因为脚本应该是修订控制的一部分,所以所有开发人员都会得到它):

# copied as is from the SO answer
# I want to keep MY version when there is a conflict
# Nothing to do: %A (the second parameter) already contains my version
# Just indicate the merge has been successfully "resolved" with the exit status
exit 0

编辑: 还尝试了 git config merge.keepMine.driver true,如上面的 SO 答案之一所建议的那样。没用。

但我仍然遇到 merge 错误(如果我创建它们),例如在 dist/styles/sdkasl.main.css 中。

我做错了什么?感谢您的帮助。

最佳答案

documentation在这方面不是很好。

You can also use Git attributes to tell Git to use different merge strategies for specific files in your project.

听起来不错!我们可以阅读 merge 策略 here并且有一个叫做我们的的,它真的很有帮助。

不幸的是,下一行粉碎了这个梦想。强调我的。

One very useful option is to tell Git to not try to merge specific files when they have conflicts, but rather to use your side of the merge over someone else’s.

对我们来说很遗憾,如果对 dist/ 的更改在 feature不要与master冲突然后它们将 merge 到 dist/ 中在 master .第二个answerquestion你在上面链接讨论了这个。

我建议 post merge hook重置dist/到一些原始状态。

关于Git:在 gitattribute 中为整个文件夹指定 git merge 策略 "ours"(或者只是禁用特定文件夹的 merge 错误?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21309276/

相关文章:

ruby-on-rails - 在本地主机上设置 Rails 项目,postgresql 问题

git - 防止将某些提交/代码 merge 到 master 中

git - 如何管理与 xlsx(二进制)的 Git merge 冲突?

bash - 在 bash 命令中使用括号,git mv

git - 如何添加一个与旧的、已删除的 git 目录同名的 git 子模块?

git - 由于区分大小写,无法将文件添加到 git 中的暂存区

git - 为什么我使用GitFlow时需要将release分支 merge 到develop分支?

git - merge 时 git 按什么顺序应用文件修改?

bash - 我的 .bashrc 文件未在 Git Bash 启动时执行 (Windows 7)

git-bash - 克隆 git 仓库的 Bash 脚本