1

Is it possible to make git commands highlight a commit message in the terminal?

For example:

$git stash

Saved working directory and index state WIP on master: 9d657ff Sort events

HEAD is now at 9d657ff Sort events

Otherwise it is hard to catch them in the abundant output of git.

1 Answer 1

4

Adding --color works for several git commands... but not for that specific one (git stash), and they highlight the commit hash, not the commit message.

git stash list is supposed to take the same options as git log (which includes --color), but I had to specify some format (e.g. --oneline) to get it to work:

git stash list --oneline --color

Also, git has a config option to use color in all commands by default (color.ui, in git help config)... but, like the above, it works for some commands, but not that one.

Finally, git log enables you to specify precisely what colors you want in the formatting, and since many commands use git log and accept options for it, you could highlight the commit message in that way, for those commands (and make aliases for them).

FWIW I agree it would be a good feature.

Sign up to request clarification or add additional context in comments.

3 Comments

And how do I change colours for log? I can't find it here: kernel.org/pub/software/scm/git/docs/git-config.html
@klm123: you can set format.pretty in the git config, but that sets only the default. The "default default" is git config format.pretty medium which expands to format:commit %H%nAuthor: %aN %aE%nDate: %ad%n%n%w(0,4,4)%B (I think, worked for simple test anyway). Add %C directives to taste. It would be nice to be able to define format strings and then use --pretty=myform1, --pretty=myform2, etc., but that does not seem to be an option now.
Another way is to create an alias (in .gitconfig), but you have to remember to use that name instead of git log, and it's only for that one command, so not as smooth as @torek's suggestion. e.g. I have this under [alias]: lg = "log --oneline --graph --color-words --branches --decorate --date=short --pretty=format:'%C(yellow)%h %Creset%s%C(yellow)%d %Cgreen(%ar)'" You use it as git lg, just like git log, with whatever other options, commits, paths etc you need.

Your Answer

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.