0

We are migrating from TFS VC using git-tfs. However, because of the nature of our branches (some branches were created by copying the folders, and not via branching), we could not migrate all the TFVC history. As such, our migrated branches do not share the same base.

To simplify the problem, this is our current situation:

  • two branches in our TFVC server, qc and release.
  • the same two branches in git, but as unrelated branches
  • if today in TFVC I want to merge from qc to release, it shows 5 changed files
  • However, I cannot merge from qc to release in git, as the branches are not related.

I can run git merge qc --no-commit --no-ff --allow-unrelated-histories and solve the conflicts. That works fine. However, I need to create an initial merge first that only "connects" the branches, to then do a git merge qc and see the same 5 changed files, with the same diffs.

The reason for that is that we are still running git-tfs to synchronize. The developers need to get used to git (they have been working with TFVC since always, so now they are learning it). At some moment we will stop synchronizing, to start working with the git server. That's why we need to "fake" the history between the branches, or do a big merge that does not contain this 5 files, to then do another merge to show exactly the same differences as in TFVC.

Thanks in advance!

jparaya
  • 1,331
  • 11
  • 15
  • If you know what is the last common commit between the branches, a better solution is surely to use `git replace --graft` to link the 2 branches. If the result suits you, don't forget to do a `filter-branch` before sharing the result. – Philippe Jun 08 '20 at 22:45
  • It's a good question. I will try to take the time to add this case in the git-tfs documentation... – Philippe Jun 08 '20 at 22:46

2 Answers2

0

Checkout qc. Copy the five troublesome files elsewhere. Checkout the 5 files from release, thus overwriting them in qc so they are the same in both branches. Add and commit.

Now checkout release and do the merge.

Now checkout qc again and copy the five troublesome files back into place, overwriting them with the troublesome contents. Add and commit.

Now checkout release again, and merge again, resolving as needed.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thanks matt. I was struggling with git commands and so, when the solution was way simpler. Thank you so much! – jparaya Jun 07 '20 at 17:23
0

One answer has already been approved but you might have also considered to rewrite history of the child branch on its first revision so that it pointed to whatever revision from the parent branch it was started. Something like:

git checkout first-revision-child-branch
# working in detached HEAD
git reset soft revision-of-parent-branch-where-child-branch-was-copoed-from
git commit -m 'first revision of child branch's
# replicate all the revisions of the child branch
git cherry-pick first-revision-of-child-branch..child-branch
# if you like the result
git branch -f child-branch
git checkout child-branch

Now the branches are related.

eftshift0
  • 26,375
  • 3
  • 36
  • 60