git-流程完成发布-选择性合并

git-flow finish release - selective merge

我们公司最近开始使用 git-flow,但遇到了以下问题:

我们有一个 DEV_MODE 布尔值来控制应用程序中的日志记录级别,我们希望开发分支始终具有 DEV_MODE=true.
但是,在发布版本时,我们将 DEV_MODE 更改为 false

当我在 git-flow 完成发布时,它会将 DEV_MODE=false 合并到开发分支中。

我有一个钩子可以用来防止这种情况发生,或者可能有一种方法可以告诉 git 如何从发布分支合并文件以进行开发?

您可以通过对文件 "template" 进行版本控制来完全避免合并问题,其中包含一个占位符值:

DEV_MODE=@devmode@

然后您可以声明一个 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

(图片显示在“Customizing Git - Git Attributes", from "Pro Git book”)

smudge 脚本可以使用它来检测当前分支:

#!/bin/sh
branch=$(git rev-parse --symbolic --abbrev-ref HEAD)