5

Is there any way to show source while using pretty=format?

Im getting information on which track specific commit was pushed by command

git log --source --oneline

But I also need a date=short which I see cannot be used together with --oneline. But can with pretty=format. Problem is that I don't know how to show --source in pretty=format, can you help?

asked Feb 22, 2019 at 10:38
2
  • This posted 15 min ago. Related maybe? Hmmm..... not really. Commented Feb 22, 2019 at 10:39
  • Well, I have to have --source information Commented Feb 22, 2019 at 10:44

2 Answers 2

6

You should take a look at this post. It gives a very nice exemple of a customize git log. And also an oneliner to define it with a Git alias.

To try it, you can type:

git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

To define it in an alias:

git config --global alias.lg "git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

To use it :

git lg

To check your configuration:

git config alias.lg

To remove it:

git config --unset alias.lg

date=short

If you want to go further in the configuration, you should look at the Git pretty-formats documentation (placeholders section).

For the date you were talking about, you could change the %cr by %ad because this format respects the --date=option. So you could use --date=short as you want.


Tig

To finish there is a very powerful tool you could use if you are a command line lover like me: Tig

answered Feb 22, 2019 at 15:37
Sign up to request clarification or add additional context in comments.

1 Comment

The syntax for the alias has changed, with at least version 2.45 adding the alias should be: git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
1

This will become possible with the --pretty=format:%S token supported in the upcoming Git 2.21.0.

answered Feb 22, 2019 at 13:00

2 Comments

Are you sure because as said here. pretty-formats were last updated in 2.20.0 and there is no --pretty=format:%S. You are probably talking about the subject placeholder %s: --pretty=format:%s.
@NicolasDupouy no, I'm talking about a new placeholder which will be in 2.21.0rc0, -rc1 and -rc2. Since these haven't been released yet, the new placeholder doesn't show up in the online documentation, but you can already see it in the documentation source on the master branch.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.