Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge no common commits into master branch?

Tags:

git

tfs

git-tfs

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.

like image 519
m00nbeam360.0 Avatar asked Oct 16 '15 03:10

m00nbeam360.0


People also ask

Can you merge without committing?

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.

What is git merge -- no FF?

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.

Why you should rebase instead of merge?

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 .


1 Answers

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.

like image 106
m00nbeam360.0 Avatar answered Sep 18 '22 18:09

m00nbeam360.0