Question

I'm having a weird error with git 1.8.3 on Windows. Using git subtree, I took a file to be shared between two projects and pushed it to another repository.

So, in repo1 I did this:

# push script
git subtree split --prefix=shared-dir --rejoin --branch split
git push shared-repo split:master
git branch -D split

In both repos, shared-repo refers to the remote containing the shared code. The shared code would reside in a directory with the same name.

In repo2 I did this:

# pull script
git fetch shared-repo
git subtree merge --prefix=shared-dir shared-repo/master

What I expect it to do is to fetch the shared file and put it in repo2 under the directory ./shared-dir/. What happens is that the file is put in the root of the repository!

Moving the file to the correct folder, committing and executing something similar to the push script of repo1 results in a rejection in the push because it says that the push is not fast-forward. Running the pull script again says that everything is up-to-date.

I'm stomped and searching the internet didn't reveal anyone else having a similar problem. What's wrong and what can I do?


Update: the same happens with git 1.7.9.5 on Ubuntu 12.04 with the git-subtree script taken from the git repository some two weeks ago. I also changed the command to say --prefix=./shared-dir/ to no avail.

Interestingly, git subtree makes the shared-dir directory, but puts the shared file in the root directory instead of inside that directory.

Was it helpful?

Solution 2

The problem was that the first time adding the shared directory to the repository should be done with:

git subtree add --prefix=... .../...

OTHER TIPS

I had a similar problem on a git repo that i pulled from Github: git subtree pull was obliterating the contents of the repo. Adding the prefix with git subtree add --prefix did not work as the prefix was already added.

The only solution that worked for me was to obliterate the directory and then add the prefix again. Example:

rm -rf JSQMessagesViewController
# now commit all, then add
git subtree add --prefix JSQMessagesViewController https://github.com/jessesquires/JSQMessagesViewController master --squash
# Now the pull will work!
git subtree pull --prefix JSQMessagesViewController https://github.com/jessesquires/JSQMessagesViewController master --squash

A better solution would be welcome, of course.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top