Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to push to a new subrepo which has some initial commits #145

Open
robe070 opened this issue Feb 12, 2016 · 4 comments
Open

How to push to a new subrepo which has some initial commits #145

robe070 opened this issue Feb 12, 2016 · 4 comments
Labels

Comments

@robe070
Copy link

robe070 commented Feb 12, 2016

How do you push to a new subrepo which has some initial commits?
The subrepo init works.
The subrepo push or subrepo pull both fail with this:

git-subrepo: Can't find a common ancestor between refs/subrepo/shared/fetch and subrepo-push/shared. This might be the case if someone used push --force on the subrepo. You need to find out why and possibly reclone the subrepo.

Documentation states that the remote branch must be "properly merged".

I have performed a git pull into the parent project and that made no difference.

@grimmySwe
Copy link
Collaborator

How do you push to a new subrepo which has some initial commits?

Do I understand this correctly in that you first perform git subrepo init <subdir> but you set the remote to an already existing repository?

Current solution will try to find a common ancestor and as stated in the error message it can't be found, why? Because it can't find commits with equal tree hash between the two repos. Think of it as trying to merge two separate branches with no common ancestors.

One way to solve this would be:

  1. move the subrepo dir from inside the project to a temporary location.
  2. clone the subrepo that you want to connect to into the project. This way you will have a common ancestor.
  3. move the new .gitrepo file to temp location
  4. replace the subrepo dir inside project with the one in 1
  5. replace the .gitrepo file inside the subrepo dir with the one in 3
  6. commit the changes in the project

Example:

$ cd project
$ mv subdir /tmp/
$ git subdir clone <subrepo> subdir
$ mv subdir/.gitrepo /tmp/
$ rm -rf subdir
$ mv /tmp/subdir .
$ mv /tmp/.gitrepo subdir/
$ git add .
$ git commit -m "Created a common ancestor for subrepo"

@robe070
Copy link
Author

robe070 commented Feb 12, 2016

thanks. I'm learning fast, I hope :)
For my purposes I've found by far the fastest method is to copy my bigrepo, run this on it:

git filter-branch --prune-empty --subdirectory-filter subdir currentbranch

And then pull the result into a new repo.

This takes minutes (for small number of commits out of the 30,000 total) rather than an hour with subrepo and 6 hours with subtree.

After I've extracted all my subdir from the bigrepo I can pull them all into a new project repo with subrepo to reconstitute the original bigrepo. With all the commits squashed I believe it will run much quicker.

This completely avoids the common ancestor issue.

Do you see any issues with that this strategy?

@grimmySwe
Copy link
Collaborator

Looks good to me.

One question though, I was under the impression that you had an existing repo that you wanted to use for your subrepo?

@robe070
Copy link
Author

robe070 commented Feb 13, 2016

Just a few standard files. When I pull the subdir into the 'new' repo it warns there are no common commits. I also get progress reported by filter-branch. And one of my subdir would not subtree push to an empty repo.

Thanks for your help.

Suggestion for the wiki - when pushing and no common ancestor is reported, if its really OK, just pull the subdir branch into the new repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants