第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

重新安置分支機(jī)構(gòu),包括其所有子級

重新安置分支機(jī)構(gòu),包括其所有子級

Git
肥皂起泡泡 2019-10-06 11:09:28
我有以下Git存儲(chǔ)庫拓?fù)洌篈-B-F (master)   \   D (feature-a)    \ /     C (feature)      \       E (feature-b)通過重新feature分支,我希望重新構(gòu)建整個(gè)子樹(包括子分支):$ git rebase feature masterA-B-F (master)     \   D (feature-a)      \ /       C (feature)        \         E (feature-b)但是,這是實(shí)際結(jié)果:      C' (feature)     /A-B-F (master)   \   D (feature-a)    \ /     C      \       E (feature-b)我知道我可以通過執(zhí)行以下操作輕松地手動(dòng)修復(fù)它:$ git rebase --onto feature C feature-a$ git rebase --onto feature C feature-b但是,有沒有一種方法可以自動(dòng)為分支(包括其所有子代/后代)建立基礎(chǔ)?
查看完整描述

3 回答

?
紅顏莎娜

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超13個(gè)贊

幾年前,我寫了一些東西來處理這種事情。(當(dāng)然,歡迎提出改進(jìn)意見,但不要過多地評判-這是很久以前的事了!我什至還不了解Perl!)


它用于更多靜態(tài)情況-您可以通過設(shè)置表單的config參數(shù)來配置它branch.<branch>.autorebaseparent。它不會(huì)碰到任何沒有設(shè)置配置參數(shù)的分支。如果這不是您想要的,則可以輕松地將其入侵到所需位置。在過去的一兩年中,我并沒有真正使用過它,但是當(dāng)我使用它時(shí),它似乎總是非常安全和穩(wěn)定的,因?yàn)榇笠?guī)模自動(dòng)重新定級是可能的。


就是這樣 通過保存成一個(gè)名為使用它git-auto-rebase在你的PATH。-n嘗試使用空運(yùn)行()選項(xiàng)也是一個(gè)好主意。它可能比您真正想要的要詳細(xì)一些,但是它將向您顯示將要嘗試重新建立基礎(chǔ)的內(nèi)容以及要建立的內(nèi)容??赡軙?huì)節(jié)省您一些悲傷。


#!/bin/bash


CACHE_DIR=.git/auto-rebase

TODO=$CACHE_DIR/todo

TODO_BACKUP=$CACHE_DIR/todo.backup

COMPLETED=$CACHE_DIR/completed

ORIGINAL_BRANCH=$CACHE_DIR/original_branch

REF_NAMESPACE=refs/pre-auto-rebase


print_help() {

    echo "Usage:  git auto-rebase [opts]"

    echo "Options:"

    echo "    -n   dry run"

    echo "    -c   continue previous auto-rebase"

    echo "    -a   abort previous auto-rebase"

    echo "         (leaves completed rebases intact)"

}


cleanup_autorebase() {

    rm -rf $CACHE_DIR

    if [ -n "$dry_run" ]; then

        # The dry run should do nothing here. It doesn't create refs, and won't

        # run unless auto-rebase is empty. Leave this here to catch programming

        # errors, and for possible future -f option.

        git for-each-ref --format="%(refname)" $REF_NAMESPACE |

        while read ref; do

            echo git update-ref -d $ref

        done

    else

        git for-each-ref --format="%(refname)" $REF_NAMESPACE |

        while read ref; do

            git update-ref -d $ref

        done

    fi

}


# Get the rebase relationships from branch.*.autorebaseparent

get_config_relationships() {

    mkdir -p .git/auto-rebase

    # We cannot simply read the indicated parents and blindly follow their

    # instructions; they must form a directed acyclic graph (like git!) which

    # furthermore has no sources with two sinks (i.e. a branch may not be

    # rebased onto two others).

    # 

    # The awk script checks for cycles and double-parents, then sorts first by

    # depth of hierarchy (how many parents it takes to get to a top-level

    # parent), then by parent name. This means that all rebasing onto a given

    # parent happens in a row - convenient for removal of cached refs.

    IFS=$'\n'

    git config --get-regexp 'branch\..+\.autorebaseparent' | \

    awk '{

        child=$1

        sub("^branch[.]","",child)

        sub("[.]autorebaseparent$","",child)

        if (parent[child] != 0) {

            print "Error: branch "child" has more than one parent specified."

            error=1

            exit 1

        }

        parent[child]=$2

    }

    END {

        if ( error != 0 )

            exit error

        # check for cycles

        for (child in parent) {

            delete cache

            depth=0

            cache[child]=1

            cur=child

            while ( parent[cur] != 0 ) {

                depth++

                cur=parent[cur]

                if ( cache[cur] != 0 ) {

                    print "Error: cycle in branch."child".autorebaseparent hierarchy detected"

                    exit 1

                } else {

                    cache[cur]=1

                }

            }

            depths[child]=depth" "parent[child]" "child

        }

        n=asort(depths, children)

        for (i=1; i<=n; i++) {

            sub(".* ","",children[i])

        }

        for (i=1; i<=n; i++) {

            if (parent[children[i]] != 0)

                print parent[children[i]],children[i]

        }

    }' > $TODO


    # Check for any errors. If the awk script's good, this should really check

    # exit codes.

    if grep -q '^Error:' $TODO; then

        cat $TODO

        rm -rf $CACHE_DIR

        exit 1

    fi


    cp $TODO $TODO_BACKUP

}


