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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Haralan Dobrev <harry@xxxxxxxxxxxx> writes:

> 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.



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux