Subversion rebase?

后端 未结 6 623
误落风尘
误落风尘 2020-12-23 02:06

I find this way easier to merge branches and less conflicts:

Copy trunk to a new branch, merge it with feature branch/s. When things done, merge the n

6条回答
  •  时光说笑
    2020-12-23 02:49

    I use a script that does a git like rebase for svn:

    #!/bin/bash
    
    set_safe()
    {
        set -eo pipefail
    }
    
    validate_number()
    (
        if (! [ "$1" -eq "$1" ] 2>/dev/null ) then
        {
            echo "$1 is not a number"
            return 1
        }
        fi
    )
    
    get_line()
    (
        set_safe
        #head -n "$1" | tail -n 1
        sed -n "${1}p;$(($1+1))q"
    )
    
    split_trim()
    (
        set_safe
        tr "$1" '\n' | sed -e 's/^\s*//;' -e 's/\s*$//'
    )
    
    run_svn()
    (
        set +x
        #echo "svn $*" 1>&2
        svn --non-interactive --password "$svn_password" "$@"
    )
    
    rebase()
    (
        set_safe
    
        url="$1"
        cur="$2"
        end="$3"
    
        validate_number "$cur"
        if ([ -z "$end" ] || [ "$end" = "HEAD" ]) then
        {
            end="$(run_svn info "$url" | grep "Last Changed Rev" | cut -d' ' -f4)"
            echo "end: $end"
        }
        else
        {
            validate_number "$end";
        }
        fi
    
        while (true) do
        {
            log="$(run_svn log "$url" -l1 -r "$cur:HEAD")"
            meta="$(echo -n "$log" | get_line 2 | split_trim '|')"
            next="$(echo -n "$meta" | get_line 1 | tail -c +2)"
            author="$(echo -n "$meta" | get_line 2)"
            date="$(echo -n "$meta" | get_line 3 | awk '{print $1, $2, $3}')"
            msg="$(echo -n "$log" | tail -n +4 | head -n -1)"
            cur=$next
    
            if ([ -z $cur ] || [ $cur -gt $end ]) then { break; } fi
    
            echo "$msg" > .msg
    
            echo "Merging revision $cur:"
            echo "========"
            cat .msg
            echo "========"
    
            run_svn merge "$url" -c $cur
            run_svn commit -F .msg
            rm -f .msg
            run_svn update
    
            echo "Success"
            echo
    
            cur=$(($cur + 1))
        }
        done
    )
    
    if ([ -z "$1" ]) then
    {
        echo "Usage:"
        echo "    svn-rebase.sh   [end revision]"
        exit
    }
    fi
    
    echo -n "svn password: "
    read -s svn_password
    echo
    
    rebase "$1" "$2" "$3"
    err=$?
    if ([ $err -ne 0 ]) then { echo "rebase failed: $err"; } fi
    exit $err
    

    It merges revisions from other branch one by one.

提交回复
热议问题