5

Git:在 merge 的时候忽略特定的文件

 2 years ago
source link: https://hiberabyss.github.io/2018/03/03/git-ignore-specific-file/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Git:在 merge 的时候忽略特定的文件

Mar 3, 2018 | Git | 阅读 | 236 字 | 1 分钟
0 条评论

有时当我们 merge 别的分支到当前分支时, 希望当前分支的某个文件能保持不变. 例如在更新 Hexo 主题时保证 _config.yml 文件不变, 以减少合并冲突的产生. 本文会介绍如何通过 gitattributes 来实现这个目标.

首先需要添加一个 merge driver:

git config --global merge.ours.driver true

然后在项目的根目录下添加一个文件 .gitattributes , 在文件里添加需要被忽略的文件:

_config.yml merge=ours

.gitattributes 里可以设置文件的 merge driver, 我们先是添加了一个名叫 ours 的 merge driver, 这个 driver 被设定为 true , 也就是使用这个 merge driver 的文件在 merge 的时候什么都不会做, 也就会保持不变.

References

来发评论吧~
Powered By Valine
v1.4.18

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK