Git获取对象,没有引用

时间:2015-08-09 18:44:10

标签: git git-fetch git-refspec

我想从远程仓库中获取对象,但不更新任何本地引用。 (是的,我知道这是一个相当不寻常的案例。)

我看到我可以将refspec传递给git fetch,但是当我传递一个空的(git fetch my-remote '')时,它似乎默认为其他东西,因为我收到以下错误:

fatal: Couldn't find remote ref HEAD
fatal: The remote end hung up unexpectedly

有没有办法指定“null”ref-spec?

1 个答案:

答案 0 :(得分:0)

To not update any ref you leave part after : in refspec empty:

git fetch origin master:

Then find the commit hash in .git/FETCH_HEAD

Answer to your comment: no, git fetches only objects necessary to get the specified remote ref. The pattern of getting only one branch is commonly used, there is even a dedicated option for git clone for this.

PS: I would instead fetch to a temporary branch with some random name.