2011년 11월 24일 목요일

Cherry-picking specific patch

Hmm.. this seems easier..
git diff commit_before..commit_iwant > path
patch -p1 < path

----
I needed to adapt specific WebKit open source patch while upversioning.
This was from side effect of one open source patch.
What I did are:

1. Get the commit ids of specific patch and just before of it.
For example, see the log by 'git log' then it might show like below..

commit f16c8bee1573c195750b68e4d500ab4982f0471a
Author: weinig@apple.com
Date: Wed Nov 2 02:24:50 2011 +0000
...
commit a1a74a31943577f1426a0fed52470cae064f3b31
Author: nduca@chromium.org
Date: Wed Nov 2 02:18:28 2011 +0000
...

Suppose my wanted commit is weinig's patch, but still I need commit id of (-1).
It can be nduca's patch id.

2. Save patch to the file system.
git format-patch -k --stdout a1a74a31943577f1426a0fed52470cae064f3b31..f16c8bee1573c195750b68e4d500ab4982f0471a > blahblah.patch

3. Adapt this patch to your local
Changes directory to your local git root and type.
git am -3 -k blahblah.patch

Then you can see the cherry-picked patch is on the top of the log list.
Enjoy git learning~