从远程Git存储库中检索特定的提交

编程入门 行业动态 更新时间:2024-10-22 23:15:37
本文介绍了从远程Git存储库中检索特定的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法从远程Git仓库中只检索一个特定的提交而无需将其克隆到我的PC上?远程repo的结构与我的完全相同,因此不会有任何冲突,但我不知道如何做到这一点,我不想克隆这个庞大的存储库。

我是git的新手,有什么办法吗? 你只克隆一次,所以如果您已拥有远程存储库的克隆,从中取出不会再下载所有内容。只需指出您想要提取哪个分支,或者获取更改并签出您想要的提交。

从新存储库提取非常便宜在带宽中,因为它只会下载你没有的更改。

Git将所有内容存储在 .git 文件夹中。提交不能被提取并孤立存储,它需要它的所有祖先。它们是相互关联的。

为了减少下载大小,你可以让git只提取对象与特定分支或提交相关: pre $ g $ git fetch origin refs / heads / branch:refs / remotes / origin / branch

这将只下载包含在远程分支分支 (只有你错过的),并将其存储在 origin / branch 中。您可以然后合并或签出。

您也可以只指定一个SHA1提交:

git fetch origin 96de5297df870:refs / remotes / origin / foo-commit

只下载指定SHA-1 96de5297df870(及其未命中的祖先)的提交,并将其存储为(不存在的)远程分支 origin / foo-commit 。

Is there any way to retrieve only one specific commit from a remote Git repo without cloning it on my PC? The structure of remote repo is absolutely same as that of mine and hence there won't be any conflicts but I have no idea how to do this and I don't want to clone that huge repository.

I am new to git, is there any way?

解决方案

You only clone once, so if you already have a clone of the remote repository, pulling from it won't download everything again. Just indicate what branch you want to pull, or fetch the changes and checkout the commit you want.

Fetching from a new repository is very cheap in bandwidth, as it will only download the changes you don't have. Think in terms of Git making the right thing, with minimum load.

Git stores everything in .git folder. A commit can't be fetched and stored in isolation, it needs all its ancestors. They are interrelated.

To reduce download size you can however ask git to fetch only objects related to a specific branch or commit:

git fetch origin refs/heads/branch:refs/remotes/origin/branch

This will download only commits contained in remote branch branch (and only the ones that you miss), and store it in origin/branch. You can then merge or checkout.

You can also specify only a SHA1 commit:

git fetch origin 96de5297df870:refs/remotes/origin/foo-commit

This will download only the commit of the specified SHA-1 96de5297df870 (and its ancestors that you miss), and store it as (non-existing) remote branch origin/foo-commit.

更多推荐

从远程Git存储库中检索特定的提交

本文发布于:2023-11-28 16:30:38,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:库中   Git

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!