I have several repositories with "just the same" package.json and several config files. I have changes made in one repository and want to spread this changes on others. I managed to do just the right thing following these instructions:
- git format-patch HEAD^ (from repo with changes)
- git remote add patch repo/with/changes (from repo that needs changes)
- git fetch patch (from repo that needs changes)
- git am -3 path/to/patch/patch --ignore-whitespace --ignore-space-change (from repo that needs changes)
- merge conflicts by hands (visual tool)
The problem is with the last step -- I want to automise this one too. Is it possible to define some merge strategy like "merge ours on lines connected with patch, merge theirs on every other conflicted line"? I have rather simple conflicts on package.json file, where conflicting lines are rather from patch (I want these to have), or from package-name and versions of some packages (I want this to leave as it was for the package).
I know, it is better to think of a way how to avoid duplicating and move similar files to some shared package, but yet I have no idea how it can be done for parts like "package.json" and if it's worth it. Any suggestions on this issues are also very appreciated, but the main focus is still on "as-it-is-now" problem with patch. Or maybe some other ways to spread changes on almost coinciding parts of different repos.
The example of thing I want to automerge looks like this (ex. in package.json, other files merged without conflicts and get changes from patch, but I guess in other cases there can be similar problems in other files too)
From first repo (patch origin)
{
"name": "packageA",
...
script A: "..." // <- patch changed something here
... // <- patch changed something here
script C: "..." // <- patch changed something here
...
dependencies: {
somePackage: "versionA"
}
}
From second repo
{
"name": "packageB", // <- here is conflict, I want to leave "package B"
...
script A: "..." // <- here is conflict, I want to get it from patch
... // <- here is conflict, I want to get it from patch
script C: "..." // <- here is conflict, I want to get it from patch
...
dependencies: {
somePackage: "versionB" // <-- here is conflict, I want to leave "versionB"
}
}