从远程git仓库获取特定的提交 [英] Fetch specific commit from remote git repo

查看:154
本文介绍了从远程git仓库获取特定的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我基本上要做的就是从一个远程仓库中下拉一个给定的提交(由SHA标识),然后将其作为新分支(其名称为自动生成)推送到另一个远程仓库。源回购会有所不同,这些都是一次性操作,所以我不希望 git remote add 这些遥控器,我不想创建参考/分支对于提交。我不想更改我的任何本地分支机构的头部。



所以,我怎样才能抓住给定的远程提交(以及任何它的父提交对我来说是新的),并将其添加到我的本地git数据库中?


$ b git pull c $ c>隐式地涉及到合并或rebase,所以这是不可能的。



我试过 git fetch https://github.com /foo/bar.git 7d0969daba1fdf9d5bb9bc9a2847fd1bc1c7e426

但这只会导致

错误:no such remote ref 12819ad8e10e5906df5352d7d8fec1fceb1f3afc

(是的,我验证了那个提交SHA存在于那个远程;看起来像git不接受SHA在这里)。

我的意思是,我想我可以想出一个任意的本地分支名称,以便始终将提交拉入,然后在每次推送后删除该分支,但这似乎不雅观......

解决方案

Git不会同意您可以通过设计获取SHA。似乎没有任何计划可以基于以前的开发者对话来启用该功能邮件列表

您必须在遥控器上提供参考才能获取。你应该能够自动生成这个部分,我会想象,因为你必须有一个机制来传递远程和来回已经。

So, what I'm basically trying to do is to pull down a given commit (identified by its SHA) from one remote repo, and then push it to another remote repo as a new branch (whose name I autogenerate). The source repo will vary and these are all one-shot operations, so I don't want to git remote add these remotes and I don't want to create refs/branches for the commits. And I don't want to change the HEADs of any of my local branches.

So, how do I just grab the given remote commit (and any of its parent commits that are new to me) and add it/them to my local git database?

git pull implicitly involves a merge or rebase, so that's out of the question.

I tried git fetch https://github.com/foo/bar.git 7d0969daba1fdf9d5bb9bc9a2847fd1bc1c7e426
but that just leads to
error: no such remote ref 12819ad8e10e5906df5352d7d8fec1fceb1f3afc
(and yes, I verified that that commit SHA exists on that remote; looks like git doesn't accept a SHA here anyway).

I mean, I guess I could come up with a single arbitrary local branch name to always pull the commits down into, and then delete that branch after every push, but that's seems inelegant...

解决方案

Git does not allow you to fetch by SHA by design. It doesn't seem like there are any plans to enable that either based on previous conversations on the developers mailing list

You will have to have a reference on the remote in order to be able to fetch. You should be able to auto-generate this part I would imagine, since you have to have a mechanism to pass the remote and sha back and forth already.

这篇关于从远程git仓库获取特定的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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