threads / bug / 59594

Git bug

Subject: Git bug

## tl;dr

3 messages between Apr 14, 2023 and Apr 17, 2023.

replies: 2people: 2as markdown or json

Gabriel Furstenheim Milerud· Apr 14, 2023, 09:41 UTC · lore

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)
> repository in branch A
git name-rev $(git rev-parse HEAD) --name-only
> returns A

git checkout B git name-rev $(git rev-parse HEAD) --name-only

What did you expect to happen? (Expected behavior) It should return B

What happened instead? (Actual behavior) It returns A

What's different between what you expected and what actually happened? git rev-parse does not seem to update. Same is happenning with git rev-parse @{-1}

Anything else you want to add: git version 2.34.1

I recently migrated to ubuntu 22. In ubuntu 18 with previous git version is was working as expected.

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info] git version: git version 2.34.1 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 5.19.0-38-generic #39~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 17 21:16:15 UTC 2 x86_64 compiler info: gnuc: 11.3 libc info: glibc: 2.35 $SHELL (typically, interactive shell): /bin/bash

[Enabled Hooks]
René Scharfe· Apr 14, 2023, 16:07 UTC · re: Gabriel Furstenheim Milerud · lore

Re: Git bug

Am 14.04.23 um 11:41 schrieb Gabriel Furstenheim Milerud:
Show 17 quoted lines
> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
>
> What did you do before the bug happened? (Steps to reproduce your issue)
>> repository in branch A
> git name-rev $(git rev-parse HEAD) --name-only
>> returns A
> git checkout B
> git name-rev $(git rev-parse HEAD) --name-only
>
>
>
> What did you expect to happen? (Expected behavior)
> It should return B
>
> What happened instead? (Actual behavior)
> It returns A

Do you have a short recipe for creating the branches to reproduce this behavior? Here's my (failed) attempt:

   # create repository
   git init -q /tmp/repo
   cd /tmp/repo
   # create branch a
   echo a >a
   git add a
   git commit -q -m a
   git branch a
   # create branch b
   echo b >b
   git add b
   git commit -q -m b
   git branch b
With that done Git v2.34.1 gives me the output you expect:
   $ git switch a
   Switched to branch 'a'
   $ git name-rev $(git rev-parse HEAD) --name-only
   a
   $ git switch b
   Switched to branch 'b'
   $ git name-rev $(git rev-parse HEAD) --name-only
   b
> What's different between what you expected and what actually happened?
> git rev-parse does not seem to update. Same is happenning with git
> rev-parse @{-1}
   $ git name-rev $(git rev-parse @{-1}) --name-only
   a

This is expected because @{-1} means the branch/commit checked out before the current one.

What does "git rev-parse HEAD" return for you in each case? Do your branches perhaps have the same HEAD commit?

Show 5 quoted lines
> Anything else you want to add:
> git version 2.34.1
>
> I recently migrated to ubuntu 22. In ubuntu 18 with previous git
> version is was working as expected.

I guess you use LTS releases, i.e. jammy (22.04) and bionic (18.04)? bionic shipped with Git 2.17.1 according to https://packages.ubuntu.com/

René
Gabriel Furstenheim Milerud· Apr 17, 2023, 09:46 UTC · lore

Re: Git bug

In case someone stumbles onto this. The right way to do it is:
git rev-parse --symbolic-full-name --abbrev-ref=loose @{-1}

On Sat, 15 Apr 2023 at 11:00, Gabriel Furstenheim Milerud <furstenheim@gmail.com> wrote:

Show 81 quoted lines
>
> Sorry, my bad. I didn't realize that it worked based on commits. I got confused by git checkout -, which doesn't.
>
> Cheers
>
> On Fri, 14 Apr 2023, 18:07 René Scharfe, <l.s.r@web.de> wrote:
>>
>> Am 14.04.23 um 11:41 schrieb Gabriel Furstenheim Milerud:
>> > Thank you for filling out a Git bug report!
>> > Please answer the following questions to help us understand your issue.
>> >
>> > What did you do before the bug happened? (Steps to reproduce your issue)
>> >> repository in branch A
>> > git name-rev $(git rev-parse HEAD) --name-only
>> >> returns A
>> > git checkout B
>> > git name-rev $(git rev-parse HEAD) --name-only
>> >
>> >
>> >
>> > What did you expect to happen? (Expected behavior)
>> > It should return B
>> >
>> > What happened instead? (Actual behavior)
>> > It returns A
>>
>> Do you have a short recipe for creating the branches to reproduce this
>> behavior?  Here's my (failed) attempt:
>>
>>    # create repository
>>    git init -q /tmp/repo
>>    cd /tmp/repo
>>
>>    # create branch a
>>    echo a >a
>>    git add a
>>    git commit -q -m a
>>    git branch a
>>
>>    # create branch b
>>    echo b >b
>>    git add b
>>    git commit -q -m b
>>    git branch b
>>
>> With that done Git v2.34.1 gives me the output you expect:
>>
>>    $ git switch a
>>    Switched to branch 'a'
>>    $ git name-rev $(git rev-parse HEAD) --name-only
>>    a
>>
>>    $ git switch b
>>    Switched to branch 'b'
>>    $ git name-rev $(git rev-parse HEAD) --name-only
>>    b
>>
>> > What's different between what you expected and what actually happened?
>> > git rev-parse does not seem to update. Same is happenning with git
>> > rev-parse @{-1}
>>
>>    $ git name-rev $(git rev-parse @{-1}) --name-only
>>    a
>>
>> This is expected because @{-1} means the branch/commit checked out
>> before the current one.
>>
>> What does "git rev-parse HEAD" return for you in each case?  Do your
>> branches perhaps have the same HEAD commit?
>>
>> > Anything else you want to add:
>> > git version 2.34.1
>> >
>> > I recently migrated to ubuntu 22. In ubuntu 18 with previous git
>> > version is was working as expected.
>>
>> I guess you use LTS releases, i.e. jammy (22.04) and bionic (18.04)?
>> bionic shipped with Git 2.17.1 according to https://packages.ubuntu.com/
>>
>> René
>>

← back to recent threads