我正在开发一个用户脚本,我的雇主要求我开始通过 Git 进行管理。
现在,我有一个稳定文件和一个 beta 文件,这样组织中的每个人都可以安装稳定代码,但如果他们愿意,也可以选择帮助测试 beta 添加。该文件的某些部分应该保持不同,内容和更改不应在分支之间 merge 。
例如,如果我将 Beta 文件转换为 Git 分支,然后确定 Beta 更改是稳定的并将 Beta merge 回稳定代码(不会更改)我理解的 Git Merge 过程将根据 Beta 分支中那些行上的任何值“有帮助地”更新稳定的 Greasemonkey 定义 header 。这是完全不可取的,因为这些 header 包含 Greasemonkey 将检查更新的自动更新 URL。
// ==UserScript== (stable)
// @downloadURL -- StableURL File Location
// ==/UserScript==
// ==UserScript== (beta)
// @downloadURL -- BetaURL File Location
// ==/UserScript==
>Git Merge<
// ==UserScript== (stable)
// @downloadURL -- BetaURL File Location
// ==/UserScript==
我想保留在 Beta 代码和稳定代码之间使用不同 URL 的能力,但无法确定一种方法来使 Git 的 merge 过程忽略 Greasemonkey 正确执行其操作所需的行,但是如果我没有将 Beta 作为单独的分支,我不确定如何使用 Git 轻松地将更改后的代码从 Beta 迁移到 Stable,这就是要求我采用 Git 功能的既定原因。 (好吧,另一个原因是为了让其他人更容易贡献和识别项目的历史......)
非常感谢任何帮助。
最佳答案
除了对这些值的更改外,您的所有更改都应该 merge ,这使得它们不像其他更改,不是对内在内容的更改,而是特定于部署的更改。这些可能最好应用于 checkout 后 Hook 。这是一个示例,每个分支包含处理器
cat <<\EOF >.git/hooks/post-checkout
#!/bin/sh
if branch=`git symbolic-ref HEAD --short -q`; then
for file in `git ls-files -cix*.@branch`; do
echo "* making ${file%.@branch} from $file with branch-specific includes"
echo '/^@include-branch-specific ([a-z/]*)$/ { s//cat \1.'$branch'/e }' \
| sed -rf- $file >${file%.@branch}
done
fi
EOF
chmod +x .git/hooks/post-checkout
# testing
git checkout beta
cat <<\EOF >config.@branch
// ==UserScript==
@include-branch-specific config
// ==/UserScript==
EOF
echo >config.stable '// @downloadURL -- StableURL File Location'
echo >config.beta '// @downloadURL -- BetaURL File Location'
git add config.*
# git rm --cached config
git commit -m'setting up per-branch configs'
git checkout
git checkout stable
git cherry-pick beta
git checkout
关于git - 让Git在分支之间保留不同的section内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20078756/