Git get --source information in --format

I am trying to format my git logs in a very specific format.

I originally used git log --format="%H,%an,%ae,%ad,%p" , which would produce the following output (for each commit):

 b05f827b41856e6f4bcfba20c32f58434ce3a5a6,Kevin Jalbert, kevin.j.jalbert@gmail.com ,Fri Sep 7 14:43:16 2012 -0400,206f23d 

Now I am trying to get ref information (i.e. tag / branch) for each commit. I can view this information with the git log --source , and this shows what exactly I want (i.e. Ref, which is after the SHA):

 commit 84deec66f94085ee3a0e6f6204f06296d7a1a903 refs/remotes/origin/HEAD Author: Kevin Jalbert < kevin.j.jalbert@gmail.com > Date: Fri Sep 21 17:02:33 2012 -0400 commit message commit f1e1b8d11defc48839557db5e54a5a6f7ffe6cad refs/heads/issue_5 Author: Kevin Jalbert < kevin.j.jalbert@gmail.com > Date: Thu Sep 13 15:34:36 2012 -0400 commit message commit d7acdbd957d9b477f8849fd5a37882cdd78d8e1f refs/tags/v0.3.0 Author: Kevin Jalbert < kevin.j.jalbert@gmail.com > Date: Wed Sep 12 16:48:46 2012 -0400 commit message 

What I'm trying to do is include this information at the end of my original command --format="..." so that I have an output that looks like this:

  b05f827b41856e6f4bcfba20c32f58434ce3a5a6,Kevin Jalbert, kevin.j.jalbert@gmail.com ,Fri Sep 7 14:43:16 2012 -0400,206f23d,refs/remotes/origin/HEAD 

I cannot find any format placeholder that refers to the commit branch / tag / ref based on the --source flag. Am I just missing the right placeholder? Or is there an alternative way to format / display ref along with the user information I desire?

+4
source share
2 answers

I was looking for this too. I could not find the flag as part of git-log , but the following will work by adding a column to the end of the CSV line:

 $ git log --no-color --source --oneline --all | while read sha1 srcref subject > do echo "$(git log -1 --format="%H,%an,%ae,%ad,%p" $sha1),$source" > done 

The --oneline format is %h %<our missing format character> %s when --source provided, so we get part of the way there. Then loading SHA1 back to git log -1 with the rest of the format specifiers will bring us the rest of the way.

+1
source

%d may be what you are looking for - it will show which branches / tags refer to each commit.

0
source

Source: https://habr.com/ru/post/1437631/


All Articles