将一个本地分支替换为另一个本地分支...并保留跟踪

时间:2015-07-21 17:48:16

标签: git git-branch branching-and-merging git-remote

我有2个跟踪不同存储库的本地分支:

  • local-live(跟踪我们的实时回购)
  • local-staging(跟踪暂存仓库)

我们已经设置了“持续部署”,因此当我推送我的本地升级登台环境时,将更新更新。我希望分段能够反映现场的代码(当前情况并非如此)。

如何使用“local-live”分支中的代码替换“local-staging”分支?我想擦除所有分段更改,使分段反映现场的内容。我希望我的本地分段仍然可以跟踪分段回购(即分段中的“git push”将按预期运行)

希望这很清楚。感谢。

2 个答案:

答案 0 :(得分:2)

好像你想把你的实时分支合并到你的临时分支。

以下是详细指南:

http://www.git-tower.com/learn/git/ebook/command-line/branching-merging/merging

基本上你必须这样做:

$ git checkout local-staging
$ git merge local-live

<小时/> 现在,如果您想将实时分支的更改放在分段分支之上,则应使用rebase。 并做一些事情:

$ git checkout local-live
$ git rebase local-staging
$ git checkout local-staging
$ git merge local-live

检查一下:

https://git-scm.com/book/en/v2/Git-Branching-Rebasing

<小时/> 现在,如果你不想合并分支,你应该做一个破坏性的操作:O

你可以进行&#34;硬重置&#34;和#34;强制推动&#34;。

$ git checkout local-staging
$ git reset --hard <desired commit of local-live>
$ git push --force origin local-staging

更多信息:

https://es.atlassian.com/git/tutorials/undoing-changes/git-reset

答案 1 :(得分:2)

你想进行硬重置。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Filterable inside custom select - jQuery Mobile Demos</title>
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,700">
<link rel="stylesheet" href="jquery.mobile/css/themes/default/jquery.mobile-1.4.5.min.css">
<link rel="stylesheet" href="jquery.mobile/_assets/css/jqm-demos.css">
<script src="jquery.mobile/js/jquery.js"></script>
<script src="jquery.mobile/_assets/js/index.js"></script>
<script src="jquery.mobile/js/jquery.mobile-1.4.5.min.js"></script>

<script>
( function( $ ) {
function pageIsSelectmenuDialog( page ) {
    var isDialog = false,
        id = page && page.attr( "id" );
    $( ".filterable-select" ).each( function() {
        if ( $( this ).attr( "id" ) + "-dialog" === id ) {
            isDialog = true;
            return false;
        }
    });
    return isDialog;
}
$.mobile.document
    // Upon creation of the select menu, we want to make use of the fact that the ID of the
    // listview it generates starts with the ID of the select menu itself, plus the suffix "-menu".
    // We retrieve the listview and insert a search input before it.
    .on( "selectmenucreate", ".filterable-select", function( event ) {
        var input,
            selectmenu = $( event.target ),
            list = $( "#" + selectmenu.attr( "id" ) + "-menu" ),
            form = list.jqmData( "filter-form" );
        // We store the generated form in a variable attached to the popup so we avoid creating a
        // second form/input field when the listview is destroyed/rebuilt during a refresh.
        if ( !form ) {
            input = $( "<input data-type='search'></input>" );
            form = $( "<form></form>" ).append( input );
            input.textinput();
            list
                .before( form )
                .jqmData( "filter-form", form ) ;
            form.jqmData( "listview", list );
        }
        // Instantiate a filterable widget on the newly created selectmenu widget and indicate that
        // the generated input form element is to be used for the filtering.
        selectmenu
            .filterable({
                input: input,
                children: "> option[value]"
            })
            // Rebuild the custom select menu's list items to reflect the results of the filtering
            // done on the select menu.
            .on( "filterablefilter", function() {
                selectmenu.selectmenu( "refresh" );
            });
    })
    // The custom select list may show up as either a popup or a dialog, depending on how much
    // vertical room there is on the screen. If it shows up as a dialog, then the form containing
    // the filter input field must be transferred to the dialog so that the user can continue to
    // use it for filtering list items.
    .on( "pagecontainerbeforeshow", function( event, data ) {
        var listview, form;
        // We only handle the appearance of a dialog generated by a filterable selectmenu
        if ( !pageIsSelectmenuDialog( data.toPage ) ) {
            return;
        }
        listview = data.toPage.find( "ul" );
        form = listview.jqmData( "filter-form" );
        // Attach a reference to the listview as a data item to the dialog, because during the
        // pagecontainerhide handler below the selectmenu widget will already have returned the
        // listview to the popup, so we won't be able to find it inside the dialog with a selector.
        data.toPage.jqmData( "listview", listview );
        // Place the form before the listview in the dialog.
        listview.before( form );
    })
    // After the dialog is closed, the form containing the filter input is returned to the popup.
    .on( "pagecontainerhide", function( event, data ) {
        var listview, form;
        // We only handle the disappearance of a dialog generated by a filterable selectmenu
        if ( !pageIsSelectmenuDialog( data.toPage ) ) {
            return;
        }
        listview = data.prevPage.jqmData( "listview" ),
        form = listview.jqmData( "filter-form" );
        // Put the form back in the popup. It goes ahead of the listview.
        listview.before( form );
    });
})( jQuery );

