git rebase에 대한 병합 전략을 어떻게 선택합니까? 페이지 언급 -X<option>은에 전달할 수 있습니다 git-merge.

git-rebase맨 페이지 언급 -X<option>은에 전달할 수 있습니다 git-merge. 언제 / 어떻게 정확히?

나는에 패치를 적용하여 리베이스 싶습니다 재귀 전략과 그들의 옵션 (적용 어떤 스틱, 오히려 전체 충돌의 커밋을 건너 뛰는 이하). 나는 병합을 원하지 않고 역사를 선형으로 만들고 싶습니다.

난 노력 했어:

git rebase -Xtheirs

git rebase -s 'recursive -Xtheirs'

그러나 git은 -X두 경우 모두 거부합니다 .


git rebase -Xtheirs트리 충돌을 수동으로 해결해야한다는 점을 제외하고는 최신 버전에서 작동합니다. 이러한 충돌을 해결 한 후 git rebase -Xtheirs --continue( -X반복적으로) 실행해야합니다 .



답변

Git v1.7.3 이상 버전에서이를 사용할 수 있습니다.

git rebase --strategy-option theirs ${branch} # Long option
git rebase -X theirs ${branch} # Short option

( 문서에git rebase --strategy recursive --strategy-option theirs ${branch} 명시된 바와 같이 짧음 )

Git v1.7.3 릴리즈 노트 :

git rebase --strategy <s>선택한 병합 전략에 의해 이해되는 추가 옵션을 전달 하는 --strategy-option/ -X옵션을 배웠습니다 .

주의 : “우리”와 “그들”은 스트레이트 머지 중에하는 것과 반대입니다. 다시 말해, “그들의”는 현재 브랜치 의 커밋을 선호합니다 .


답변

고유 한 옵션 세트가 포함 된 병합 전략을위한 것입니다.

git rebase <branch> -s recursive -X theirs

이 패치에서 언급 하지만 (2010 년 2 월)

맨 페이지는 git-rebase병합 전략 을 지원하지만 rebase 명령은에 대해 알지 못하며 -X사용법을 알려줍니다.

그래도 작동하지 않으면 지금 토론 중입니다!
(최근 자식에서 지원)


커밋 db2b3b820e2b28da268cc88adff076b396392dfe (2013 년 7 월, git 1.8.4+) 에서 업데이트 ,

대화식 리베이스에서 병합 옵션을 무시하지 마십시오

병합 전략 및 옵션은에서 지정할 수 git rebase있지만을 사용 -- interactive하면 완전히 무시됩니다.

서명 : Arnaud Fontaine

-X, 일반 rebase뿐만 아니라 대화식 rebase에서도 작동합니다.


답변

으로 iCrazy는 말했다,이 기능은 이후 자식 1.7.3에만 사용할 수 있습니다. 그래서 가난한 영혼 (나 같은)이 여전히 1.7.1을 사용하고 있다면, 내가 한 해결책을 제시합니다.

깃 리베이스-그들의

ui 옵션, 여러 파일 처리, 파일에 실제로 충돌 마커가 있는지 확인하는 등의 용도로 사용되는 매우 정교하고 긴 스크립트입니다. 그러나 “핵심”은 다음 두 줄로 요약 할 수 있습니다.

cp file file.bak
awk '/^<+ HEAD$/,/^=+$/{next} /^>+ /{next} 1' file.bak > file

다음은 전체 스크립트입니다.

#!/bin/bash
#
# git-rebase-theirs - Resolve rebase conflicts by favoring 'theirs' version
#
#    Copyright (C) 2012 Rodrigo Silva (MestreLion) <linux@rodrigosilva.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program. If not see <http://www.gnu.org/licenses/gpl.html>

#Defaults:
verbose=0
backup=1
inplace=0
ext=".bak"

message() { printf "%s\n" "$1" >&2 ; }
skip()    { message "skipping ${2:-$file}${1:+: $1}"; continue ; }
argerr()  { printf "%s: %s\n" "$myname" "${1:-error}" >&2 ; usage 1 ; }
invalid() { argerr "invalid option: $1" ; }
missing() { argerr "missing${1:+ $1} operand." ; }

usage() {
    cat <<- USAGE
    Usage: $myname [options] [--] FILE...
    USAGE
    if [[ "$1" ]] ; then
        cat >&2 <<- USAGE
        Try '$myname --help' for more information.
        USAGE
        exit 1
    fi
    cat <<-USAGE

    Resolve git rebase conflicts in FILE(s) by favoring 'theirs' version

    When using git rebase, conflicts are usually wanted to be resolved
    by favoring the <working branch> version (the branch being rebased,
    'theirs' side in a rebase), instead of the <upstream> version (the
    base branch, 'ours' side)

    But git rebase --strategy -X theirs is only available from git 1.7.3
    For older versions, $myname is the solution.

    It works by discarding all lines between '<<<<<<< HEAD' and '========'
    inclusive, and also the the '>>>>>> commit' marker.

    By default it outputs to stdout, but files can be edited in-place
    using --in-place, which, unlike sed, creates a backup by default.

    Options:
      -h|--help            show this page.
      -v|--verbose         print more details in stderr.

      --in-place[=SUFFIX]  edit files in place, creating a backup with
                           SUFFIX extension. Default if blank is ""$ext"

       --no-backup         disables backup

    Copyright (C) 2012 Rodrigo Silva (MestreLion) <linux@rodrigosilva.com>
    License: GPLv3 or later. See <http://www.gnu.org/licenses/gpl.html>
    USAGE
    exit 0
}
myname="${0##*/}"

# Option handling
files=()
while (( $# )); do
    case "$1" in
    -h|--help     ) usage            ;;
    -v|--verbose  ) verbose=1        ;;
    --no-backup   ) backup=0         ;;
    --in-place    ) inplace=1        ;;
    --in-place=*  ) inplace=1
                    suffix="${1#*=}" ;;
    -*            ) invalid "$1"     ;;
    --            ) shift ; break    ;;
    *             ) files+=( "$1" )  ;;
    esac
    shift
done
files+=( "$@" )

(( "${#files[@]}" )) || missing "FILE"

ext=${suffix:-$ext}

for file in "${files[@]}"; do

    [[ -f "$file" ]] || skip "not a valid file"

    if ((inplace)); then
        outfile=$(tempfile) || skip "could not create temporary file"
        trap 'rm -f -- "$outfile"' EXIT
        cp "$file" "$outfile" || skip
        exec 3>"$outfile"
    else
        exec 3>&1
    fi

    # Do the magic :)
    awk '/^<+ HEAD$/,/^=+$/{next} /^>+ /{next} 1' "$file" >&3

    exec 3>&-

    ((inplace)) || continue

    diff "$file" "$outfile" >/dev/null && skip "no conflict markers found"

    ((backup)) && { cp "$file" "$file$ext" || skip "could not backup" ; }

    cp "$outfile" "$file" || skip "could not edit in-place"

    ((verbose)) && message "resolved ${file}"
done


답변