-1

I need a simple way to quickly check a branch and commit three. So I went to the Git documentation and found this:

git log --pretty=format:"%h %s" --graph

Output:

* 2d3acf9 Ignore errors from SIGCHLD on trap
*  5e3ee11 Merge branch 'master' of https://github.com/dustin/grit.git
|\
| * 420eac9 Add method for getting the current branch
* | 30e367c Timeout code and tests
* | 5a09431 Add timeout protection to grit
* | e1193f8 Support for heads with slashes in them
|/
* d6016bc Require time for xmlschema
*  11d191e Merge branch 'defunkt' into local

However the actual output in CLI looks like this

git log --pretty=format:"%h %s" --graph

Output:

* 2d3acf9 Ignore errors from SIGCHLD on trap
*  5e3ee11 Merge branch 'master' of https://github.com/dustin/grit.git
* 420eac9 Add method for getting the current branch
* 30e367c Timeout code and tests
* 5a09431 Add timeout protection to grit
* e1193f8 Support for heads with slashes in them
* d6016bc Require time for xmlschema
* 11d191e Merge branch 'defunkt' into local

I can achieve what I need by using this command:

git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all

But as you can see, it's too long and easy to type when in a rush. I can't always use an alias to shorten it.

What is wrong with git log --pretty=format:"%h %s" --graph?

I need to run this mainly on Windows in PowerShell, but also on Linux in terminal.

What didn't help me:

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
GreenMarty
  • 232
  • 3
  • 7
  • can you describe your cli context ? OS, shell (and possibly terminal), if it is a plain local shell (e.g: `bash` on your local linux system, or `cmd.exe` on Windows, or a ssh console, or ...) – LeGEC Jun 09 '23 at 10:54
  • fwiw: I know I have the expected output on bash/Ubuntu, cmd.exe/Windows 10 and powershell/Windows 10. Something is meddling with your output. – LeGEC Jun 09 '23 at 10:57
  • @LeGEC Hey there, as i mentioned in the question , it's "I need to run this mainly on Windows in PowerShell but also on Linux in terminal." To be more precise Win 10, Win 11 powershell 1.0 and 7.0 also Linux FXCE terminal, google cloud console ssh in browser for start but I would like it to work regardless of system. – GreenMarty Jun 09 '23 at 11:40
  • @LeGEC I managed to make it work by adding `--all` at the end of the command. Apparently it doesn't work other way in certain cases. – GreenMarty Jun 09 '23 at 11:53
  • "in linux on terminal" : do you see the same glitch when running that command on linux ? – LeGEC Jun 09 '23 at 13:03
  • @LeGEC interesting. It's not Linux vs Windows or cmd vs ps vs linux terminal issue. It's project specific. Some projects do that while other don't. I just tested on those that do at first. Do you know what makes that happened. `--all` fixes it by showing entire history of repo. – GreenMarty Jun 09 '23 at 15:37
  • What do you mean by *"commit three"*? *"commit [tree](https://en.wikipedia.org/wiki/Tree_(command))"*? Or something else? – Peter Mortensen Jun 22 '23 at 10:43

2 Answers2

0

git log --oneline --all --graph --reflog is what I use for this purpose.

Caleb
  • 205
  • 1
  • 8
  • Hey, thanks for the input. Solution i found before you answered was to add `--all` into the command. Your answer is basically doing the same. Reason you got down-voted by someone (not me) was most likely because you didn't add explanation. I can edit your answer but it's better to let you know. – GreenMarty Jun 09 '23 at 14:54
-1

I've managed to graphically represent the complete commit tree in CLI by adding --all into the command.

Fast way

git log --oneline --graph --all

Simple but customizable way with --pretty=format

git log --pretty=format:"%h %ar %s" --graph --all

code desc
git log commit history
--pretty=format:"%h %s" shown data
--graph ASCII art-based visualization of branches
--all displays entire commit history from all branches

part inside --pretty=format:"%h %ar %s" allows to customize printed data.

GIT doc example: E.g, format:"The author of %h was %an, %ar%nThe title was >>%s<<%n" would show something like this:

The author of fe6e0ee was Junio C Hamano, 23 hours ago
The title was >>t4119: test autocomputing -p<n> for traditional diff input.
GreenMarty
  • 232
  • 3
  • 7
  • fwiw : `git log --oneline --graph` . `--oneline` is basically a shortcut for `--pretty="%h %s"`, which should autocomplete. – LeGEC Jun 09 '23 at 19:51
  • Well yes, `- - oneline` is shortcut for ` ` however using pretty allows for additional customization. – GreenMarty Jun 11 '23 at 04:37
  • What do you mean by *"commit three"*? *"commit [tree](https://en.wikipedia.org/wiki/Tree_(command))"*? Or something else? – Peter Mortensen Jun 22 '23 at 10:42
  • @PeterMortensen Typo indeed. I meant tree like structure of commits portrayed in graphical way. Purpose is to show how each branch grows, merge points and each commits with additional details. – GreenMarty Jun 22 '23 at 12:08