3

私は ClearCase に精通しており、ファイルを他のブランチからブランチにマージできます。これはgitでどのように可能ですか? たとえば、私は次の構造を持っています

master--->branch_2
  |
  |
  V
branch_1

そのため、いくつかの独立した開発が行われていますbranch_1branch_2. kdiff3 のようないくつかのマージツールbranch_2を使用して、特定のコードをマージしたいと考えています。branch_1

編集: Kdiff3 には、ファイルの 2 つまたは 3 つのバージョン (同じまたは異なるブランチから) を比較して、競合を強調する素晴らしいマージ オプションがあります。次に、各競合をジャンプして、ファイルの 1 つ以上のバージョンからコードを選択し、(必要に応じて) いくつかの編集を行い、最後にファイルを保存します。この機能は、私が ClearCase を使用していたとき、非常に便利でした。同じように動作するように kdiff3 で git mergetool を構成する方法はありますか?

前もって感謝します

4

3 に答える 3

1

It sounds like you want to merge a specific portion of changes from a given commit in branch_2.

If that's the case, you can use git cherry-pick --no-commit or (-n) to apply the changes from a commit in branch_2 without creating a new commit. From that point you can decide which changes to commit by staging only portions of the modified files.

Here's an example:

git checkout branch_1
git cherry-pick -n <some-commit>  # 1. Apply the changes from some commit in branch_2
                                  # without creating a new commit
git reset HEAD                    # 2. Unstage all changes from that commit
git add -p                        # 3. Decide which changes to include in the commit
git commit                        # 4. Commit those changes
于 2015-09-25T11:47:01.277 に答える
1

branch_1 に立ってcherry-pick、branch_2 から必要なコミットを単純化できます。

git cherry-pick <some sha1>

branch_1 で作業をリベースして、branch_2 の後に配置することもできます

git rebase --onto branch_2 branch_1
于 2015-09-25T05:50:58.293 に答える
0

ターゲットブランチにいる:

git checkout branch1

branch2 のバージョンを参照しながら、branch1 のコードを編集します。

git difftool branch2 -- file.txt

通常どおり変更をコミットします

git add file.txt
git commit
于 2015-09-25T05:49:40.577 に答える