Reputation: 15
So I currently have 2 repos:
repoA:branchA
repoB:branchB
Codewise they're identical, but the history on the branches are diff. When I do work I do purely in repoB:branchB (so open a PR, get approved, merge). After that's done I want to mirror that "merge" commit over to repoA:branchA. How would I get this done? Considering they have different histories? Maybe I can just cherry pick a commit? So overall, I want to sync repoA:branchA and repoB:branchB even though they have different histories. I just need specific commits copied over from repoB:branchB to repoA:branchA.
Thank you!
Upvotes: 1
Views: 68
Reputation: 487755
History, in Git, is the commits in the repository. History is formed by taking the last commit in each branch—as found by the branch's name—and working backwards through the backwards-pointing chain, in which each commit identifies its parent by hash ID. All the commits that you can reach in this way, or from any other name, such as a tag name, are part of the repository. For more about this, see Think Like (a) Git.
You can make a repository with multiple different histories—different, disconnected graphs—by using git fetch
to a remote or URL with the other history. These histories are difficult to merge, because of the lack of common ancestors, but git cherry-pick
still works on them. Pick a commit, use git cherry-pick
to treat its immediate parent as a sort of merge base, and Git will do a three-way merge between that commit's parent, that commit, and your current commit.
Hence, if you're in repo A, and the change you want is in repo B between commits P and C (where C is the child), you might run:
git fetch <url-of-repo-B>
git cherry-pick <hash-of-C>
Note that this brings in the entire history from repository B. That's harmless, except for the fact that your repository will temporarily be much bigger. Eventually, these commits, if unreferenced, will age out and be garbage collected.
Upvotes: 1