Gitブランチから特定のファイルをマージする方法 質問する

Gitブランチから特定のファイルをマージする方法 質問する

2 つの Git ブランチがあります:

  1. ブランチ1
  2. ブランチ2

ブランチ2のすべての履歴 (複数のコミット)をfile.pyブランチ 1file.pyのそのファイルのみにマージしたいと思います。

本質的には、 branch1file.pyで作業したいのですが、コマンドを活用したいと考えています。merge

これを行う最善の方法は何ですか?

ベストアンサー1

コンテンツがbranch2file.pyから入って、それがbranch1に適用されなくなった場合、一部の変更を選択して他の変更はそのままにしておく必要があります。完全な制御を行うには、スイッチを使用して対話型のマージを実行します。--patch

$ git checkout --patch branch2 file.py

のマニュアル ページの対話モード セクションでは、git-add(1)使用するキーについて説明しています。

y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk nor any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk nor any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help

特に、split コマンドが便利です。

おすすめ記事