7

I hope this does not seem to obvious. I have two git repository. We decided to split one branch from the first repoistry into a git sub module. Now I have been using this sub module, however people have been pushing commits to the first repository into the branch that was made into a sub module.

How can I merge the changes from the branch in the first repository into newly created second repository? (Which we now use as the sub-module)

I have tried adding another remote into the second repo and merging that branch across, using:

git remote add otherOrigin git-Blah@blah.blah:originalRepo.git
git merge otherOrigin originalBranch

However I get:

fatal: 'otherOrigin' does not point to a commit

Thanks

Karussell
  • 16,303
  • 14
  • 88
  • 188
binarycreations
  • 2,922
  • 5
  • 28
  • 37

2 Answers2

2

If the two repos, for the given branch (the one split as a sub-module in Repo1, while being kept in Repo2), initially have a common history, then it should be possible, in theory, to:

  • split the branch in Repo2 as an individual repo
  • add that individual repo as a remote of the current submodule repo
  • try and perform the merge from there.

But that can quickly become a drag if you have to repeat that process on a regular basis (unless you can script it).

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • ...and then whack people over the head for repeatedly messing it up. ;-) – ebneter Jun 22 '11 at 01:21
  • 2
    Sorry I didn't accept this earlier, I was too busy whacking people over the head – binarycreations Jan 30 '12 at 21:23
  • 1
    @Graham: no problem. I had answers accepted more than *three* years after being posted ;) And I am not too sure if I want to know what they were busy doing during that time... – VonC Jan 30 '12 at 21:57
1

clone your repository. Now use filter-branch to just keep the changes to what should be in your submodule. add this repo as a remote of your submodule. fetch the branch from that new remote. Use git rebase --root --onto to "place" the changes to some point in the history of your submodule.

Hope this helps.

Adam Dymitruk
  • 109,813
  • 21
  • 138
  • 137