在 GitHub 上分叉存储库的子目录并将其作为我自己存储库的一部分 [英] Forking a sub directory of a repository on GitHub and making it part of my own repo

查看:24
本文介绍了在 GitHub 上分叉存储库的子目录并将其作为我自己存储库的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,我对 Git 和 GitHub 非常陌生,我已经阅读了一些内容,但我不确定我正在尝试做的事情是否完全可能.

Apologies, I am very new to Git and GitHub, I've read through a few things but I'm not sure if what I'm trying to do is entirely possible.

基本上我想分叉 XBMC 上使用的 Confluence Skin 并修改位于此处的各种元素:

Basically I want to fork the Confluence Skin used on XBMC and modify various elements located here:

https://github.com/xbmc/xbmc/tree/master/addons/skin.confluence

但是我不想 fork 整个 XBMC 存储库,所以简单的 fork 操作是行不通的.

However I don't want to fork the entire XBMC repository, so a simple fork action won't do.

以下是我的一般要求:

  • 我想把skin.confluence文件夹中的内容放到我自己的GitHub账户上的一个仓库中

  • I would like to take the contents of the skin.confluence folder and put it into a repository on my own GitHub account

我需要能够将其链接到原始 XBMC 存储库中以接收上游提交,因为我的修改通常基于主题,而不是基于功能.

I need to be able to keep it linked within the original XBMC repo to receive upstream commits, as my modifications will generally be theme based, rather than functionality.

感谢 tbekolay 发布的响应,我已经能够进行子树拆分以仅获取 repo 的 skin.confluence 部分并基本上创建一个分支,但是我不确定如何使其与原始 XBMC 保持联系存储库,同时通过我的修改推送到我自己的存储库.

Thanks to the response posted by tbekolay, I have been able to do a subtree split to take only the skin.confluence part of repo and essentially create a branch, however I am unsure on how to keep it linked with the original XBMC repo while being pushed to my own repo with my modifications.

推荐答案

这在 git 中几乎是可能的,尽管它不是典型的用例,因此可能会有一些粗糙的边缘这个(特别是如果你是 git 的新手).

This is mostly possible with git, though it is not a typical use case, so there may be some rough edges as you do this (especially if you are new to git).

我们将用于这项工作的工具是 git subtree.

The tool that we'll use for this job is git subtree.

首先克隆整个 XBMC 存储库.

Start by cloning the whole XBMC repository.

git clone https://github.com/xbmc/xbmc.git
cd xbmc

我们默认从 master 分支开始.我们要创建自己的master 分支,所以让我们将master 重命名为upstream-master.

We start on the master branch by default. We want to make our own master branch, so let's rename master to upstream-master.

git branch -m upstream-master

现在使用 git subtree split 只包含你想要的部分.我们将分离出来的部分创建一个名为 upstream-skin 的新分支.

Now use git subtree split to only include the part that you want. We'll make the split off part a new branch called upstream-skin.

git subtree split --prefix=addons/skin.confluence -b upstream-skin
git checkout upstream-skin

这为您提供了一个新的 upstream-skin 分支,它只包含 addons/skin.confluence 的内容,并带有一个过滤的历史记录,其中只包含修改过的提交addons/skin.confluence 中的文件.

This gives you a new upstream-skin branch that only contains the contents of addons/skin.confluence, and with a filtered history that contains only the commits that modified files in addons/skin.confluence.

现在,让我们设置遥控器.由于您克隆了 xbmc/xbmc.gitorigin 远程将指向那里.让我们将其重命名为 upstream.

Now, let's set up our remotes. Since you cloned xbmc/xbmc.git, the origin remote will point there. Let's rename that to upstream.

git remote rename origin upstream

在 Github 上创建一个存储库以包含您对 addons/skin.confluence 的修改.例如,我将使用 tbekolay/xbmc-skin,但将其替换为您自己的存储库.将此存储库添加为远程,并将您的 upstream-skin 分支推送到它.

Make a repository on Github to contain your modifications to addons/skin.confluence. As an example, I'll use tbekolay/xbmc-skin, but replace this with your own repo. Add this repo as a remote, and push your upstream-skin branch to it.

git remote add origin https://github.com/tbekolay/xbmc-skin.git
git fetch origin
git push -u origin upstream-skin

最后,我们将创建一个名为 master 的新分支,其中将包含您的更改.

Finally, we'll make a new branch called master that will contain your changes.

git checkout -b master
git push -u origin master

您现在拥有 addons/skin.confluence 子目录的分支".

You now have a "fork" of the addons/skin.confluence subdirectory.

当您处理自己的本地和远程存储库时,您可以使用普通的 git 命令.确保在 master 分支(或其他一些分支,如果你愿意)而不是 upstream-skin 分支上这样做,它应该只包含来自上游项目.

When you're dealing with your own local and remote repositories, you can use normal git commands. Make sure to do this on the master branch (or some other branch, if you'd like) and not the upstream-skin branch, which should only ever contain commits from the upstream project.

git checkout master
echo "My XBMC Skin" > README
git add README
git commit -m "Added README"
git push

接收上游提交

当您处理上游存储库时,您必须混合使用 gitgit subtree 命令.要获得新的过滤提交,我们需要分三个阶段进行.

Receiving upstream commits

When you're dealing with the upstream repository, you will have to use a mix of git and git subtree commands. To get new filtered commits, we need to do it in three stages.

在第一阶段,我们会将 upstream-master 更新到 XBMC 存储库的当前版本.

In the first stage, we'll update upstream-master to the current version of the XBMC repository.

git checkout upstream-master
git pull

这应该会拉下新的提交,如果有的话.

This should pull down new commits, if there are any.

接下来,我们将使用提交的新过滤版本更新 upstream-skin.由于 git subtree 确保提交哈希是相同的,所以这应该是一个干净的过程.请注意,您希望在 仍在 upstream-master 分支上运行这些命令.

Next, we will update upstream-skin with the new filtered version of the commits. Since git subtree ensures that commit hashes will be the same, this should be a clean process. Note that you want to run these commands while still on the upstream-master branch.

git subtree split --prefix=addons/skin.confluence 
  --onto upstream-skin -b upstream-skin

随着 upstream-skin 现已更新,您可以根据需要更新您的 master 分支(通过合并或重新定位).

With upstream-skin now updated, you can update your master branch as you see fit (either by merging or rebasing).

git checkout master
git rebase upstream-skin

<小时>

请注意,XBMC 存储库是巨大的,git subtree 命令将花费相当多的时间来过滤所有历史记录——而且由于您每次都在重新生成拆分子树与远程存储库交互,这是一项非常昂贵的操作.我不确定这是否可以加快速度.


Note that the XBMC repository is gigantic, and the git subtree commands will take quite a bit of time to filter through all that history -- and since you're regenerating the split subtree each time you interact with the remote repository, it's quite an expensive operation. I'm not sure if this can be sped up.

这篇博文 更详细地介绍了上述命令.另请参阅 git-subtree 文档 了解更多细节.

This blog post goes into some more detail on the commands above. Also see the git-subtree docs for even more detail.

这篇关于在 GitHub 上分叉存储库的子目录并将其作为我自己存储库的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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