</script>
<style>
.ui-selectmenu.ui-popup .ui-input-search {
    margin-left: .5em;
    margin-right: .5em;
}
.ui-selectmenu.ui-dialog .ui-content {
    padding-top: 0;
}
.ui-selectmenu.ui-dialog .ui-selectmenu-list {
    margin-top: 0;
}
.ui-selectmenu.ui-popup .ui-selectmenu-list li.ui-first-child .ui-btn {
    border-top-width: 1px;
    -webkit-border-radius: 0;
    border-radius: 0;
}
.ui-selectmenu.ui-dialog .ui-header {
    border-bottom-width: 1px;
}
</style>

</head>
<body>
<div data-role="page" class="jqm-demos" id="pageMainForm">

    <div data-role="header" class="jqm-header">
        <h2><a href="../" title="jQuery Mobile Demos home"><img src="../_assets/img/jquery-logo.png" alt="jQuery Mobile"></a></h2>
        <p>Demos <span class="jqm-version"></span></p>
        <a href="#" class="jqm-navmenu-link ui-btn ui-btn-icon-notext ui-corner-all ui-icon-bars ui-nodisc-icon ui-alt-icon ui-btn-left">Menu</a>
        <a href="#" class="jqm-search-link ui-btn ui-btn-icon-notext ui-corner-all ui-icon-search ui-nodisc-icon ui-alt-icon ui-btn-right">Search</a>
    </div><!-- /header -->

    <div data-role="content" class="ui-content jqm-content">

    <h1>Filterable inside custom select</h1>

        <div data-demo-html="true" data-demo-js="true" data-demo-css="true">
            <form>
                <select id="filter-menu" class="filterable-select" data-native-menu="false">
                    <option value="Option 1">Option 1</option>
                    <option value="Option 2">Option 2</option>
                    <option value="Option 3">Option 3</option>
                    <option value="Option 4">Option 4</option>
                    <option value="Option 5">Option 5</option>
                    <option value="Option 6">Option 6</option>
                    <option value="Option 7">Option 7</option>
                    <option value="Option 8">Option 8</option>
                    <option value="Option 9">Option 9</option>
                    <option value="Option 10">Option 10</option>
                    <option value="Option 11">Option 11</option>
                    <option value="Option 12">Option 12</option>
                    <option value="Option 13">Option 13</option>
                    <option value="Option 14">Option 14</option>
                    <option value="Option 15">Option 15</option>
                    <option value="Option 16">Option 16</option>
                    <option value="Option 17">Option 17</option>
                    <option value="Option 18">Option 18</option>
                    <option value="Option 19">Option 19</option>
                    <option value="Option 20">Option 20</option>
                    <option value="Option 21">Option 21</option>
                    <option value="Option 22">Option 22</option>
                </select>
            </form>
        </div>

    </div><!-- /content -->

</div><!-- /page -->
</body>
</html>