複数のファイルへの変更を含む特定のコミットで変更されたファイルの一部のみに加えられた変更を Git ブランチにマージしたい場合、どうすればこれを実現できますか?
という Git コミットでファイル、、、stuff
が変更されたとします。ただし、の変更のみをファイル と にマージしたいとします。これは のジョブのように思えますが、はコミット全体をマージする方法しか知らず、ファイルのサブセットをマージする方法も知りません。A
B
C
D
stuff
A
B
git cherry-pick
cherry-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 .