172

git-rebaseman ページの言及-X<option>は に渡すことができますgit-merge。いつ/どのように正確に?

再帰戦略とそのオプションを使用してパッチを適用してリベースしたいと思います(競合するコミット全体をスキップするのではなく、スティックを適用します)。マージはしたくありません。履歴を線形にしたいのです。

私はもう試した:

git rebase -Xtheirs

git rebase -s 'recursive -Xtheirs'

-Xしかし、どちらの場合もgit は拒否します。


git rebase -Xtheirsツリーの競合を手動で解決する必要があることを除いて、最近のバージョンで動作します。git rebase -Xtheirs --continueこれらの競合を解決した後、 (-X繰り返し実行して) 実行する必要があります。

4

3 に答える 3

271

これは、Gitv1.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

注意:「私たち」と「彼ら」は、ストレートマージ中に行うことの反対を意味します。言い換えれば、「彼ら」は現在のブランチでのコミットを支持します。

于 2010-11-25T03:11:42.857 に答える
22

これは、独自のオプションセットが付属するマージ戦略用です

git rebase <branch> -s recursive -X theirs

このパッチには(2010年2月)と記載されていますが、機能するはずです。

マンページには、git-rebaseマージ戦略をサポートしていると書かれていますが、rebaseコマンドはについては知らず-X、提示されたときに使用法を示します。

それでも機能しない場合は、現在議論されています!
(最近のgitでサポートされています)


コミットからの更新db2b3b820e2b28da268cc88adff076b396392dfe (2013年7月、git 1.8.4+)、

インタラクティブリベースのマージオプションを無視しないでください

マージ戦略とそのオプションはで指定できますが、を使用するgit rebase-- interactive、それらは完全に無視されます。

サインオフ:Arnaud Fontaine

つまり-X、戦略は、プレーンなリベースだけでなく、インタラクティブなリベースでも機能するようになりました。

于 2010-05-31T18:38:44.420 に答える
7

iCrazyが言ったように、この機能は git 1.7.3 以降でのみ利用できます。そこで、(私のような) まだ 1.7.1 を使用している貧しい人々のために、私が自分で行った解決策を提示します。

git-rebase-theirs

これは非常に洗練された (したがって長い) スクリプトであり、本番環境での使用を目的としています: UI オプション、複数のファイルの処理、ファイルに実際に競合マーカーがあるかどうかのチェックなどですが、「コア」は 2 行に要約できます。

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
于 2012-04-17T22:57:54.887 に答える