Posts

Showing posts with the label Git Log

Better Way Of Getting A GIT Commit Message By Short Hash?

Answer : git log takes (among other things): -n num to limit the number of commits shown: choose 1 (and if num is 9 or less you can just write - num , hence, -1 , for short) --pretty=format: string with directives to change the log output format. The %s directive gets the commit "subject", which is what you also get with oneline . Hence: git log -n 1 --pretty=format:%s $hash (or git log -1 --pretty=format:%s ) will do the trick here. For a complete list of format directives, see the git log documentation, under "PRETTY FORMATS" (about halfway down). Depending on how much of the commit message you actually want, there are several pretty-format specifiers that you can use: · %s: subject · %f: sanitized subject line, suitable for a filename · %b: body · %B: raw body (unwrapped subject and body) So something like git log -1 --pretty=format:%b <hash> , or use one of the other specifiers (I think %s is probably cl...

Color In Git-log

Answer : As of git 1.8.3 (May 24, 2013), you can use %C(auto) to decorate %d in the format string of git log . From the release notes: * "git log --format" specifier learned %C(auto) token that tells Git to use color when interpolating %d (decoration), %h (short commit object name), etc. for terminal output.) The git log --decorate will put by default: the HEAD in cyan the remote branches in red the tag in green and can be changed through color.decorate config. But the git log --format don't offer a way to display specifically the HEAD or remotes or branch: all three are displayed through %d , with one color possible. Update May 2013, as mentioned below by Elad Shahar (upvoted), git 1.8.3 offers one more option: git log –format now sports a %C(auto) token that tells Git to use color when resolving %d (decoration), %h (short commit object name), etc. for terminal output. This Atlassian blog post comments that this feature i...