1

I need to do the inverse of this question.

So almost a year ago we split our Git repository off from itself by copying the current state of both branches into a new repository. To make it simple:

<== 2015 Dec              1 Jan                    2016 Jan ==>
Past history, till SVN    New Repo First Commit    All commits to present

We will soon be using subtrees to turn each of the projects in this repository into its own Git repository, but I do not want to do that so long as we are missing 5 years of our commit history in our central repository. Here are the steps I've tried so far:

cd ProjectFull/
git reset --hard # Project was in a branch
git checkout master # Go to master before trying to rebase
git remote add ProjectSplit ../ProjectSplit # New repository is in another directory
git fetch ProjectSplit # Fetch new repository
git cherry-pick <initial commit hash> --strategy-option theirs
git pull --rebase -s recursive -X theirs origin master

My idea was to cherry-pick the new repo's initial commit and then rebase off of that commit, but that fails. The commands I've listed above do not error out, but they delete all of the history of the old repository.

Here's a truncated log of my Git rebase:

$ git rebase origin dev
First, rewinding head to replay your work on top of it...
Applying: Merge branch 'dev' of <REPO> into dev
Using index info to reconstruct a base tree...
<stdin>:298480: trailing whitespace.

<stdin>:298553: trailing whitespace.

<stdin>:298559: trailing whitespace.

<stdin>:298565: trailing whitespace.

<stdin>:298571: trailing whitespace.

warning: squelched 1751272 whitespace errors
warning: 1751277 lines add whitespace errors.
Falling back to patching base and 3-way merge...

CONFLICT (add/add): Merge conflict in <FILE>
Auto-merging <FILE>
CONFLICT (add/add): Merge conflict in <FILE>
Auto-merging <FILE>
CONFLICT (add/add): Merge conflict in <FILE>
Auto-merging <FILE>
CONFLICT (add/add): Merge conflict in <FILE>
Auto-merging <FILE>
CONFLICT (add/add): Merge conflict in <FILE>
Auto-merging <FILE>
<Same>

Failed to merge in the changes.
Patch failed at 0001 Merge branch 'dev' of <REPO> into dev
The copy of the patch that failed is found in:
   ProjectFull/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

The script in this answer failed halfway through the old repo's patches.

This answer only works for dissimilar repositories.

Community
  • 1
  • 1
NobleUplift
  • 5,631
  • 8
  • 45
  • 87
  • How does the rebase fail? Any message? This looks like a rebase scenario to me. – harmonica141 Jul 21 '16 at 19:43
  • Sorry for the late reply @harmonica141, I didn't start working on again until today and now needs to be done soon so it has my focus again. – NobleUplift Aug 08 '16 at 21:39
  • a) Were you able to trace this whitespace error? b) Is the content of the folder mentioned in `The copy of the patch that failed is found in: ProjectFull/.git/rebase-apply/patch` of any help? What does it contain? Only one commit in there? – harmonica141 Aug 09 '16 at 10:42
  • @harmonica141 I don't think the whitespace errors are at fault. I've done many Git patches before and they've never been an issue. I believe the issue is with the `CONFLICT (add/add)`, which I have no idea what that means. Also, the patch file is 5 MB so there are many, many commits in it. – NobleUplift Aug 09 '16 at 14:49

1 Answers1

1

Your mileage may vary and I may well have misunderstood the question and your intent, so I'll propose options with short summary:

Consider stitching repos

Perl CPAN has git-stitch-repo, nice module that streamlines git fast-export to git fast-import.

Should linearize history.

Subdir option

Have two dirs instead of one. Or multiple dirs.

You are following procedure for that already. Abandon final cherry-picking from your question and just have old repo as a directory along current one.

Least troublesome, just glues repos together. Doesn't try linearizing history.

Git subtree merge

Merge subtree is a Git command, easier to use than both subtrees and submodules (and less administer-heavy).

You may need to then use --follow when looking at git log for individual files (after the merge).

Reexamine why you need it

Are you certain it will be helpful? If you feed that old Git log to ELK, would indexed search fit your colleagues (and yourself) better? With possibility of setting some dashboards in Kibana? Or if you set git instaweb on a machine with old repo, so that folks can browse it through web, will it perhaps meet your demands?

Consider git merge-repos

Never tried, so can't recommend, but it's apparently for just such an occasion and it was written when git-stitch-repo was young. May be worth checking out.

With some rewrite

There is also an option with some history rewrite, with git filter-branch. Probably can be done with BFG as well.

  • I'll check into all of these tomorrow morning. – NobleUplift Aug 09 '16 at 22:31
  • I tried `git-stitch-repos` last week but my repository has many merges between master and dev, so it didn't work. Next I tried `git merge-repos` but it just puts both folders at the top level of the repo (ProjectFull, ProjectSplit) which would disallow me from retaining both the Full and Split history when each of the subfolders for these repos is made into its own repository. – NobleUplift Aug 15 '16 at 17:59