问题
We've recently started using git-flow
in our company, and we've came across the following issue:
We have a DEV_MODE
boolean that controls the level of logging in the app, we want the develop branch to always have DEV_MODE=true
.
However, when releasing a version we change the DEV_MODE
to false
.
When I do finish-release in git-flow
, it'll merge the DEV_MODE=false
into the develop branch.
I there a hook I can use to prevent this, or maybe a way to tell git how to merge files from release branches to develop?
回答1:
You can avoid the merge issue entirely by versionning a file "template", with a placeholder value in it:
DEV_MODE=@devmode@
You can then declare a content filter driver (in a .gitattributes file) in order to automatically generate the right content for that file on checkout, depending on the branch currently checked out.

(image shown in "Customizing Git - Git Attributes", from "Pro Git book")
The smudge
script can use this to detect the current branch:
#!/bin/sh
branch=$(git rev-parse --symbolic --abbrev-ref HEAD)
来源:https://stackoverflow.com/questions/28739242/git-flow-finish-release-selective-merge