Dowemo
0 0 0 0


Question:

I have a project where I've merged in a library using Git subtree. I've pushed and pulled a few minor changes between the library and the project.

Later on, a new repository has been created which is the definitive home for the library. It contains essentially the same version of the library code as my project did, with perhaps one or two minor changes. For various reasons, it doesn't share any direct Git history with the previous home of the library (it is not a clone of the previous library).

What I want to do now is change my project so that it pulls/pushes the library from the new location. The first time this happens I also need to resolve any merge conflicts, although in this case the changes are trivial and they could just be redone later.

What is the best way to do this?

I tried deleting taking a copy of the the library in my project, then removing it along with the old remotes and branches. I then tried doing subtree add etc from the new location. This seemed to work, but when I try to push back from my project to the library I'm getting a fatal bad object error.

I assume that there's a flaw in the approach that I've tried - probably to do with the lack of a shared history - but I don't quite have a deep enough understanding of what's going on to know how to fix it, or what the "proper" approach to this problem should be.

[update: edited the question to make it slightly clearer - it was a bit ambiguous]


Best Answer:


Perhaps, you should set up a separate working branch (or repositiory) with your version of the library (only the library tree with your changes) which you could then push back to the original library repo.

So, in order to push to the original remote repo, first prepare locally what you expect to appear as a commit remotely; there can be different workflows to achieve this: either, during the work on your project, you first commit your library changes to your special local working branch dedicated to the library (that branch should inherit the original history of the library), and then merge this branch with the library changes into your project working branch (where the library is a subtree), or merge your changes back from the project working branch into the dedicated library working branch. Then you can push your dedicated library working branch to the original remote repo when you wish.

So, essentially, first you create a local dedicated working branch so that it inherits the original history:

git branch MY_LIBFOO REMOTE_BRANCH_LIBFOO

(REMOTE_BRANCH_LIBFOO is your locally strored remote branch that interests you, which is updated by git fetch)

then, following your workflow, make sure that your changes to the library are in the working branch MY_LIBFOO, and then you can

git push original_libfoo MY_LIBFOO:TARGET_BRANCH_REMOTELY

This way, there is a clear idea of what is happening.




Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs