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

Re: git-checkout -B resets branch not showing last revision

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 17, 2018, 08:45 UTC
Message-ID
<xmqqlgdmkyq9.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<CANu1nimmRCkudQyW8fksg9LRu3tdoSV93S6PD7U_tJ82Vk4kZA@mail.gmail.com>
Haralan Dobrev <harry@hkdobrev.com> writes:
Show 15 quoted lines
> I recently had the following case:
>
> 1. I have a local branch called `foo` which I haven't checkout recently.
> 2. Due to a bad alias I ran the following command:
>
>     git-checkout -B foo
>
> This checked out and reset the foo branch. Which is according to the
> documentation.
> However, the output of the command does not show the previous state of
> the foo branch
> unlike what `git-reset --hard` does for some time.
>
> The previous revision is not present in the `reflog` either as I
> haven't checked it out.

A reflog entry is a record of Old and New object names, with timestamp of the transition and a comment left by the tool. You may see only one record in "git reflog foo@{now}" output, but that record actually knows both the new commit (i.e. the HEAD when you ran "checkout -B") and the old one (i.e. the one you are asking to know). It is only the stupid "git reflog" output that only shows the "new" side of the entry.

So if you do
	head -n1 .git/logs/refs/heads/foo
you'll find the "Old" state at the leftmost column.

I personally do not think it is a good remedy to add more cruft to the output from checkout etc. like we do for "reset --hard" (if anything, I think we should actually remove it from the latter, and show it only asked for --verbose, or something). These ephemeral output messages can easily be missed and not get noticed until they scroll away out of the terminal window.

Teaching "git reflog" to show one extra "fake" entry using the "Old" side of the oldest reflog entry would be a much better solution.

Previous: Haralan Dobrev
Message 2 of 2 in “git-checkout -B resets branch not showing last revision”
  1. Haralan DobrevApr 17, 2018
  2. Junio C HamanoApr 17, 2018

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.