Lib*_*bux 82 git version-control dvcs repository
我有一个名为的存储库Generic
,它是一个通用的应用程序.我已将其分叉到一个名为Acme
的存储Generic
库中,该存储库仅构建在应用程序存储库上,并为其添加了Acme Co品牌.
如果我对核心功能进行了更改Generic
,我想Acme
使用我对核心功能所做的最新更改来更新存储库Generic
.我该怎么办?
据我所知,我基本上试图将上游存储库中所做的更改合并到当前的fork中.
如果它意味着什么,我正在尝试这样做,因为我有一个通用的应用程序,然后我为个人客户构建和品牌(如Acme
本例所示).如果有更清洁的方法,请告诉我.
McL*_*vin 117
在您的Acme
仓库中发出以下命令.它增加了一个新的名为远程仓库upstream
指向Generic
回购.
git remote add upstream https://location/of/generic.git
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用以下命令Generic
将对所做的任何更改合并到当前分支中Acme
:
git pull upstream
Run Code Online (Sandbox Code Playgroud)
如果您只是希望它在不自动合并的情况下下载更改,请使用git fetch
而不是git pull
.
如果要禁用推送到该存储库,请使用类似的方式将推送URL设置为无效的URL
git config remote.upstream.pushurl "NEVER GONNA GIVE YOU UP"
Run Code Online (Sandbox Code Playgroud)
Git现在会对你大吼大叫,如果你试图推进就无法找到回购upstream
(对Rickroll感到抱歉,但这是第一个突然出现在我头脑中的随机字符串).
小智 23
为了从不同的 repo 中提取特定分支,您可以使用以下 git 命令。
git pull <git_url> <branch> --allow-unrelated-histories
Run Code Online (Sandbox Code Playgroud)
正如@vin提到的,您可以git pull
直接从另一个存储库而不添加新的源(假设从另一个存储库的master
分支拉到本地master
分支):
git pull https://some-other-repo.git master:master
# OR pull to a new local branch
git pull https://some-other-repo.git master:new_local_branch
Run Code Online (Sandbox Code Playgroud)
如果两个存储库的提交历史记录没有链接,那么--allow-unrelated-histories
将需要它,但请谨慎使用,因为这意味着您知道自己在做什么。
您还可以将git push
本地存储库添加到另一个存储库,而无需将其添加为远程存储库:
git push https://some-other-repo.git master:master
# OR create a new branch on remote
git push https://some-other-repo.git master:new_remote_branch
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
38207 次 |
最近记录: |