How to ignore files in Git merge?

2020-05-24 04:55发布

I'm working on a (Django) website with two branches: master and dev.

master is the production version and no work should be done here directly. All the changes should come from merging dev branch, once it is considered to be stable.

dev, as you may guess, is the development branch and all the changes are made here (and subbranches).

In the server I have two websites working, the production one (uses master branch) and another private for development, with dev subdomain that uses dev branch.

The problem is that all the configuration files, static files (images, etc.) are inside the control version to be able to easily push them to the server. But, if these kind of files (static, config...) are modified in dev to just debug in the server and then I need to merge with master... How can I set some files and dirs to be ignored when merging dev into master?

I've been searching and I've found some related questions, but they tell you to use .gitattributes with merge=ours. However, this approach has a big caveat: it only applies the strategy if the file is modified in the two branches, but this isn't my case.

Any tips on how should I go on?

3条回答
狗以群分
2楼-- · 2020-05-24 05:06

It's been a long time. But I'm searching for a same solution. Out of nowhere, it just pops in my head: use a sub module for configurations. With a sub module, you can have multiple branches for different configurations.

Use symbolic links to link files from the sub module (in a sub directory).

查看更多
爷、活的狠高调
3楼-- · 2020-05-24 05:15

To be honest, git sounds like the wrong place to be solving this problem.

Django offers facilities for having separate settings/configuration for production and development environments. I suggest you take a look at this post: Django: How to manage development and production settings?

If you follow the advice in the post above, you can muck with the configuration, etc. for your dev environment and then merging to master will be harmless as production will have its own configuration.

查看更多
Emotional °昔
4楼-- · 2020-05-24 05:24

git checkout master

git merge --no-log --no-ff --no-commit dev

git checkout master <files-you-don't-want-to-merge>


git add <files-you-don't-want-to-merge>

git commit -a

~~~ Test / Build ~~~

git push origin master 


查看更多
登录 后发表回答