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.
With --no-commit perform the merge and stop just before creating a merge commit, to give the user a chance to inspect and further tweak the merge result before committing. Note that fast-forward updates do not create a merge commit and therefore there is no way to stop those merges with --no-commit.
The Git merge --no-ff command merges the specified branch into the command in the current branch and ensures performing a merge commit even when it is a fast-forward merge. It helps in record-keeping of all performed merge commands in the concerning git repo.
The Rebase Option But, instead of using a merge commit, rebasing re-writes the project history by creating brand new commits for each commit in the original branch. The major benefit of rebasing is that you get a much cleaner project history. First, it eliminates the unnecessary merge commits required by git merge .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With