因为开发现场跟部署的环境不同,有很多ip地址每次都要改来改去;于是开两个分支master(用来保存部署现场的ip)和dev(开发环境的ip),开发功能时在dev分支,然后使用master合并,每个分支都保存着自己的config配置文件,不想dev分支被master合并时config文件也合并.

  1. 创建自定义merge driver
git config --global merge.ours.driver true 
  1. 在要被merge的分支上创建.gitattributes文件,并且在文件中置顶不merge的文件名
echo 'config.js merge=ours' >> .gitattributes git add .gitattributes git commit -m 'chore: Preserve config.js during merges' //只是为了commit代码,可以 
  1. 回到要合并到的分支master,执行merge:

git merge dev

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

dev分支上的config.js就不会被合并了;


原文链接:https://www.jianshu.com/p/09b546b936a7

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