如何在git中直接合并两个更远的分支?

时间:2015-07-13 15:59:29

标签: git merge remote-branch

我试图搜索这个问题,但没有人回答我的问题。

请举个例子:
我在git服务器中得到了两个分支

<script src="LeagueNotes/js/jquery.min.js"></script>
<script src="LeagueNotes/js/champions_list.js"></script>
<script src="LeagueNotes/js/jquery.validate.min.js"></script>
<style>
    * { font-family:Arial; }
    h2 { padding:0 0 5px 5px; }
    h2 a { color: #224f99; }
    a { color:#999; text-decoration: none; }
    a:hover { color:#802727; }
    p { padding:0 0 5px 0; }

    input { padding:5px; border:1px solid #999; border-radius:4px; -moz-border-radius:4px; -web-kit-border-radius:4px; -khtml-border-radius:4px; }
</style>

<h2>
    <a href="#" id="addChampion">Add Another Champion</a>
</h2>
<form name="second_form" id="second_form" action="#" method="POST" style="margin: 0;"  >
    <div id="p_scents">
        <p>    
            <label for="p_scnts">
                <input type="text" id="champion[]" size="20" list="champions" value=""  placeholder="Enter Champion's name">
                <datalist id="champions"></datalist>
                <a href="#" id="addGeneral">Add General Change</a><a></a>
                <a href="#" id="addSpell"> Add Spell</a><a></a>

            </label>
        </p>
    </div>
    <br/><input type="submit" value="submit">
</form>
<script>
    for(var key in champions){
                if(champions.hasOwnProperty(key)){
                    $('#champions').append('<option value="' + key + '">');

                }
            }
    var config = {
                      fillAll: true
                    };

                    document.forms["second_form"].oninput = function(e) {
                      var champion = this["champion[]"];

                      //Force into array
                      if (champion[0] === undefined)
                        champion = [this["champion[]"]];

                      var reached = {
                        valid: 0,
                        unique: 0
                      };

                      var inputs = [].map.call(champion, function(n) {
                        return n.value
                      }).filter(function(n) {
                        return n.length
                      });

                      var valid = [].every.call(champion, function(n, i) {
                        n.setCustomValidity("");
                        if (config.fillAll) return (reached.valid = i, champions.hasOwnProperty(n.value));
                        else return n.value ? (
                          reached.valid = i,
                          champions.hasOwnProperty(n.value) > -1
                        ) : true;
                      });

                      var unique = inputs.slice(0).sort().every(function(n, i, a) {
                        reached.unique = inputs.lastIndexOf(n);
                        return n != a[i - 1];
                      });

                      //Check for valid champions
                      if (!valid) {
                        champion[reached.valid].setCustomValidity("This is not a valid champion, please correct this field and resubmit.")
                      }

                      //Check for duplicates
                      if (!unique) {
                        champion[reached.unique].setCustomValidity("This champion has already been entered.")
                      }

                      this.checkValidity();
                    };

    function change(x, dblchamp){
        if(dblchamp===true){
            if(x==="Passive"){x=0;}
            if(x==="Q"){x=1;}
            if(x==="Q2"){x=2;}
            if(x==="W"){x=3;}
            if(x==="W2"){x=4;}
            if(x==="E"){x=5;}
            if(x==="E2"){x=6;}
            if(x==="R"){x=7;}
            if(x==="R2"){x=8;}


        }else if(dblchamp===false){
            if(x==="Passive"){x=0;}
            if(x==="Q"){x=1;}
            if(x==="W"){x=2;}
            if(x==="E"){x=3;}
            if(x==="R"){x=4;}
        }
        console.log(x);
        return x;
    }
    function val(elm) {
        var championsWithExtraSpells = ["Aatrox", "Elise", "Fizz", "Heimerdinger", "Jayce", "Lee Sin", "Nidalee", "Rek'Sai","Twisted Fate"];
        //var championName = $("#change").closest('input').val();
        //var championName =$("#champion\\[\\]").val();
         var championName = $(elm).closest("label").find("input").val();
        //document.getElementById("champion[]").value;
        console.log(championName);

        if($.inArray(championName, championsWithExtraSpells)==-1){
            var existsInArray = false;}
        else{
            var existsInArray = true;}
         var d = $(elm).val();
        var spellname = document.getElementById("championSpell[]");
        var z = champions[""+championName+""][change(d, existsInArray)];
        test =  $(elm).nextAll("input").first().val('test'); 
        test.value=champions[""+championName+""][change(d, existsInArray)];

    }

    $(function() {
        var scntDiv = $('#p_scents');
        var i = $('#p_scents label').size() + 1;
        var j =0;
        $('body').on('click', '#addChampion', function() {
            $('<p><a href="#" id="remScnt">Remove</a><br><label for="p_scnts"><input type="text" id="champion[]" size="20" list="champions" name="champion[]" value="" placeholder="Enter Champion\'s name" /><datalist id="champions"></datalist><a href="#" id="addGeneral">Add General Change</a><a href="#" id="addSpell"> Add Spell</a><a></a></label></p>').appendTo(scntDiv);
                i++;
                return false;
        });

        $('body').on('click', '#remScnt', function() { 
                if( i >2 ) {
                        $(this).parents('p').remove();
                        i--;
                }
                return false;
        });

         $('body').on('click', '#addGeneral',function() { 
               $(
               '<p><label for="var"><textarea type="text" id="champion[]" size="20" name="GeneralChange[]" value="" placeholder="Enter Description" /><select><option value="buff">Buff</option><option value="nerf">Nerf</option><option value="new">New</option><option value="change">Change</option><option value="bugfix">Bugfix</option></select></label> <a href="#" id="remVar">Remove Change</a></p>').appendTo($(this).next()); 
                j++;
                return false;
        });


        $('body').on('click', '#remVar',function() { 
                        $(this).parent('p').remove();
                return false;
        });

        $('body').on('click', '#addSpell',function() { 
               $(
               '<p><select name="change[]" id="change[]" onchange="val(this)"><option value="Passive">Passive</option><option value="Q" selected>Q</option><option value="W">W</option><option value="E">E</option><option value="R">R</option></select><label for="var"><input type="text" id="championSpell[]" readOnly="true"><br><textarea type="text" id="p_scnt" size="20" name="p_scnt_' + i +'" value="" placeholder="Enter Description" /><select><option value="buff">Buff</option><option value="nerf">Nerf</option><option value="new">New</option><option value="change">Change</option><option value="bugfix">Bugfix</option></select></label> <a href="#" id="addGeneral">Add Change</a> <a href="#" id="remVar">Remove Spell</a></p>').appendTo($(this).next());
                return false;
        });
});
</script>

分支&#39;功能&#39;从主人那里扩展出来,因为其他人都在做主人,我不想影响他们,所以我扩展了#39;功能&#39; ;在我的本地并将其推到远程。

由于两天后每个人都提交了提交,我想在我的功能上提取最少的代码&#39;有没有办法可以合并代码来自&origin; /来自&#39;到&#39;原点/功能&#39;,然后只需提取原始/功能&#39;。

我试过

origin/master
origin/feature

但是,在我git checkout origin/feature git merge origin/master git status # you would see that this is the lease code with lots of commits git checkout feature git pull 之后,我什么也没得到,即使那些最少的提交都丢失了。

所以我意识到本地的git pull只是遥控器中origin/feature的图像。这就是为什么我的方式不起作用。

满足我要求的另一种方式是

origin/feature

这就是我现在使用的方式。

我想知道有没有一种方法可以直接合并这两个远程分支而无需推送任何东西?

1 个答案:

答案 0 :(得分:1)

#fetch latest changes in origin
git fetch origin

git checkout feature

#to sync feature with what you have now
git push origin feature

#merge locally, while you sit on feature
git merge origin/master
#now push the merge to the origin
git push origin feature