特定のファイルの変更のみをチェリーピックするにはどうすればいいですか? 質問する

特定のファイルの変更のみをチェリーピックするにはどうすればいいですか? 質問する

複数のファイルへの変更を含む特定のコミットで変更されたファイルの一部のみに加えられた変更を Git ブランチにマージしたい場合、どうすればこれを実現できますか?

という Git コミットでファイル、、、stuffが変更されたとします。ただし、の変更のみをファイル と にマージしたいとします。これは のジョブのように思えますが、はコミット全体をマージする方法しか知らず、ファイルのサブセットをマージする方法も知りません。ABCDstuffABgit cherry-pickcherry-pick

ベストアンサー1

cherry-pick -n私は( )を使用してこれを実行します。--no-commitこれにより、コミットする前に結果を検査 (および変更) できます。

git cherry-pick -n <commit>

# unstage modifications you don't want to keep, and remove the
# modifications from the work tree as well.
# this does work recursively!
git checkout HEAD <path>

# commit; the message will have been stored for you by cherry-pick
git commit

変更の大部分が不要なものである場合は、個々のパスを確認する代わりに (中間の手順)、すべてをリセットしてから、必要なものを追加できます。

# unstage everything
git reset HEAD

# stage the modifications you do want
git add <path>

# make the work tree match the index
# (do this from the top level of the repo)
git checkout .

おすすめ記事