Git通过哈希获取特定的提交

Git通过哈希获取特定的提交

本文介绍了Git通过哈希获取特定的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Git允许从任何给定的远程和引用中获取数据,例如

  git fetch< remote-url> <参考> 

这样就可以在不需要添加遥控器或创建分支的情况下使用提交的提交。



然而,这只适用于引用,如分支名称或标签,但不适用于特定的散列,因此不会直接引用任何地方。



有没有办法从远程获取特定的提交? 解决方案

根据手册, git fetch 需要一个refspec,其中最简单的形式是ref,并且一个裸SHA-1不是ref。也就是说,提交必须在远程机器上拥有一个名称(分支,标记),以便能够 fetch 它。


Git allows to fetch from any given remote and reference, for example

git fetch <remote-url> <reference>

So that those given commits are available without having to add remotes or creating branches.

This however only works for references, like branch names or tags, but not for specific hashes and thus commits that are not referenced directly anywhere.

Is there a way to fetch a specific commit from a remote?

解决方案

No. According to the manual, git fetch wants a refspec, the simplest form of which is a ref, and a bare SHA-1 isn't a ref. I.e., the commit has to have a name (branch, tag) on the remote for you to be able to fetch it.

这篇关于Git通过哈希获取特定的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:46