Skip to content

Instantly share code, notes, and snippets.

@kitzberger
Last active October 27, 2020 10:34
Show Gist options
  • Save kitzberger/aceb668f8f4837e993bd1046044bf725 to your computer and use it in GitHub Desktop.
Save kitzberger/aceb668f8f4837e993bd1046044bf725 to your computer and use it in GitHub Desktop.
Cherry-pick commits from one git repo to the other

Cherry-pick commits from one git repo to the other

Scenario: migrate code from one git repo to the other that do not have a common folder structure.

For example a single TYPO3 extension within two different projects:

  • From: typo3conf/ext/my_ext
  • To: packages/my_ext

https://git-scm.com/docs/git-format-patch https://git-scm.com/docs/git-am

Create patches in repo 1

git format-patch -2 1ab8c73f35703318070ff51fbd7320b9b1fd901c .
> 0001-Commit-message-123.patch
> 0002-Commit-message-321.patch

View content of patch

cat 0001-Commit-message.patch

From 7ae37629db6ec0745fc7ffaf6ffd704f1f9bf206 Mon Sep 17 00:00:00 2001
From: Bob Ross <[email protected]>
Date: Mon, 18 Nov 2019 12:01:54 +0100
Subject: Commit message 123

---
 .../ext/my_ext/Configuration/TypoScript/setup.txt | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/typo3conf/ext/my_ext/Configuration/TypoScript/setup.txt b/typo3conf/ext/my_ext/Configuration/TypoScript/setup.txt
index 3894b16..ddcddc3 100644
--- a/typo3conf/ext/my_ext/Configuration/TypoScript/setup.txt
+++ b/typo3conf/ext/my_ext/Configuration/TypoScript/setup.txt
@@ -27,6 +27,9 @@ lib.yyy >
 page.10.variables.header = TEXT
 page.10.variables.header.value = 1
 
+page.10.variables.footer = TEXT
+page.10.variables.footer.value = xxx
+
 lib.xxx = COA
 lib.xxx {
 
-- 
2.7.4

Apply patches in git repo 2

# --3way -> 3-way-merge
# -p4 -> strip off 4 parts (i.e. a/typo3conf/ext/my_ext)
# --directory -> new path prefix (i.e. packages/my_ext)
# --ignore-space-change (if necessary)
git am --whitespace=nowarn --3way -p4 --directory='packages/my_ext' < 0001-Commit-message-123.patch

# maybe you need to resolve conflicts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment