Git合并已修改相同文件的不同功能

时间:2019-06-28 03:22:10

标签: git gitlab git-merge git-merge-conflict

我目前正在使用git流上的功能分支进行测试。 假设我有一个当前稳定的脚本。

开发人员分支上狗的当前稳定版本

    file 1
    ---------
    function bark() {
        return 'the dog is barking';
    }

    function walk() {
        return 'the dog is walking'
    }


    file 2
    ---------
    Action

    <button type="submit" name="button1">Play</button>

    <button type="submit" name="button2">Play</button>

    if($_POST["button1"]) {
        bark();
    }

    if($_POST["button2"]) {
        walk();
    }

然后,要求彼得添加与cat相同的新功能current stable version for dog。因此,Peter对新功能分支current stable version进行了features/cat的克隆。彼得将修改所有current stable version代码。

Peter将当前稳定版本克隆到Features / cat,并且已经修改了当前稳定版本

    file 1
    -----------------------------
    function animalSound($animals = []) {
        $result = [];
        foreach($animals as $animal) {
            if($animal == 'cat') {
                $sound = 'meowing';
            } else if($animal == 'dog') {
                $sound = 'barking';
            }

            $result[] = 'The ' . $animal . ' is ' . $sound. 
        }

        return $result;
    }

    function animalWalk($animals = []) {
        $result = [];

        foreach($animals as $animal) {
            $result[] = 'The ' . $animal . ' is walking';
        }
    }


    file 2
    ---------
    Action

    <button type="submit" name="button1">Play</button>

    <button type="submit" name="button2">Play</button>

    if($_POST["button1"]) {
        bark(['dog', 'cat']);
    }

    if($_POST["button2"]) {
        walk(['dog', 'cat']);
    }

我们假设Peter尚未完全构建脚本,现在我要求Susan为狗的run构建current stable version功能。 然后Susan将current stable version克隆到名为features/dogrun的新功能分支中

苏珊:功能/运行方式

    file 1
    ----------------
    function bark() {
        return 'the dog is barking';
    }

    function walk() {
        return 'the dog is walking'
    }

    // add run feature
    function run() {
        return 'the dog is running';
    }

    file 2
    ---------
    Action

    <button type="submit" name="button1">Play</button>

    <button type="submit" name="button2">Play</button>

    // menambah fitur run
    <button type="submit" name="button3">Play</button>

    if($_POST["button1"]) {
        bark();
    }

    if($_POST["button2"]) {
        walk();
    }

    // add run feature
    if($_POST["button3"]) {
        run();
    }

让我们说Susan已经完成了run feature的构建,并且该功能已经投入生产。 现在Peter: features/cat已经在暂存分支中,可以开始生产了。如何合并Peter: features/catSusan: features/run?在功能之间,所有代码都已更改,无法合并。如果Peter: features/cat首先合并到主分支(生产),则Susan: features/run将不再起作用。

此示例案例只是简单的脚本,因为在我的真实案例中,很多相同的文件会被另一个文件修改,并且代码会更复杂。

1 个答案:

答案 0 :(得分:1)

如果分支涉及冲突,则不应合并。

Peter准备就绪后,应在最新的master生产分支上重置他的功能/猫,以便在他的工作站上本地重播他的features/cat提交。

在那里(在彼得的环境中)会发生冲突,并在那里解决(由彼得解决)

随后对master的合并将是微不足道的。

相关问题