dsxz84851 2014-03-14 12:24 采纳率: 100%
浏览 1341

如何从git merge中排除特定的提交(永远)

I'm developing some web application (php, codeigniter). Today a time to push it to github has come, but I've encountered an issue I can't manage.

I've got 2 branches:

  • master - this branch should be used for github pushing, does not contain credentials or any other sensitive data (just public code)
  • dev - this is master's child, used for development, does contain credentials (of my private app instantion)

By credentials I mean: database login, password, host, user; oauth services id / secrets; encryption_key. Credentials are stored in 2 separated files within /application/config folder.

The idea is that I'll make all changes on dev, than merge dev into master, and pull master content to github (but master can't contain my private credentials).

This is what I've done till now:

  1. Removed all credentials from /application/config/config.php and /applications/config/database.php (as I don't want them to be public on github) they've become an empty strings like: $db['default']['hostname'] = '';
  2. Started git repository and made an initial commit - the default branch that was created is named 'master'
  3. Pulled master into github

And it's pretty cool till now - I've got my project code on github with no credentials within. Next I need to make some changes in my project, so I:

  1. Created new branch 'dev'
  2. Stored my credentials into dev, and make a commit - I need dev instantion to have credentials as I'm uploading this to ftp server every time I change something in the code (I don't use local LAMP or anything like this in this project)

So now I need to make some change in dev, upload it and pull to github so I:

  1. Make an change on dev (let's say add new feature)
  2. Checkout to master
  3. Merge dev into master.

What I expected to happen: Git will ask me which version of configs should be used in 'master' as it is different in both branches. I will use diff to chose a 'master' verion of files (which does not contain credentials). Git will remember my choice, and in the future I will not have to chose again when I'll merge dev into master. Git works like this on one of my other projects, where dev is a master branch and instantions are it's children (In this case dev is a child and I merge child into parent).

What happened: Git just copied credentials from dev to master, did not ask me about that. So now my master branch is 'tainted' by credentials and I can't push it to github anymore.

My questions are:

  1. Why is that happening, how can I avoid this?
  2. Is there any other (better?) way to handle that kind of issue.

Please let me know if anything is unclear, any help will be appreciated.

  • 写回答

3条回答 默认 最新

  • doudui5753 2014-03-14 12:32
    关注

    Git will only flag a conflict if files in your master branch were changed after your original branch to dev, then the same files were changed in dev.

    I suggest you add a .gitignore entry for your credentials, or separate them using an ENVIRONMENT variable, in codeigniter this is very easy, all you have to do is on your apache config (vhost if your using them) is add SetEnv APPLICATION_ENV development then you can add a folder inside application/configs called development, now when you are running in development environment, these configs will take precedence over the ones in the base config directory.

    This isn't so much about gitignoring files, or removing commits, but a good file structure, and environment setup to differentiate between the separate environments, you an use development, staging, and production (which is the default)

    otherwise add a .gitignore row to tell git to ignore those certain files.

    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料