如何将更改从骨架子存储库拉入生产超级存储库 [英] How to pull in changes from skeleton sub-repository into production super-repository

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

问题描述

我正在使用 Aurelia 框架,其中包含用于不同目的的各种项目设置,但它是更多关于您将如何使用 git 执行某些操作的一般性问题,如下所述.

我希望能够将 GitHub 骨架存储库中发布的更新合并到我实际从事的项目中.你会怎么做?

目前,我刚刚在 skeleton-typescript 项目(我正在使用)中初始化了一个新的本地存储库,并将其连接到一个私有远程存储库以推送我的更改.但是通过这种设置,我的项目特定更改污染了父存储库(远程指向 Github 上的 aurelia-skeleton).

最好进行某种单向跟踪,因为 aurelia 框架远程存储库通常仅用于拉取更改.

作为第二步,如何使用这样的设置创建拉取请求会很有趣.在这种情况下,我想使用我在子存储库中所做的更改合并到 aurelia remote 的 fork 中...

解决方案

我通常的工作流程是创建一个专门的分支来跟踪上游项目.您可以在该分支上挑选您想要的内容并创建拉取请求,而不会将模板与您的项目细节混淆.

<小时>

首先,继续 fork aurelia/skeleton-navigation,以便您可以轻松地通过 Github 的 GUI 发出拉取请求.

在名为 skeleton-typescript

new 文件夹中使用名为 upstream 的远程克隆项目的分支

git clone -o upstream git@github.com:YOUR_GITHUB_USERNAME/skeleton-navigation.git skeleton-typescriptcd 骨架打字稿

重命名主分支.

git branch -m asmaster

skeleton-typescript

创建一个新的存储库

提示:您可以使用 Github 的 API 类似 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 拆分成一个子树(见源码手册页的代码),它将包含一个新树,其中包含 prefix 目录中文件的所有提交历史.

git subtree split --prefix=skeleton-typescript

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

<块引用>

539d913a8cf9b34b644273b5cdb480359553247c

从那个提交创建你的主分支.

git checkout -b master 539d913a8cf9b34b644273b5cdb480359553247c

推送并跟踪您的新存储库.

git push -u origin master

向后移植

skeleton-typescript

上提交一些工作

echo显着贡献">>文件.txtgit 添加.git commit -m "backport test commit"git push origin master

检查上游超级项目分支,并挑选子树提交.

git checkout asmastergit cherry-pick -x --strategy=subtree mastergit push 上游 asmaster:master

现在,您可以从上游分支 YOUR_GITHUB_USERNAME/skeleton-navigation:master 分支向其 aurelia/skeleton-navigation:master 分支发出拉取请求.

更新中

毫无疑问,现在上游的上游 (aurelia/skeleton-navigation:master) 将会更新,其中包括对子树的 skeleton-typescript 文件夹的更新.

添加另一个遥控器来跟踪原始项目.

git 远程添加上游 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(获取)上游 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 asmastergit pull 上游大师

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

git subtree split --prefix=skeleton-typescript

<块引用>

095c0c9f7ed06726e9413030eca4050a969ad0af

切换回子项目.

git checkout master

如果您从未向后移植更改,那么 git subtree split 的一个显着属性是您将拥有完全相同的哈希提交历史记录,因此您可以在不重写历史记录的情况下快速向前合并.来自 文档:

<块引用>

完全相同历史的重复拆分保证是相同的(即产生相同的提交 ID).因此,如果您添加新提交然后重新拆分,则新提交将作为提交附加在您上次生成的历史记录之上,因此 git merge 和朋友将按预期工作.

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天全站免登陆