如何将骨架子库的变化引入生产超级库 [英] How to pull in changes from skeleton sub-repository into production super-repository

查看:105
本文介绍了如何将骨架子库的变化引入生产超级库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Aurelia骨架,其中包含用于不同目的的各种项目设置,但它是更多关于如何使用下面所述的git来做一些事情的一般问题。



我希望能够将GitHub框架库中发布的更新合并到我正在实际使用的项目中。你会怎么做?



目前我刚刚在骨架打字稿项目(我正在使用)中初始化一个新的本地存储库,并将它连接到一个专用远程回购推动我的变化。但是通过这种设置,我正在污染父库(远程指向Github上的aurelia-skeleton),并进行了特定于项目的更改。



最好有一些作为aurelia骨架远程存储库的单向跟踪方式通常只用于拉取更改。



第二步,您将会很有趣用这样的设置创建一个拉请求。在这种情况下,我想使用我在子存储库中所做的更改将其合并到aurelia远程的分支中...

解决方案

我平时的工作流程是创建一个专门的分支,从中追踪上游项目。你可以选择你想要到那个分支上的东西,并创建一个请求,而不会混淆你的项目特定模板。






首先,请继续前进,并通过Github的GUI轻松地发出pull请求。



在名为 new 文件夹中使用远程命名为上游的项目的分支克隆skeleton-typescript $ b $ pre $ g $ git clone -o upstream git@github.com YOUR_GITHUB_USERNAME / skeleton-navigation.git skeleton-typescript

cd骨架打字稿

重命名主分支。

  git branch -m asmaster 

skeleton-typescript

创建一个新存储库

提示:您可以执行此操作直接从命令行使用 Github的API wi像 curl

  curl --data'{name:skeleton-typescript}'-u YOUR_GITHUB_USERNAME https://api.github .com / user / repos 

添加遥控器。

  git remote add origin git@github.com:YOUR_GITHUB_USERNAME / skeleton-typescript.git 

将repo拆分为子树(查看手册页的源代码),它将包含一个新的树,其中包含前缀目录中所有文件的提交历史记录。

  git subtree split --prefix = skeleton-typescript 

这将打印出一个提交ID,它是子树的 HEAD


539d913a8cf9b34b644273b5cdb480359553247c

从该提交创建主分支。

  git checkout -b master 



$ p
$ b

  git push -u origin master 



Backporting

h1>

> skeleton-typescript

  echo显着贡献>> file.txt 
git add。
git commit -mbackport test commit
git push origin master

  git checkout asmaster 
git cherry-检查上游超级项目分支,并挑选子树提交。 pick -x --strategy = subtree master
git push upstream asmaster:master

现在你可以从您的上游fork YOUR_GITHUB_USERNAME / skeleton-navigation:master 分支向它们的 aurelia / skeleton-navigation:master 发出pull请求c>分支。



更新



现在, c $ c> aurelia / skeleton-navigation:master ),其中包含对子树的 skeleton-typescript 文件夹的更新。



添加另一个远程来跟踪原始项目。

  git remote add upupstream git @ github。 com:aurelia / skeleton-navigation.git 

请注意,您现在在本地存储库中有3个远程控制台。

  git remote -v 




  origin git@github.com:YOUR_GITHUB_USERNAME / skeleton-typescript.git(fetch)
origin git@github.com:YOUR_GITHUB_USERNAME / skeleton-typescript.git(推送)
上游git@github.com:YOUR_GITHUB_USERNAME / skeleton-navigation.git(fetch)
上游git@github.com:YOUR_GITHUB_USERNAME / skeleton-navigation.git(推送)
上传git@github.com:aurelia / skeleton-navigation.git(获取)
上传git @ github .com:aurelia / skeleton-navigation.git(推送)


取消更新。

  git checkout asmaster 
git pull upupstream master



再次拆分子树并获取HEAD提交。

  git subtree split --prefix = skeleton-typescript 




095c0c9f7ed06726e9413030eca4050a969ad0af

切换回子项目。

  git checkout master 

如果您从未回溯过更改, git subtree split 的值得注意的属性是您将拥有完全相同的散列提交历史,因此您可以在不重写历史的情况下快速转发合并。从文档


完全相同历史的重复分割保证是相同的(即产生相同的提交id)。正因为如此,如果添加新的提交然后重新拆分,新的提交将作为提交附加到上次生成的历史记录的顶部,所以git合并和朋友将按预期工作。




  git merge 095c0c9f7ed06726e9413030eca4050a969ad0af 

