Git: merging public and private branches while while keeping certain files intact in both branches

醉酒当歌 提交于 2019-11-27 07:17:24
VonC

To be on the safe side, you can add a git attribute (see here for an example) for those private files.

That way, you can define a script (a "merge manager") which will ensure the file including private informations will remain empty (or with a public content) if merged on the public branch, while keeping its local content if merged to the private branch.
It means you can merge/rebase without thinking about that file.

One way to do this is with git rebase. By keeping your private changes as a few commits off the end of your master, you can commit public stuff to the master branch (or whatever you choose your working branch to be), and then rebase your private branch against master whenever you want to update.

Another way to handle this is to keep template configuration files in Git, such as frobozz.config.template. In your working directory, copy frobozz.config.template to the (unversioned) frobozz.config and modify. Just be sure to back up your working directory too, if you need your local changes to be backed up.

This only appears to work if there are merge conflicts detected. Merging back and forth between branches the file does get overwritten. Unless I set something up wrong. Of course this in on windows msysgit git version 1.6.5.1.1367.

Keep passwords under version control is the worst idea ever. You need CVS, not git, to work with separate files. Git as many other modern DVCS working with the entire tree, not with separate files.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!