如何维护(大部分)并行分支只有一些差异 [英] How to maintain (mostly) parallel branches with only a few difference

查看:118
本文介绍了如何维护(大部分)并行分支只有一些差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:我试图让我的unix dot-files在git下。我必须在(至少)cygwin环境和一些标准的linux发行版(ubuntu和opensuse)之间工作,并且我拥有仅针对cygwin的代码文件/行。由于我不想检出无用的文件,或者不得不处理大量的dotfiles内部情况,因此我正在为每个环境创建分支。但是我所做的大部分编辑对于所有环境都很常见,所以几乎每次我做出提交时,都需要将更改传播到所有分支。



所以基本上我有几个分支除了少数几次提交之外几乎完全相同,而且我确实需要在所有分支中提交大部分提交。



问题:如果有的话,推荐的git工作流程是什么?或者有没有更好的设置(不使用多个分支?)为我的情况?



[我尝试樱桃采摘,但涉及相当多的工作,而不是在这里提到所有重复的提交和让我的分支保持同步的噩梦。]

解决方案

,在一个分支中有许多常见文件正在发展,并且每个环境只有几个特定的​​配置文件......我们不会将配置文件存储在Git中。完全可以。

我们将所有配置文件的模板存储在所有特定的每个环境值中,另外还有一个脚本可以替换模板文件中的变量由正确的值(检测当前平台)

这样,我们不需要为这些文件创建分支。






管理这些类型文件的另一个好方法是使用 git属性过滤器驱动程序 (另见 Pro Git book )。


过滤器驱动程序包含一个 clean 命令和一个 smudge 命令,其中任何一个都可以不指定。

结帐时,当指定 smudge 命令时,该命令被送入blob对象来自其标准输入,其标准输出用于更新工作树文件。

同样, clean 命令用于转换

这样,由smudge引用的脚本(由Git管理)可以将所有变量替换为特定于平台的值,而干净的脚本会将其内容恢复到未触及的配置文件。



主要想法依然是:避免创建分支只适用于那种平行演变。

Scenario: I'm trying to get my unix dot-files under git. I have to work between (at least) the cygwin environment and some standard linux distros (ubuntu and opensuse), and I have files/lines of code that are only specific to, say, cygwin. Since I don't want to checkout useless files or have to deal with lots of cases inside my dotfiles, I'm creating branches for each of my environments. But most of the edits I do are common to all environments, so almost every time I made a commit I need to propagate that change to all my branches.

So basically I have several branches that are almost identical except for a few commits, and most commits I do need to be in all branches.

The question: what is the recommended git workflow for this, if there is any? Or is there a better setup (without using multiple branches?) for my scenario?

[I tried cherry-picking, but that involves quite a bit of work, and not to mention all the duplicate commits out here and the nightmare it is to keep my branches in sync.]

解决方案

For that particular case, where there is a lot of common files evolving in one branch, and only a few config files specific per environment... we do not store the config file in Git. At all.

We do store template of said config files, plus all the specific per-environment values, plus a script able to replace the variables in the template files by the correct value (detecting the current platform)

That way, we do not need to make a branch only for those files.


Another good way to manage those kind of files (with a platform-specifc content) is through a git attribute filter driver (see also Pro Git book).

A filter driver consists of a clean command and a smudge command, either of which can be left unspecified.
Upon checkout, when the smudge command is specified, the command is fed the blob object from its standard input, and its standard output is used to update the worktree file.
Similarly, the clean command is used to convert the contents of worktree file upon check-in.

That way, a script (managed with Git) referenced by the smudge can replace all the variables by platform-specific values, while the clean script will restore its content to an untouched config file.

The main idea remains: avoid creating branches only for that kind of parallel evolution.

这篇关于如何维护(大部分)并行分支只有一些差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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