git合并时忽略某个文件

因为开发现场跟部署的环境不同,有很多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

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


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

原文地址:https://www.cnblogs.com/lxlin/p/10843583.html