2016-07-13 12 views
1

私はtopicalを持っています。これはdevelopmentブランチです。今度はtopicalBranchがコミットを先行しており、一方developmentは他のコントリビュータからのプル要求を受け入れ、developmentの更新されたマージは最新のコミットC4と相反する変更点を持っています。更新されたベースブランチから私のフィーチャーブランチに変更を取得します

C1---C2---C5 development 
     \ 
     C3---C4 topicalBranch 

私は新しいツリーが見えるようにしたい:

C3' とC4' のC5からの変更を持って
C1---C2---C5 development 
      \ 
      C3'---C4' topicalBranch 

だから、現在のツリーは次のようになります。私はGit-Rebasingを検索しましたが、developmentに何も変更することなく、topicalBranchを更新します。

developmentブランチで行われた変更をtopicalBranchに更新する最も良い方法は、developmentブランチに新しいプルリクエストを作成できるようにすることです。

+3

実際、 'git rebase'はあなたが探している答えです。なぜそれがあなたにふさわしくないと思ったのですか? –

+0

これは、 'development'に' topicalBranch'をリベースすると、 'development'を私の変更に反映させないのでしょうか? 私が望むのは、 'development'から' topicalBranch'に新しい変更を加えることです。 私はこれを仮定するのに全く間違っているかもしれません。 誰かがこれについて詳細な説明をすることができますか? – shubhamsingh

+1

@shubhamsinghはい、あなたが開発をチェックアウトし、あなたが話題をrebaseした場合、それが起こります。ブライアンが言っていることは、あなたが局所的にチェックアウトし、その後開発を再開すべきだということです。 –

答えて

3

rebaseは間違いなくあなたが望むものです。ただし、メモこれはあなたの履歴を書き換えます。したがって、他の開発者があなたの局所的な支店を引っ張っている場所から遠隔のリポジトリに移動しているなら、彼らは引き込みを強制しなければならないでしょう。しかし、あなたがtopicalBranchで働く唯一の人なら、これは問題ではありません。

新しいリポジトリを初期化し、リベース後のツリーの外観を示すコミットをいくつか作成して、シナリオを再構築してみましょう。

jeff ~ $ mkdir test && cd test 
jeff test $ git init 
Initialized empty Git repository in /home/jeff/test/.git/ 
jeff test (master #) $ touch file1 && git add . && git commit -m "init repo" 
[master (root-commit) ba3e0ed] init repo 
1 file changed, 0 insertions(+), 0 deletions(-) 
create mode 100644 file1 
jeff test (master) $ git branch -m development 

jeff test (development) $ touch file2 && git add . && git commit -m "file2" 
[development fb03bd9] file2 
1 file changed, 0 insertions(+), 0 deletions(-) 
create mode 100644 file2 

今度は、局所的に分岐しましょう。

jeff test (development) $ git checkout -b topicalBranch 
Switched to a new branch 'topicalBranch' 
jeff test (topicalBranch) $ touch file3 && git add . && git commit -m "file3" 
[topicalBranch c9ffa5a] file3 
1 file changed, 0 insertions(+), 0 deletions(-) 
create mode 100644 file3 
jeff test (topicalBranch) $ touch file4 && git add . && git commit -m "file4" 
[topicalBranch 5322397] file4 
1 file changed, 0 insertions(+), 0 deletions(-) 
create mode 100644 file4 

他の開発者からのコミットをシミュレートします。

jeff test (topicalBranch) $ git checkout development 
Switched to branch 'development' 
jeff test (development) $ touch file5 && git add . && git commit -m "file5" 
[development e237fb5] file5 
1 file changed, 0 insertions(+), 0 deletions(-) 
create mode 100644 file5 

今、私たちは木があなたのようなもので、私たちは新しいがtopicalBranchに開発ブランチからコミット取得したいことがわかります。

jeff test (development) $ git log --graph --oneline --decorate --all 
* e237fb5 (HEAD -> development) file5 
| * 5322397 (topicalBranch) file4 
| * c9ffa5a file3 
|/ 
* fb03bd9 file2 
* ba3e0ed init repo 

それでは、リベースしましょう。

jeff test (development) $ git checkout topicalBranch 
Switched to branch 'topicalBranch' 
jeff test (topicalBranch) $ git rebase development 
First, rewinding head to replay your work on top of it... 
Applying: file3 
Applying: file4 

そして最後に、あなたは前に開発ブランチから新しいコミットを含めるようにtopicalBranchは、その歴史の再書かれていることがわかります。

jeff test (topicalBranch) $ git log --graph --oneline --decorate --all 
* f332250 (HEAD -> topicalBranch) file4 
* a069799 file3 
* e237fb5 (development) file5 
* fb03bd9 file2 
* ba3e0ed init repo 

今、あなたは開発に簡単に早送りマージtopicalBranchできるようになります。

このプロセスは、開発ブランチに入る新しいコミットのために必要なだけ頻繁に繰り返すことができます。 topicalBranchが最終的に終了したときに解決すべき矛盾がなく、競合を定期的に解決できるように、これを頻繁に行うことをお勧めします。さらに、早期に構成やアーキテクチャの変化を発見するのに役立ちます。

+0

私はこの答えは説明が少なすぎ、コマンド+コンソール出力が多すぎると思います。 – Roman

+1

@jeffコマンドの詳細な回答をありがとう。これらを使ってローカルのgitリポジトリを複製し、 'rebase'は' topicalBranch'の更新された変更と 'development'ブランチに触れることなく、分岐履歴を持つよりも私の履歴を「線形」にすることに気付きました。 – shubhamsingh

+0

'topicalBranch'を' C2'ではなく 'C5'に基づいてリベースすることは、' development'ブランチには影響しません。 'topicalBranch'の頭部から' C1'を(一時的に)コミットするための祖先チェーンが**線形であるように見えるにもかかわらず、2つのブランチは異なったままであり、ブランチの開発に関する新しいコミットは**ない**自動的に 'topicalBranch'に入ります。 –

1

あなたはそれはあなたがあなたの局所ブランチからgit merge developmentを行う必要があり、より

C1---C2--------C5 development 
     \   \ 
     C3---C4---C6' topicalBranch 

のようになりますので、あなたの局所ブランチに開発ブランチをマージする必要があります。

+2

これは、他の人が引っ張っているので、歴史が残っているように見せかける場合は、乱雑なツリーと簡単な引っ張りのトレードオフを考慮して、 'rebase'の代わりとして良い答えです。 –

関連する問題