将 master 合并到每个主机自定义分支时避免合并冲突
Avoiding merge conflicts when merging master into per-host customized branch
我想将我所有的点文件存储在 git
具有单独分支的存储库中
对于每台机器。我有一个我无法解决的问题阻碍了我
为此目的使用 git
。我想知道其他人如何
解决了。
我将有一个 master
分支,它只包含
模板定义和应该通用的定义
对于所有分支,例如:
export EMAIL="@EMAIL@"
export SURFRAW_google_results=1000
我将在机器分支上用我正确的电子邮件替换 @EMAIL@
并提交它,但 SURFRAW_google_results
将保持不变。为了
例如,在 work
分支上我将有这个:
export EMAIL="user@corp.com"
export SURFRAW_google_results=1000
现在,我决定将 SURFRAW_google_results=1000
改为 10。
应该在全球共享,所以我首先在 master
:
上更改它
export EMAIL="@EMAIL@"
export SURFRAW_google_results=10
然后我将 work
变基到 master
:
$ git checkout work
$ git rebase master
现在我遇到了冲突,因为我在上面的那条线
改变是不同的:
<<<<<<< a60114eea1c98d2354a07bd4fd0cdd63cba62e93
export EMAIL="@EMAIL@"
export SURFRAW_google_results=10
=======
export EMAIL="user@corp.com"
export SURFRAW_google_results=1000
>>>>>>> m
在 bash
的情况下,我可以很快逃脱
通过采购机制包括机器特定的部分,但是怎么样
不支持 including/sourcing 其他配置的配置,例如 .fluxbox/keys
或 .screenrc
?
而不是直接在分支之间修改并发数据(导致冲突), you can considering content filter driver, using .gitattributes declaration。
(图片来自“Customizing Git - Git Attributes", from "Pro Git book”)
想法是在版本中管理这些点文件,但是用模板占位符代替实际值(取决于分支)。
生成的实际点文件仍然被忽略(.gitignore
)。
这意味着您的实际工作树没有得到 "dirty".
具有实际值的文件也可以进行版本控制,但名称不同(因此 merging/rebasing 时不会发生冲突)
涂抹脚本 select 根据分支名称的正确值文件,并根据在 git checkout
期间应用涂抹脚本的点文件模板生成正确的点文件。
要使每个分支的污迹效果不同,我建议调用一个脚本,该脚本首先查看当前分支的名称。
请参阅我的旧答案“Best practice - Git + Build automation - Keeping configs separate”中的示例。
#!/bin/sh
branch=$(git rev-parse --symbolic --abbrev-ref HEAD)
OP mentions that, for the smudge script to apply on checkout, removing the index is needed. That is true, as I explained here:
the index is the middle-man for moving things from your work-tree to the object-store AND for moving things from the object-store to your work-tree.
通过删除索引,您强制 git 恢复它,这意味着应用任何内容过滤器驱动程序(如果存在)。
参见“git: re-checkout files after creating smudge filter”。
我想将我所有的点文件存储在 git
具有单独分支的存储库中
对于每台机器。我有一个我无法解决的问题阻碍了我
为此目的使用 git
。我想知道其他人如何
解决了。
我将有一个 master
分支,它只包含
模板定义和应该通用的定义
对于所有分支,例如:
export EMAIL="@EMAIL@"
export SURFRAW_google_results=1000
我将在机器分支上用我正确的电子邮件替换 @EMAIL@
并提交它,但 SURFRAW_google_results
将保持不变。为了
例如,在 work
分支上我将有这个:
export EMAIL="user@corp.com"
export SURFRAW_google_results=1000
现在,我决定将 SURFRAW_google_results=1000
改为 10。
应该在全球共享,所以我首先在 master
:
export EMAIL="@EMAIL@"
export SURFRAW_google_results=10
然后我将 work
变基到 master
:
$ git checkout work
$ git rebase master
现在我遇到了冲突,因为我在上面的那条线 改变是不同的:
<<<<<<< a60114eea1c98d2354a07bd4fd0cdd63cba62e93
export EMAIL="@EMAIL@"
export SURFRAW_google_results=10
=======
export EMAIL="user@corp.com"
export SURFRAW_google_results=1000
>>>>>>> m
在 bash
的情况下,我可以很快逃脱
通过采购机制包括机器特定的部分,但是怎么样
不支持 including/sourcing 其他配置的配置,例如 .fluxbox/keys
或 .screenrc
?
而不是直接在分支之间修改并发数据(导致冲突
想法是在版本中管理这些点文件,但是用模板占位符代替实际值(取决于分支)。
生成的实际点文件仍然被忽略(.gitignore
)。
这意味着您的实际工作树没有得到 "dirty".
具有实际值的文件也可以进行版本控制,但名称不同(因此 merging/rebasing 时不会发生冲突)
涂抹脚本 select 根据分支名称的正确值文件,并根据在 git checkout
期间应用涂抹脚本的点文件模板生成正确的点文件。
要使每个分支的污迹效果不同,我建议调用一个脚本,该脚本首先查看当前分支的名称。
请参阅我的旧答案“Best practice - Git + Build automation - Keeping configs separate”中的示例。
#!/bin/sh
branch=$(git rev-parse --symbolic --abbrev-ref HEAD)
OP mentions that, for the smudge script to apply on checkout, removing the index is needed. That is true, as I explained here:
the index is the middle-man for moving things from your work-tree to the object-store AND for moving things from the object-store to your work-tree.
通过删除索引,您强制 git 恢复它,这意味着应用任何内容过滤器驱动程序(如果存在)。
参见“git: re-checkout files after creating smudge filter”。