# Get relationships from config, or if continuing, verify validity of cache

get_relationships() {

    if [ -n "$continue" ]; then

        if [ ! -d $CACHE_DIR ]; then

            echo "Error: You requested to continue a previous auto-rebase, but"

            echo "$CACHE_DIR does not exist."

            exit 1

        fi

        if [ -f $TODO -a -f $TODO_BACKUP -a -f $ORIGINAL_BRANCH ]; then

            if ! cat $COMPLETED $TODO | diff - $TODO_BACKUP; then

                echo "Error: You requested to continue a previous auto-rebase, but the cache appears"

                echo "to be invalid (completed rebases + todo rebases != planned rebases)."

                echo "You may attempt to manually continue from what is stored in $CACHE_DIR"

                echo "or remove it with \"git auto-rebase -a\""

                exit 1

            fi

        else

            echo "Error: You requested to continue a previous auto-rebase, but some cached files"

            echo "are missing."

            echo "You may attempt to manually continue from what is stored in $CACHE_DIR"

            echo "or remove it with \"git auto-rebase -a\""

            exit 1

        fi

    elif [ -d $CACHE_DIR ]; then

        echo "A previous auto-rebase appears to have been left unfinished."

        echo "Either continue it with \"git auto-rebase -c\" or remove the cache with"

        echo "\"git auto-rebase -a\""

        exit 1

    else

        get_config_relationships

    fi

}


# Verify that desired branches exist, and pre-refs do not.

check_ref_existence() {

    local parent child

    for pair in "${pairs[@]}"; do

        parent="${pair% *}"

        if ! git show-ref -q --verify "refs/heads/$parent" > /dev/null ; then

            if ! git show-ref -q --verify "refs/remotes/$parent" > /dev/null; then

                child="${pair#* }"

                echo "Error: specified parent branch $parent of branch $child does not exist"

                exit 1

            fi

        fi

        if [ -z "$continue" ]; then

            if git show-ref -q --verify "$REF_NAMESPACE/$parent" > /dev/null; then

                echo "Error: ref $REF_NAMESPACE/$parent already exists"

                echo "Most likely a previous git-auto-rebase did not complete; if you have fixed all"

                echo "necessary rebases, you may try again after removing it with:"

                echo

                echo "git update-ref -d $REF_NAMESPACE/$parent"

                echo

                exit 1

            fi

        else

            if ! git show-ref -q --verify "$REF_NAMESPACE/$parent" > /dev/null; then

                echo "Error: You requested to continue a previous auto-rebase, but the required"

                echo "cached ref $REF_NAMESPACE/$parent is missing."

                echo "You may attempt to manually continue from the contents of $CACHE_DIR"

                echo "and whatever refs in refs/$REF_NAMESPACE still exist, or abort the previous"

                echo "auto-rebase with \"git auto-rebase -a\""

                exit 1

            fi

        fi

    done

}


# Create the pre-refs, storing original position of rebased parents

create_pre_refs() {

    local parent prev_parent

    for pair in "${pairs[@]}"; do

        parent="${pair% *}"

        if [ "$prev_parent" != "$parent" ]; then

            if [ -n "$dry_run" ]; then

                echo git update-ref "$REF_NAMESPACE/$parent" "$parent" \"\"

            else

                if ! git update-ref "$REF_NAMESPACE/$parent" "$parent" ""; then

                    echo "Error: cannot create ref $REF_NAMESPACE/$parent"

                    exit 1

                fi

            fi

        fi


        prev_parent="$parent"

    done

}


# Perform the rebases, updating todo/completed as we go

