Merge no common commits into master branch?
Asked Answered
A

1

16

I have a Git repo that has a lot of commits and separate code, say

/Proj1

I also have another Git repo that has 1 commit in it that is not a common commit,

/Proj2

How can I merge the two repos and have history show up correctly with parent commits? Basically, there aren't any shared commits between the two repos but I want to have one repo that has both sets of code. I'd like for it to look like:

proj2 commit
proj2 commit
proj1 commit (root)

I know that rebase is an option, but not sure if using --onto replaces the root commit (which it seems to do if I do a fetch from the remote repo and rebase --onto --root master).

I've tried using git subtrees which initially look like they work, but when I use git-tfs to push my commits up, but I'm getting an error that says

warning: the parent ... does not belong to a TFS tracked branch (not checked in TFS) and will be ignored

and the commits don't actually push up (also likely because it's a subtree).

Edit: I only want to end up with 1 repo (Proj1) but have Proj2's commits come after Proj1's commit on the master branch.

Aplenty answered 16/10, 2015 at 3:50 Comment(11)
You should have one Git repository per project. Why would you want to merge them?Zenaidazenana
Git + TFS? You poor, poor soul.Hedges
I've edited my question. There is basically 2 sets of code that are in different repos (no common commits), and I'd like to have history of the 2nd repo move into the 1st repo.Aplenty
@Cupcake git-tf better?Aplenty
It was a joke, don't mind me ;)Hedges
Haha no worries, only using git-tfs for a few steps!Aplenty
It's moments like these were I wish high-rep users could invite low rep users to chat. Please explain what the directory/structure of project 1 and 2 are. Are they actually the same project, just in two separate repos? Or are they two completely different projects, and you're trying to use one project in the other (like importing an external library, and thus the subtrees)? I'm not sure if TFS supports Git subtrees, might be something that's worth looking up.Hedges
If TFS doesn't support subtrees, it would not be difficult to rebase the history of one project into the history of another. The --root option shouldn't be necessary, unless you want to edit the root commit...it's been a while since I've done this sort of thing, so I'll need to double check. Although this would not be a difficult thing to do in Git, however, I don't know how such a change will be received by TFS.Hedges
If you wanted to rebase one history tree on top of the other, the correct command to use would be git rebase --onto master --root otherMaster. In such a case, the root of otherMaster is transplanted onto the tip of master, and assuming that there are no conflicts, its code state will not be altered by the rebase.Hedges
Thanks for your suggestions, Cupcake. TFS does actually support subtrees last that I checked. Two different projects and trying to use one project in the other. I used git subtrees add --prefix='{name}" and it looked like after that, the git-TFS tool wouldn't accept the commits in the subtree's history (maybe that's a git-TFS issue?).Aplenty
Ah, you fixed it, @Cupcake! Turns out that I was mixing up the order of the rebase switches. :)Aplenty
A
21

Cupcake helped solve this one. Here's one way to do this:

In ProjA, add Proj B as a remote:

git remote add projb C:\projB

Do a git fetch to grab all of the commits of projB's master branch:

git fetch projb

Rebase starting from the root of projB onto the tip (end) of projA's master branch:

git rebase --onto master --root projb/master

And that's it! There are potentially less risky ways to perform this, but this definitely solves it for now.

Aplenty answered 16/10, 2015 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.