让Git在分支之间保留不同的部分内容 [英] Making Git retain different section content between branches

查看:203
本文介绍了让Git在分支之间保留不同的部分内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



现在,我有一个稳定的文件和一个测试版文件,以便组织中的每个人都可以安装稳定的代码,但是如果愿意,可以选择帮助测试beta版本。该文件的某些部分应该保持不同,内容和更改不应该在分支之间合并。

例如,如果我将Beta文件转换为Git分支,并且后来决定Beta更改是稳定的,并将Beta重新合并到Stable代码(这不会改变)Git Merge过程,因为我知道它会根据这些行上的值帮助更新Stable Greasemonkey定义头在Beta分支中。这是完全不可取的,因为这些头文件包含Greasemonkey将检查更新的自动更新URL。

  // == UserScript ==(稳定)
// @downloadURL - StableURL文件位置
// == / UserScript ==

// == UserScript ==(beta)
// @downloadURL - BetaURL文件位置
// == / UserScript ==

> Git合并<

// == UserScript ==(稳定)
// @downloadURL - BetaURL文件位置
// == / UserScript ==

我想保留在Beta代码和Stable代码之间具有不同URL的能力,但一直未能识别方法为了让Git的合并过程忽略Greasemonkey需要正确执行的操作,但是如果我没有将Beta作为单独的分支,我不确定如何使用Git轻松地将已更改的代码从Beta迁移到Stable,这是要求我采用Git功能的原因。 (好吧,另一个原因是为了让其他人更容易参与和识别项目的历史......)

非常感谢任何帮助。

除了对这些值的更改外,所有更改都应该合并,这使得它们与其他值不同,不会对内部内容进行更改,但会对其进行部署 - 具体的变化。这些可能最适用于结账后的挂钩。下面是一个示例,每个分支包括处理器

  cat<< \ EOF> .git / hooks / post -checkout 
#!/ bin / sh
如果分支=`git symbolic-ref HEAD --short -q`;然后在$ g $ ls-files -cix *。@ branch`中为
作为文件;
echo $ / $ @包含分支特定([az /] *)$ / {
echo $ * $ {file%。@ branch} s // cat \1。'$ branch'/ e}'\
| sed -rf- $ file> $ {file%。@ branch}
完成
fi
EOF
chmod + x .git / hooks / post-checkout





 #testing 
git checkout beta
$ b $ cat<< \ EOF> config。@ branch
// == UserScript ==
@ include-branch-specific config
/ / == / UserScript ==
EOF

echo> config.stable'// @downloadURL - StableURL File Location'
echo> config.beta'// @downloadURL - BetaURL文件位置'

git add config。*
#git rm --cached config
git commit -m'setting per-branch configs'
git checkout

git checkout stable
git cherry-pick beta
git checkout


I'm developing a Userscript that my employers have asked me to begin to manage via Git.

Right now, I have a stable file and a beta file, so that everyone in the organization can install the stable code but can choose to help test the beta additions instead, if they want. Some portions of that file should remain different, the content and changes should not be merged between branches.

For example, if I convert the Beta file to a Git Branch, and later decide that the Beta changes are stable and merge the Beta back into the Stable code (which will not have changed) the Git Merge process as I understand it will "helpfully" update the Stable Greasemonkey definition headers based on whatever values are on those lines in the Beta branch. This is thoroughly undesirable, as these headers contain an auto-update URL that Greasemonkey will check for updates.

// ==UserScript== (stable)
// @downloadURL  --  StableURL File Location
// ==/UserScript==

// ==UserScript== (beta)
// @downloadURL  --  BetaURL File Location
// ==/UserScript==

>Git Merge<

// ==UserScript== (stable)
// @downloadURL  --  BetaURL File Location
// ==/UserScript==

I want to retain the ability to have distinct URLs between the Beta code and the Stable code, but have not been able to identify a method to make Git's merge process ignore the lines that Greasemonkey needs to do its thing properly, but if I don't have the Beta as a separate Branch, I'm not sure how to use Git to easily migrate changed code from Beta to Stable, which is the stated reason for asking me to adopt Git functionality. (Well, the other reason is to make it easier for others to contribute to and identify the history of the project...)

Any help is much appreciated.

解决方案

All your changes should be merged except changes to those values, which makes them not like the others, not changes to intrinsic content but deployment-specific changes. Those might be best applied in the post-checkout hook. Here's a sample, a per-branch include processor

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在分支之间保留不同的部分内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