itsource

Gitrebase에 대한 병합 전략을 선택하려면 어떻게 해야 합니까?

mycopycode 2023. 6. 26. 21:18
반응형

Gitrebase에 대한 병합 전략을 선택하려면 어떻게 해야 합니까?

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

반복 전략과 해당 옵션(충돌하는 커밋 전체를 건너뛰는 것이 아니라 모든 스틱 적용)이 포함된 패치를 적용하여 기본을 변경하고 싶습니다.저는 병합을 원하지 않고, 역사를 선형으로 만들고 싶습니다.

시도해 봤습니다.

git rebase -Xtheirs

그리고.

git rebase -s 'recursive -Xtheirs'

하지만 그것은 거부합니다.-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선택한 병합 전략에서 이해할 수 있는 추가 옵션을 전달하는 옵션입니다.

NB: "우리"와 "그들"은 직선적인 합병 과정에서 수행되는 것과 반대되는 것을 의미합니다.즉, "그들의"는 현재 분기에 대한 커밋을 선호합니다.

이는 고유한 옵션 집합과 함께 제공되는 병합 전략을 위한 것입니다.

git rebase <branch> -s recursive -X theirs

패치에 다음이 언급되지만 작동해야 합니다(2010년 2월).

맨 페이지에 나와 있습니다.git-rebase병합 전략을 지원하지만, rebase 명령은 에 대해 알지 못합니다.-X그리고 그것과 함께 제시되었을 때 사용법을 제공합니다.

그래서 만약 그것이 여전히 작동하지 않는다면, 그것은 지금 논의되고 있습니다!
(최근 Git에서 지원됨)


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

대화형 기본 재배치에서 병합 옵션 무시 안 함

병합 전략 및 해당 옵션은 다음에서 지정할 수 있습니다.git rebase하지만 그와 함께-- interactive그들은 완전히 무시당했습니다.

사인 오프 바이: 아르노 폰테인

그것은-X이제 전략은 일반적인 기본 재배치와 함께 대화형 기본 재배치와 함께 작동합니다.

iCrazy가 말했듯이 이 기능은 git 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

언급URL : https://stackoverflow.com/questions/2945344/how-do-i-select-a-merge-strategy-for-a-git-rebase

반응형