开发者

Git : not ignored file in two branch needs to be different

I want to ask about what your approach looks like handling a situation like this: I have this setting file mongoid.yml, and I have two branches of the same 开发者_Go百科project : master and dev. I haven't put mongoid.yml into gitignore because I need it to be in the commit when I push both branches. But whenever I edit it in either branch, for example, if I edited it in the dev branch, it shows up in git status, when I commit then merge dev to master, the master branch's mongoid is now looking like the one in dev. I need them to be different. How would you approach this? thanks!


You want to make a dev branch and then check it out. Change the config file to what you need it to be. Switch back to the other branch.

git merge -s ours dev

This will ignore what you did in the dev branch, but still mark in the history as if those changes were already merged. From now on, when you merge to and from the dev branch, your config will stay as what you need it to be. This is the proper way to set up a development branch.

Hope this helps.


You can use a different merge strategy on your file to prevent the merge.

Create a .gitattributes file with:

mongoid.yml merge=ours

Then when this file conflicts during a merge, the old one will be kept.

More infos here and here.


You could keep your changes to the file in a separate commit always on top of master, and merge its parent.

For example:

  • you work on dev,
  • if you ever have to change mongoid.yml, you make commits with only this file changed,
  • before you switch to master, you git rebase -i master and move your mongoid.yml commits to the bottom (and squash them all with the first one if there's more than one),
  • then you switch to master and merge the parent of dev: git merge dev^

It's a little work on each merge and you loose the history of you changes on mongoid.yml in the dev branch, but it should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