私の連絡先情報
郵便メール:
2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
【関連トピック】
- 意思
commit
バージョンを別のブランチにリベースする- バージョンが競合した場合にリベースを実行する
- 指定したバージョンで対話型リベースを実行する
- インタラクティブなリベースを使用してバージョンを集約する
- インタラクティブなリベースを使用したコミッターの変更
- 自動集計バージョン
リベース (Rebasing
) は、Git の非常に強力な機能です。リベースは操作の一種です。commit
あ 最も初期のものは以下に基づいていましたcommit
B の;あ リベース先C、つまり意志 あ に基づいてなるC 手術。
次のデモ ケースでは、リベースが思ったほど簡単ではないことがわかります。
commit
バージョンを別のブランチにリベースするまず、最も単純なタイプのリベース操作を見てみましょう。関連する準備作業: 新しいファイルの導入、送信、内容の変更、および再送信。このようにして、ローカルの 2 倍の commit
バージョン。
まだ一緒に jgit
ライブラリの例:
# Clone jgit repo into chapter4
$ git clone https://git.eclipse.org/r/jgit/jgit chapter4
$ cd chapter4
# Checkout a new branch
$ git checkout -b rebaseExample --track origin/stable-3.1
# Create the 1st commit
$ echo "My Fishtank
Gravel, water, plants
Fish, pump, skeleton" > fishtank.txt
$ git add fishtank.txt
$ git commit -m "My brand new fishtank"
# Create the 2nd commit
$ echo "mosquitos" >> fishtank.txt
$ git add fishtank.txt
$ git commit -m "Feeding my fish"
# Rabase to stable-3.2
$ git rebase origin/stable-3.2
Successfully rebased and updated refs/heads/rebaseExample.
リベースする前に:
リベース後:
git rebase
実行プロセス:
HEAD
リベースが指すターゲットブランチ間の共通バージョン (merge-base
);merge-base
、ターゲット ブランチ上で欠落しているバージョンをすべて検索します。もし commit
バージョンまたはbranch
ブランチを別のブランチにリベースするHEAD
、バージョンの競合が発生する可能性があります。この時点で競合を解決し、コマンドを実行する必要があります。git rebase --continue
、リベースを完了できます。
このセクションの例では、競合が存在する場合にリベースを実行する方法を示します。セクション 4.1 で示した最終結果に続き、今回は rebaseExample
ブランチは以下にリベースされましたstable-3.2
支店。この例では、stable-3.1 からの新しいブランチを再チェックアウトし、 と を追加します。rebaseExample
ブランチ名は同じだが内容に互換性がないテキスト ファイルfishtank.txt
:
# Checkout rebaseExample2
$ git checkout -b rebaseExample2 --track origin/stable-3.1
# Add a new commit
$ echo "My Fishtank
Pirateship, Oister shell
Coconut shell
">fishtank.txt
$ git add fishtank.txt
$ git commit -m "My brand new fishtank"
# Rebase conflicting branches
$ git rebase rebaseExample
Auto-merging fishtank.txt
CONFLICT (add/add): Merge conflict in fishtank.txt
error: could not apply 24f9bf1ef... My brand new fishtank2
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 24f9bf1ef... My brand new fishtank2
$ subl fishtank.txt
紛争の状況は次のとおりです。
次の内容に変更し、保存して閉じます。
マージされたファイルを追加し、リベースを続行します。
$ git add fishtank.txt
$ git rebase --continue
hint: Waiting for your editor to close the file...
開かれるエディターを次の図に示します。
確認して保存して閉じると、リベースが成功したことを示すプロンプトが表示されます。
$ git rebase --continue
[detached HEAD 9911772b3] My brand new fishtank2
1 file changed, 2 insertions(+), 3 deletions(-)
Successfully rebased and updated refs/heads/rebaseExample2.
# Check new status via gitk
$ gitk
詳細は以下のとおりです。
このリベースでは、古いブランチには存在するが新しいブランチには存在しないバージョンのみがリベースされる (つまり、新しいバージョンが追加される) ことがわかります。 commit
)。
最初のリベース中断の git プロンプト情報には、次の 2 つの選択肢も表示されます。
git rebase --abort
: 文字通りの意味として、リベースを中断します。
git rebase --skip
: 競合をスキップして直接リベースすると、次のようになります。 rebaseExample2
新しいものを捨てるcommit
に直接マージされます rebaseExample
、リベース後に指された親、および rebaseExample
一貫性のある:
この例では、 rebaseExample
ブランチに基づいて使用方法をデモンストレーションする--interactive
マーク、この 2 つを 4.1 でリベースしてくださいcommit
リモート追跡ブランチへのリベースstable-3.1
優れた:
$ git checkout rebaseExample
Switched to branch 'rebaseExample'
Your branch is ahead of 'origin/stable-3.1' by 109 commits.
(use "git push" to publish your local commits)
$ git rebase origin/stable-3.1
このとき、新たにポップアップエディターにコミットリストが表示されます。 rebaseExample
そしてstable-3.1
間、すべてを次のようにリベースできますstable-3.1
のcommit
記録。例では 2 つの新しいものをそのままにしておきますcommit
、残りをすべて削除します (つまり、89 行目以前の内容)。
保存後、エディタを終了すると、次の出力が表示されます。
$ git rebase --interactive origin/stable-3.1
Successfully rebased and updated refs/heads/rebaseExample.
# Check in gitk view:
結果は次のとおりです。
拡張子の例
この例では、次のコマンドを使用して目的の効果をすばやく実現することもできます。
$ git rebase --onto origin/stable-3.1 origin/stable-3.2 rebaseExample
Successfully rebased and updated refs/heads/rebaseExample.
リベース前後の図は次のとおりです。