時々私は一度に複数のブランチで作業しています。master、release-1.1、experimentalというブランチがあるとします。新しいファイルを作成するか、実験的に変更を加え、その1つの変更を他のブランチに適用したいと思います。
これをgitで実行できますか?コミットを別のブランチにマージするだけの場合、gitは自動的に「早送り」し、その間にコミットを含めます。しかし、このユースケースを処理する方法が必要です。
What you want to do is called cherry picking. You can cherry pick a single commit using the following command:
$ git cherry-pick <commit hash or name>
This will incorporate the change from that commit only into your current branch. Note, however, that this creates a new commit; this new commit has the exact same changes as the cherry-picked commit (and even the same commit date and author), but it is technically a new commit, so you'll see it as a new commit in, e.g., gitk
. You'll also have to perform the cherry pick for each branch in which you want to see the change.
解決策ですが、残念ながら、変更を加える前に知っておく必要があるのは、この変更に対してのみ別個のブランチ(いわゆる「トピックブランチ」)を作成し、意味のある最も早いブランチまたは最も早いコミットから外して、このブランチをマージすることです。このコミットを必要とするブランチに。
場合によっては、他の解決策として、メンテナンスブランチを変更し、メンテナンスブランチを安定したブランチにマージし、安定したブランチを開発ブランチにマージすることが考えられます。
Junio C Hamano(Gitメンテナー)は彼のブログでこれについて書いています:トピックブランチ間の競合/依存関係を早期に解決する