但是,如果您已经向后移植了樱桃选择的更新或对子树历史记录的任何其他更改,那么您将需要重定义更改,否则将会有重复的提交。

  git rebase 095c0c9f7ed06726e9413030eca4050a969ad0af 


I am using the Aurelia skeleton which contains various project setups for different purposes, but it is more of a general question of how you would do something with git like discribed below.

I would like to be able to merge in the updates published in the GitHub skeleton repository to the project I am actually working on. How would you do that?

At the moment I just initialized a new local repository in the skeleton-typescript project (which I am using) and connected it to a private remote repo to push my changes. But with this setup, I am polluting the parent repository (remote pointing to aurelia-skeleton on Github) with my project-specific changes.

It would be perfect to have some kind of one-way tracking going as the aurelia-skeleton remote repository is normally only used to pull changes in.

As a second step, it would be interesting how you could create a pull request with such a setup. In this case, I would like to use the changes I made in the sub-repository to be merged into the fork of the aurelia remote...

解决方案

My usual workflow is to create a dedicated branch from which to track the upstream project. You can cherry pick what you want onto that branch and create a pull request without muddying the template with your project specifics.


First thing, go ahead and fork aurelia/skeleton-navigation so you can easily issue a pull request through Github's GUI.

Clone your fork of the project with remote named upstream in a new folder called skeleton-typescript

git clone -o upstream git@github.com:YOUR_GITHUB_USERNAME/skeleton-navigation.git skeleton-typescript

cd skeleton-typescript

Rename master branch.

git branch -m asmaster

Create a new repository for skeleton-typescript

Tip: You can do this right from the command line using Github's API with something like curl

curl --data '{"name":"skeleton-typescript"}' -u YOUR_GITHUB_USERNAME https://api.github.com/user/repos

Add the remote.

git remote add origin git@github.com:YOUR_GITHUB_USERNAME/skeleton-typescript.git

Split the repo into a subtree (see source code for man page) which will contain a new tree with all the commit history of files in the prefix directory.

git subtree split --prefix=skeleton-typescript

This will print out a single commit ID which is the HEAD of the subtree.

539d913a8cf9b34b644273b5cdb480359553247c

Create your master branch from that commit.

git checkout -b master 539d913a8cf9b34b644273b5cdb480359553247c

Push to and track your new repo.

git push -u origin master

Backporting

Commit some work on skeleton-typescript

echo "notable contribution" >> file.txt
git add .
git commit -m "backport test commit"
git push origin master

Checkout the upstream super-project branch, and cherry-pick the subtree commits.

git checkout asmaster
git cherry-pick -x --strategy=subtree master
git push upstream asmaster:master

Now you can issue a pull request from your upstream fork YOUR_GITHUB_USERNAME/skeleton-navigation:master branch to their aurelia/skeleton-navigation:master branch.

Updating

Now there's going to be updates no doubt to your upstream's upstream (aurelia/skeleton-navigation:master) which will include updates to your subtree's skeleton-typescript folder.

Add another remote to track the original project.

git remote add upupstream git@github.com:aurelia/skeleton-navigation.git

Note that you now have 3 remotes in your local repository.

git remote -v

origin    git@github.com:YOUR_GITHUB_USERNAME/skeleton-typescript.git (fetch)
origin    git@github.com:YOUR_GITHUB_USERNAME/skeleton-typescript.git (push)
upstream  git@github.com:YOUR_GITHUB_USERNAME/skeleton-navigation.git (fetch)
upstream  git@github.com:YOUR_GITHUB_USERNAME/skeleton-navigation.git (push)
upupstream    git@github.com:aurelia/skeleton-navigation.git (fetch)
upupstream    git@github.com:aurelia/skeleton-navigation.git (push)

Pull down updates.

git checkout asmaster
git pull upupstream master

Split off the subtree again and grab the HEAD commit.

git subtree split --prefix=skeleton-typescript

095c0c9f7ed06726e9413030eca4050a969ad0af

Switch back to subproject.

git checkout master

If you have never backported changes, then a notable attribute of git subtree split is that you'll have the exact same hash commit history, so you can fast forward merges without rewriting history. From the docs:

Repeated splits of exactly the same history are guaranteed to be identical (i.e. to produce the same commit ids). Because of this, if you add new commits and then re-split, the new commits will be attached as commits on top of the history you generated last time, so git merge and friends will work as expected.

git merge 095c0c9f7ed06726e9413030eca4050a969ad0af

However, if you have already backported cherry-picked updates, or any other changes to the subtree history, then you'll want to rebase changes, otherwise you'll have duplicate commits.

git rebase 095c0c9f7ed06726e9413030eca4050a969ad0af

这篇关于如何将骨架子库的变化引入生产超级库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