3

I am creating a git repository and adding a file to the repository using git commit. After commit in the git log, I could see the commit info but i am not able to see the HEADinfo. Following is the steps that I followed:

$ git config --global user.name "abc"
$ git config --global user.mail "abc@abc.com"
$ git init
  Initialized empty Git repository in /home/aishwarya/github.com/temp/.git/
$ touch a.txt
$ git add a.txt

$ git commit --message "first commit in NonBareRepo"
  [master (root-commit) 6d46130] first commit in NonBareRepo
   1 file changed, 0 insertions(+), 0 deletions(-)
   create mode 100644 a.txt
$ git log
  commit 6d46130416eef0104408d575d8d4958457fe1dab
  Author: abc <abc@abc.com>
  Date:   Mon Feb 3 22:07:18 2020 +0530

      first commit in NonBareRepo

On other machine, after creating repository with the same steps, I could see the git log output as follows(HEAD points to master):

$ git log
commit 7ba4781ddee49a3636ee700fe057c3a372502460 (HEAD -> master)
Author: abc <abc@abc.com>
Date:   Mon Feb 3 22:01:11 2020 +0530

    first commit in NonBareRepo

Please let me know if I am missing something. Thank you

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61

1 Answers1

5

You might have different config entries here. See log.decorate

But anyway, to explicitly mention branch/tag info after the commit hash in log output, use the flags

# to force it
git log --decorate

# to prevent it
git log --no-decorate

As torek points out in comment below, the threshold is more precisely 1.7.2 version, where log.decorate appeared altogether. Before that point, there were no decorations at all, and since then it defaults to auto (meaning it's turned on by default).

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • Is it possible that different versions of git have this turned on by default / not ? – mimikrija Feb 04 '20 at 15:32
  • (I mean, I have it turned on but I don't see it in any of the `.config` files :) ) – mimikrija Feb 04 '20 at 15:38
  • 1
    AFAIK, this is assumed `true` if not present. Did you try to `git config -l` from the machine where it doesn't show up? To spot a `log.decorate false` maybe? – Romain Valeri Feb 04 '20 at 15:42
  • I am not the OP, but I was wondering the same - maybe the OP can spot it by using this command. – mimikrija Feb 04 '20 at 15:51
  • 4
    `log.decorate` defaults to `auto` (or `true`? or something...) in Git versions 1.7.2 and later. If your machine on which you're *not* seeing it has Git 1.7.1 or earlier, you don't have `log.decorate` at all. (Edit: actually, I'm not sure if it was "auto" back then. There's a commit from Git 2.13 to fix a bug in the default "auto" mode as of 2.13, but when it became "auto" is less clear.) – torek Feb 04 '20 at 15:54
  • @RomainValeri, @torek thank you for your kind reply. As @RomainValeri suggested I could get the head pointer using `--decorate` option. @torek , I am using 2.7.4 and thus I think `--decorate` option should have been enabled by default. I however enabled it by using `git config --global log.decorate auto` as mentioned in https://stackoverflow.com/questions/21607305/how-to-make-git-log-decorate-by-default . I am now able to see the HEAD pointer. Thank you again. – aishwarya kamath Feb 05 '20 at 14:37
  • 1
    Perhaps the OP is using mingw64 (git version 2.8.3.windows.1 like I am where the problem persists). There is no log.decorate file but --decorate works. Edit: if you are experiencing OP's problem, update Git for Windows. Works fine now. – AndJM May 18 '22 at 12:59
  • Thanks for the feedback @AndJM, it indeed works well now on recent enough mingw64 versions. – Romain Valeri May 18 '22 at 13:18