git-subtree:推送来自克隆回购的更改 [英] git-subtree: Push changes from an cloned repo

查看:190
本文介绍了git-subtree:推送来自克隆回购的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用git-subtree(来自Avery Pennarun)。在我目前的git repo中,当然有
所有项目文件/文件夹和一个名为lib的子树。
如果我现在使用 git clone 克隆这个git repo,我得到所有的项目文件和
的子树lib(一切都应该如此)。
我现在尝试的:我在克隆的
仓库中的子树lib中更改了某些内容,并尝试使用
<$将更改推回到子树lib的远程仓库c $ c> git子树push ,但它不起作用。问题是什么?我必须先将
作为子树添加到git subtree add?



提前Thx

解决方案

免责声明,我怀疑我只是提前几天看到子树: - ) 如果您只是使用 git subtree push 您不会给子树足够的信息来提取和推送您的更改。



如果您克隆回购正确的子树已经在那里了。需要告知子树需要推送哪个子树(即使只有一个子树),并且还需要知道应该推到哪里 - 具体而言,您不希望推送到顶级回购站。因此,你需要这样的东西:

  git subtree push --prefix = lib git@github.com:arges-github / lib .git master 

显然,repo和refspec应该更改为与您的repo相匹配。



如果您想查看此处发生的情况(并且确实有帮助),子树实际上会将影响子树内文件的更改拆分为不同的分支,然后将其推送到子树回购。要看到这种情况,使用子树拆分

  git subtree split  - 重新加入--branch = shared-changes --prefix = lib 

然后看看你的分支'已经取得:

  git checkout lib-changes 

并手动推送它们

  git push git@github.com:arges -github / lib.git master 

如果这不起作用,那可能是你没有将子树合并到您的回购中。当你添加一个子树时:

  git subtree add --squash --prefix lib git@github.com:arges-github / lib.git master 

您还需要合并子树并将其推回到顶级回购站。

  git subtree pull --squash --prefix lib git@github.com:arges-github / lib.git master 
git push


I'm using git-subtree(from Avery Pennarun). In my current git repo I have of course all my project files/folders and a subtree called "lib". If I now clone this git repo using git clone I get all of the project files and the subtree "lib" (everything as it should be). What I tried now: I changed something within the subtree "lib" in the cloned repo and tried to push the changes back to the remote repo of the subtree "lib" using git subtree push, but it didn't work. What is the problem? Do I have to add it as subtree first with git subtree add?

Thx in advance

解决方案

Disclaimer, I suspect I am only a few days ahead of you learing about subtree :-)

If you are just using git subtree push you are not giving subtree enough information to extract and push your changes.

If you cloned the repo correctly the subtree will already be in there. Subtree needs to be told which subtree you want to push from (even if you only have one) and it also needs to know where to push to - specifically, you do not want to push to the top level repo. Hence, you want something like:

git subtree push --prefix=lib git@github.com:arges-github/lib.git master

Obviously the repo and refspec should be changed to match your repo.

If you want to look into what is happening here (and it does help) subtree actually splits the changes that affect the files inside the subtree into a different branch and then pushes that to the subtree repo. To see this happen, use subtree split

git subtree split --rejoin --branch=shared-changes --prefix=lib

then have a look at the branch you've made:

git checkout lib-changes

and, push them manually

git push git@github.com:arges-github/lib.git master

If this isn't working then it may be that you have not merged the subtree into your repo. When you add a subtree:

 git subtree add --squash --prefix lib git@github.com:arges-github/lib.git master

you also need to merge the subtree and push it back to your top level repo.

 git subtree pull --squash --prefix lib git@github.com:arges-github/lib.git master
 git push

这篇关于git-subtree:推送来自克隆回购的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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