1

I view my git logs in CMD which has a custom format,

git log --date=format:'%d %b %I:%M%p' --pretty=format:"%C(Yellow)%h%Creset %cd%Cgreen%d %Creset%s" -10

now I have to copy this command every time from my notepad so I was thinking if I can create a custom cmd command that will run the above command.

for eg. I would just write

showlog

and it will execute my command.

I tried creating a bat file and found this command.

start cmd.exe @cmd /k "git log --oneline -10"

but it opened a new window I would like this to execute in the same window like other git commands

So I want to know

  1. how exactly it is done within the same window?
  2. where can I learn more about this?
torek
  • 448,244
  • 59
  • 642
  • 775
Achal Urankar
  • 159
  • 1
  • 11
  • 1
    Your question as asked is really about .BAT files, but there are questions you could ask about Git here: specifically, about Git aliases, and about `git log` pretty formats. Since you've accepted the .BAT answer I've trimmed off the Git tag. – torek Nov 27 '22 at 06:39

2 Answers2

2

You don't have to use start nor cmd in your batch file, just the command itself:

@echo off
my command and parameters here

so for your showlog.bat:

@echo off
git log --date=format:'%d %b %I:%M%p' --pretty=format:"%C(Yellow)%h%Creset %cd%Cgreen%d %Creset%s" -10

% might be problematic, you might have to escape it with %%. While debugging you can remove the @echo off to have it echo the command...

Anders
  • 97,548
  • 12
  • 110
  • 164
1

Instead of (correct) @anders way for custom cmd-command, you can think about more Git-way of building Git alias (use git showlog) for the same output: simple, (somehow) faster and more manageable solution.

Something like

git config --global alias.showlog 'git log <FULL TAIL OF YOUR COMMAND HERE>'
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110