Assume I clone a repository OSS
at version 1.0 containing a class A
. Subclassing A
is not enough for me, so I copy A
to A'
and make some modifications to it. At a later point in time, I clone OSS
at version 1.1
, containing an updated version of A
. How can I merge the changes/updates from A
to my modified copy A'
? Is there a standard pattern for such cases?
Asked
Active
Viewed 102 times
6

stefan.at.kotlin
- 15,347
- 38
- 147
- 270
-
3Why do you copy `A` instead of directly modificating it? It would be easier to pull the changes from upstream and rebase your modifications on top of them. – bfontaine Aug 19 '20 at 16:45
-
2`A` is a UI widget and I need both, the original and a modified version of it – stefan.at.kotlin Aug 19 '20 at 16:59
1 Answers
6
The idea is to:
create the patch using
git diff
: between A#1.0 and 1#1.0git diff 1.0 1.1 -- A > a.patch
then apply that patch using the
patch
utility: you can specify the file you want to apply the diff to withpatch
.patch -p1 A' a.patch
On Windows, use a simplified PATH as in here, and you will see patch available:
C:\git\>where patch
C:\prgs\gits\current\usr\bin\patch.exe

VonC
- 1,262,500
- 529
- 4,410
- 5,250
-
thanks for your reply. I could execute the first command, but failed for the second one, as I am on Windows (no patch command). Any way to apply the patch using Git? – stefan.at.kotlin Aug 22 '20 at 12:40
-
@stefan.at.wpf If you installed GIT under Windows then launch 'Git Bash' and you will find that you do have a `patch` command. – Booboo Aug 22 '20 at 12:53
-
@stefan.at.wpf I have edited the answer to add the right Windows `%PATH%` for you to use `patch`. – VonC Aug 22 '20 at 14:16
-
Thank you both :-) My first limited test looks promising, actually I feared that `patch` would complain because of different class names, but somehow patch seems to be intelligent enough to detect that `A'` is just mentioned at the places were earlier `A` was mentioned, great. I will do some more testing if it also works for more advanced cases. – stefan.at.kotlin Aug 22 '20 at 14:47
-