14

We have a repository, git-flow based, where we added an external library as a subtree (using Atlassian SourceTree's git subtree) on the development branch.

Project/
  Library/
    X/
    Y/
    Z/

Later we did a git flow release, merging the changes from develop into master (release).

The problem is when checking out master, the contents of Library get placed on the root of the repository instead of inside Library, like it had lost the git subtree prefix during the merge.

Project/
  X/
  Y/
  Z/

Any idea what's gone wrong?

Ramon Poca
  • 1,889
  • 1
  • 10
  • 19
  • are you sure it was first in a subfolder? What happens if you create a new branch out of the old master and try the whole thing again, does it happen again? – iberbeu Dec 09 '14 at 17:05
  • Yes it is. In the development branch is on a subfolder. It was the git-flow release process that seems not to have preserved the subtree pointer. – Ramon Poca Dec 10 '14 at 17:16
  • 2
    Sort of a dumb question but where is your .git folder located? – Mobile Ben Dec 16 '14 at 01:34
  • 2
    How did you "added an external library as a subtree"? file copy, git clone, git submodule ? – sax Dec 16 '14 at 08:04
  • As any git repo, it's in the root of the repository. – Ramon Poca Dec 16 '14 at 15:39
  • The external library was added using "git subtree". – Ramon Poca Dec 16 '14 at 15:40
  • 2
    I've had the same. Steps were as documented for using git subtree. `git remote add $PROJECT_NAME $GIT_URI; git subtree add --prefix=$PROJECT_PATH $PROJECT_NAME $PROJECT_BRANCH` so far so good. However, the next time I ran `git pull # (no explicit remote or branch)` the contents of the second remote repo were also pulled into my main project root. I suspect it's something to do with the git remote tracking options, as ANY remote is considered a valid peer, and ... they all get pulled. My git config says `fetch = +refs/heads/*:refs/remotes/$PROJECT_NAME/*` and I suspect that's it. – dman May 13 '15 at 02:10

1 Answers1

1

The subtree itself has its own root directory on its own branch. See http://git-scm.com/book/en/v1/Git-Tools-Subtree-Merging, especially:

You want to pull the Rack project into your master project as a subdirectory. You can do that in Git with git read-tree. You’ll learn more about read-tree and its friends in Chapter 9, but for now know that it reads the root tree of one branch into your current staging area and working directory. You just switched back to your master branch, and you pull the rack branch into the rack subdirectory of your master branch of your main project:

$ git read-tree --prefix=rack/ -u rack_branch

user2622016
  • 6,060
  • 3
  • 32
  • 53
  • That describes the subtree merging strategy, I'm using git-subtree (See https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt). – Ramon Poca Dec 16 '14 at 16:58