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

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

问题描述

道歉,我对Git和GitHub非常陌生,我已经阅读了一些内容,但我不确定我要做的是完全

>

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

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

然而,我不想分叉整个XBMC存储库,所以一个简单的fork动作不会这样。



以下是我的一般要求:


  • 我想借此skin.confluence文件夹的内容并将其放到我自己的GitHub帐户中的存储库中


  • 我需要能够将其与原始XBMC回购库以接收上游提交,因为我的修改通常是基于主题的,而不是功能。




感谢tbekolay发布的响应,我可以做一个子树拆分,只取得回购的skin.confluence部分,并且基本上创建一个分支,但是我不确定如何保留它与原来的XBMC repo相关联,同时被我的修改推送到我自己的repo中。

解决方案

c $ c> git ,尽管它不是一个典型的用例,所以当你这样做时可能会有一些粗糙的边缘(特别是如果你是 git

我们将用于这项工作的工具是 git subtree 。 p>

设置存储库



从克隆整个XBMC存储库开始。

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

默认情况下,我们从 master 分支开始。我们希望创建自己的 master 分支,因此我们将 master 重命名为 upstream-master

  git branch -m upstream-master 

现在使用 git subtree split 来只包含你想要的部分。我们将分成一个叫做 upstream-skin 的新分支。

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

这给你一个新的上游皮肤分支,它只包含 addons / skin.confluence ,并且过滤历史记录仅包含修改< addons / skin.confluence 中的文件的提交。



现在,让我们设置我们的遥控器。既然你克隆了 xbmc / xbmc.git ,那么 origin remote将指向那里。我们将它重命名为 upstream

  git remote rename origin upstream 

在Github上创建一个存储库,以包含对 addons / skin.confluence code>。作为一个例子,我将使用tbekolay / xbmc-skin,但用您自己的回购替换它。将此回购作为远程设备添加,并将您的上游皮肤分支添加到它。

  git remote add origin https://github.com/tbekolay/xbmc-skin.git 
git fetch origin
git push -u origin上游皮肤

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

  git checkout -b master 
git push -u原点大师

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

对存储库进行更改



在处理自己的本地和远程存储库时,可以使用normal git 命令。确保在 master 分支(或其他某个分支,如果你愿意的话)而不是 upstream-skin 分支,它应该只包含来自上游项目的提交。

  git checkout master 
echoMy XBMC Skin> README
git add README
git commit -mAdded README
git push



接收上游提交



当您处理上游存储库时,您必须使用 git git subtree 命令。要获得新的过滤提交,我们需要分三步完成。



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

  git checkout upstream-master 
git pull

如果有任何提交,这应该拉下新的提交。



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

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

现在更新 upstream-skin ,您可以更新您的 master 分支,你认为合适(通过合并或重新分配)。

  git checkout master 
git rebase upstream-skin






请注意,XBMC资源库是巨大的,并且 git子树命令将花费相当多的时间来过滤所有历史记录 - 并且由于每次交互时重新生成拆分子树与远程存储库,这是一个相当昂贵的操作。我不确定这是否可以加快。



这篇博文详细介绍了上述命令。另请参阅 git-subtree docs 了解更多详情。


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.

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

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

Here are my general requirements:

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

  • 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.

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.

解决方案

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).

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

Setting up a repository

Start by cloning the whole XBMC repository.

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

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

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

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.

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

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

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

git checkout -b master
git push -u origin master

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

Making changes to your repositories

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

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.

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.

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

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


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.

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