문제

I have an app which include a Github repository (vendor/one) as a sub-module. I fork vendor/one to me/one on Github to share my changes and sending pull requests.

Locally, I set up the sub-module as:

cd ~/Projects/app
git submodule add https://github.com/me/one.git Libraries/One
cd Libraries/One
git remote add upstream https://github.com/vendor/one.git

As time goes ...

  • I have push origin master a few times
  • there are some new commits in vendor/one repository

At a point, I'd to like merge with vendor/one for new features and patches, also I'd like to preserve commits of me/one. So what I plan to do:

cd ~/Projects/app
cd Libraries/One
git branch temp
git checkout temp
git fetch upstream
git merge upstream/master
(conflicts expected)
(resolve conflicts)
(merge temp with master)
push origin master

Does the above workflow make sense? Is there a tutorial or best practice somewhere?

도움이 되었습니까?

해결책

I would recommend rebasing instead of merging here: you replay your commits on top of upstream/master, preserving the history of master as being the mirror image of upstream/master (plus all your own commits).
That will also make a future pull request trivial for upstream to apply, since your commits will simply be on top of the most recent version of upstream/master.

That will involve a for push, but since it is your fork, you are likely to be the only contributor on that repo anyway.

cd ~/Projects/app
cd Libraries/One
git fetch upstream
git rebase upstream/master
(conflicts expected)
(resolve conflicts)
push -f origin master

다른 팁

Submodules

When you clone a submodule into your repository, it will have its own .git/config file and its own notion of origin. Assuming that the submodule is yours (e.g. there is no third-party repository upstream of your remote) then you don't need to worry about creating an upstream remote for the submodule.

If you do need to create an upstream remote for your submodule, it's easy enough. Just cd into the top-level directory of your submodule, and give it one the same way you did for the main repository.

cd myForkOfOtherProject
git remote add upstream git://example.com/otherProject.git

There is no namespacing conflict, because a submodule is really just a normal git repository with some additional meta-information tracked in the superproject. The superproject and the submodule do not share their .git/config files.

For all intents and purposes, you handle origin and upstream inside the submodule the same way you do for any other repository. Git commands that you run inside the submodule are independent of the superproject, which is mostly interested in tracking the submodule's current commit ID.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top