perform_rebases() {

    local prev_parent parent child

    for pair in "${pairs[@]}"; do

        parent="${pair% *}"

        child="${pair#* }"


        # We do this *before* rebasing, assuming most likely any failures will be

        # fixed with rebase --continue, and therefore should not be attempted again

        head -n 1 $TODO >> $COMPLETED

        sed -i '1d' $TODO


        if [ -n "$dry_run" ]; then

            echo git rebase --onto "$parent" "$REF_NAMESPACE/$parent" "$child"

            echo "Successfully rebased $child onto $parent"

        else

            echo git rebase --onto "$parent" "$REF_NAMESPACE/$parent" "$child"

            if ( git merge-ff -q "$child" "$parent" 2> /dev/null && echo "Fast-forwarded $child to $parent." ) || \

                git rebase --onto "$parent" "$REF_NAMESPACE/$parent" "$child"; then

                echo "Successfully rebased $child onto $parent"

            else

                echo "Error rebasing $child onto $parent."

                echo 'You should either fix it (end with git rebase --continue) or abort it, then use'

                echo '"git auto-rebase -c" to continue. You may also use "git auto-rebase -a" to'

                echo 'abort the auto-rebase. Note that this will not undo already-completed rebases.'

                exit 1

            fi

        fi


        prev_parent="$parent"

    done

}


rebase_all_intelligent() {

    if ! git rev-parse --show-git-dir &> /dev/null; then

        echo "Error: git-auto-rebase must be run from inside a git repository"

        exit 1

    fi


    SUBDIRECTORY_OK=1

    . "$(git --exec-path | sed 's/:/\n/' | grep -m 1 git-core)"/git-sh-setup

    cd_to_toplevel



    # Figure out what we need to do (continue, or read from config)

    get_relationships


    # Read the resulting todo list

    OLDIFS="$IFS"

    IFS=$'\n'

    pairs=($(cat $TODO))

    IFS="$OLDIFS"


    # Store the original branch

    if [ -z "$continue" ]; then

        git symbolic-ref HEAD | sed 's@refs/heads/@@' > $ORIGINAL_BRANCH

    fi


    check_ref_existence

    # These three depend on the pairs array

    if [ -z "$continue" ]; then

        create_pre_refs

    fi

    perform_rebases


    echo "Returning to original branch"

    if [ -n "$dry_run" ]; then

        echo git checkout $(cat $ORIGINAL_BRANCH)

    else

        git checkout $(cat $ORIGINAL_BRANCH) > /dev/null

    fi


    if diff -q $COMPLETED $TODO_BACKUP ; then

        if [ "$(wc -l $TODO | cut -d" " -f1)" -eq 0 ]; then

            cleanup_autorebase

            echo "Auto-rebase complete"

        else

            echo "Error: todo-rebases not empty, but completed and planned rebases match."

            echo "This should not be possible, unless you hand-edited a cached file."

            echo "Examine $TODO, $TODO_BACKUP, and $COMPLETED to determine what went wrong."

            exit 1

        fi

    else

        echo "Error: completed rebases don't match planned rebases."

        echo "Examine $TODO_BACKUP and $COMPLETED to determine what went wrong."

        exit 1

    fi

}



while getopts "nca" opt; do

    case $opt in

        n ) dry_run=1;;

        c ) continue=1;;

        a ) abort=1;;

        * )

            echo "git-auto-rebase is too dangerous to run with invalid options; exiting"

            print_help

            exit 1

    esac

done

shift $((OPTIND-1))



case $# in

    0 )

        if [ -n "$abort" ]; then

            cleanup_autorebase

        else

            rebase_all_intelligent

        fi

        ;;


    * )

        print_help

        exit 1

        ;;

esac

自從我最初解決這個(gè)問題以來,我發(fā)現(xiàn)的一件事是有時(shí)答案是您實(shí)際上根本不想變基!首先要在正確的共同祖先啟動(dòng)主題分支,然后再嘗試不推動(dòng)它們前進(jìn),這是有話可說的。但這是在您和您的工作流程之間。


查看完整回答
反對 回復(fù) 2019-10-06
?
莫回?zé)o

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊

如果需要更新提交者日期,GIT_COMMITTER_DATE則可以使用環(huán)境變量(手動(dòng))。也可以使用--formatoption獲得分支名稱,而無需其他格式。


export GIT_COMMITTER_DATE=$( date -Iseconds )

git branch --format='%(refname)' --contains C | xargs -n 1 | git rebase -p --onto master C^

unset GIT_COMMITTER_DATE

# don't forget to unset this variable to avoid effect for the further work

注意:需要為--committer-date-is-author-date或設(shè)置GIT_COMMITTER_DATE相同的校驗(yàn)和C',或保證相同的校驗(yàn)Ca'和并Cb'提交(分別在重定基礎(chǔ)功能,功能 -a 和功能-b上)。


查看完整回答
反對 回復(fù) 2019-10-06
  • 3 回答
  • 0 關(guān)注
  • 561 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號