$> git clone <http://provider.com/coolrepo.git>
$> cd coolrepo
$> git fetch <http://provider.com/repowithvaluablechanges.git>
You can now use the SHA1 from the other repo with valuable changes even if they are unrelated!
$> git format-patch -k -1 --stdout <commit SHA> | git am -3 -k
-3 for three-way patch
-1 for single commit alone
Example
[dev@centosmini vfcommon-lib]$ git format-patch -k -1 --stdout d6fd19c8e185e4adc0b817da4df02b7fde3df452 | git am -3 -k
Applying: Plug in the newly created HLS VFStream
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Renaming libqamplayer/vfcommon/vfstream.cpp => vfstream.cpp
Auto-merging vfstream.cpp
[dev@centosmini vfcommon-lib]$ git push origin HEAD
Alternative way if repos are already checked out in parrallel
$> git --git-dir=../<some_other_repo>/.git format-patch -k -1 --stdout <commit SHA> | git am -3 -k
Problem
[dev@centosmini vfcommon-lib]$ git format-patch -k -1 --stdout 7e810e103495d95fc4be6450ba47c4857c35425d | git am -3 -k
previous rebase directory /home/dev/vfcommon-lib/.git/rebase-apply still exists but mbox given.
[dev@centosmini vfcommon-lib]$ git rebase --abort
It looks like git-am is in progress. Cannot rebase.
Solution
The reason behind this is that you most likely previously started a git am session and you resolved the conflict, committed and pushed, then restarted another git am session. Next time complete with something like "git am -3 --resolved"
For now you can try this :
$> git am --abort
Problem
[dev@centosmini vfcommon-lib]$ git format-patch -k -1 --stdout f428822a53cb74d56a8f84f05e903cbf414bee5f | git am -3 -k
Applying: Fix clam key wait too long bug in unencrypted stream case and Increase clam client's send-keep-alive frequency, refs VF-8701
Using index info to reconstruct a base tree...
error: patch failed: libqamplayer/clam.cpp:184
error: libqamplayer/clam.cpp: patch does not apply
error: patch failed: libqamplayer/libav_bridge.cpp:341
error: libqamplayer/libav_bridge.cpp: patch does not apply
Did you hand edit your patch?
It does not apply to blobs recorded in its index.
Cannot fall back to three-way merge.
Patch failed at 0001 Fix clam key wait too long bug in unencrypted stream case and Increase clam client's send-keep-alive frequency, refs VF-8701
When you have resolved this problem run "git am -3 --resolved".
If you would prefer to skip this patch, instead run "git am -3 --skip".
To restore the original branch and stop patching run "git am -3 --abort".
Understanding
This is because this commit is tainted with unrelated files from other directories that don't exist in the local repo. The way I work around this is to separate it in two steps:
git format-patch -k -1 --stdout b1ccea87d95686a86a080a89e420917d751779b1 > b1.diff
Then manually edit b1.diff to remove parts related to unwanted directories, then continue with
cat b1.diff | git am -3 -k
Recent Comments