On Sat, Nov 19, 2022 at 08:20:41AM +0100, Uwe Brauer wrote: > Being a mercurial user I want the git graph to look as close as possible to > mercurials, > > The following command/alias does this, but does not display colors, although > I used the decorate option > > git log --graph --all --decorate --pretty=short | git name-rev --stdin | more
--decorate is not about decoration in the colorful sense ;-) It's rather about adding names of references to those parts of the output which display commits these references point at. You do not see colors because of these reasons: - By default, Git commands are configured to output color "when possible". - Such possibility is detected by by making sure the Git command's output stream is connected to a real or emulated terminal device (TTY or PTY). - This is needed because outputting colors is done via sending special "escape sequences" partially standardized by ANSI. These sequences are literally embedded into the output stream so if you were to run $ git some command > some_file.txt and Git were to simple-mindedly output those color-controlling sequences along the rest of the text, the would end up in the file which is most probably not what one usually wants. - So, since a command pipelines as implemented in Unix and Windows shells have no way to propagate some information "backwards" from "the rightmost" command to "the leftmost", this problem generally has no solution: Git has a way to force outputting colors (we'll arrive at that in a moment), but if you force this for, say, the first command in the pipeline and then redirect output of the pipeline to a file, the file will end up containing those escape sequences. So, basically, if you're creating Git aliases, you sort of need to create a pair of aliases - one for output knowingly destined to a console and one for "raw" output. There are two ways to make a Git command output colors no matter what - by overriding a configuration variable at invocatio or with the --color command-line option. Both variants should work: git log --color=always ... and git -c color.ui=always log ... Note that I have no idea about the behaviour of `more` (as I think I've only occasionally used it back in the days of working with plain MS-DOS), but the more versatile `less` also requires explicitly telling it that it should expect ANSI color sequences in its input, so if I were to fix your pipeline, I'd stick `less -R` at the end. Consult the git-config(1) about the color.ui setting and git-log(1) - regarding the "--color" option. -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To unsubscribe from this group and stop receiving emails from it, send an email to git-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/git-users/20221119124043.lhwvjndooaukjrfm%40carbon.