git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Behavior of 'git fetch' for commit hashes

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Jun 19, 2017, 17:49 UTC
Message-ID
<20170619104936.706eff69@twelve2.svl.corp.google.com>
In-Reply-To
<14e804c6-0798-8bbd-b182-66c3cd2b870c@vaisala.com>

On Mon, 19 Jun 2017 12:09:28 +0000 <eero.aaltonen@vaisala.com> wrote:

Show 8 quoted lines
> For version 2.7.4
> =================
> Git exits with exit code 1.
> 
> However, if I first do 'git fetch <branch>', then 'git fetch <sha1> will
> also work
> 
>  * branch   <sha1> -> FETCH_HEAD

I suspect that what is happening is that 'git fetch <branch>' also downloads the commit referenced by <sha1>, so the subsequent 'git fetch <sha1>' is a no-op (except setting FETCH_HEAD).

Show 8 quoted lines
> For version 2.13.3
> ==================
> Git exits with exit code 128 and message
> fatal: Couldn't find remote ref
> 
> However, the workaround for descbibed abot for git version 2.7.4 no
> longer works. The result is always
> fatal: Couldn't find remote ref
I'll take a look into this.
Show 11 quoted lines
> Desired result
> ==============
> Commit is in .git/FETCH_HEAD and can be checked out.
> 
> 
> I want to checkout a specific commit without creating any extra named
> remotes in the local git clone.
> 
> Finally,
> What is the expected behavior for 'git fetch' in this case?
> Is there some other way I can achieve my goals?

I'll take a look into the expected behavior, but if my assumptions are correct, you should be able to just checkout the commit you want after fetching the branch:

  git fetch <forkUrl> <branch>
  git checkout <sha1>
Previous: Stefan BellerNext: Jonathan Tan
Message 3 of 5 in “Behavior of 'git fetch' for commit hashes”
  1. eero.aaltonen@vaisala.comJun 19, 2017
  2. Stefan BellerJun 19, 2017
  3. Jonathan TanJun 19, 2017
  4. Jonathan TanJun 19, 2017
  5. eero.aaltonen@vaisala.comJun 20, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.