git help in Windows command prompt

2020-07-05 07:14发布

问题:

The git help command on Windows (msysgit distribution) spawns web browser each time I run it. I tried git help -m which reports "No manual entry for ..." and git help -i which says "info: Terminal type 'msys' is not smart enough to run Info." The same happens in bash under Cygwin.

Is there any sensible way to get light-weight help in cmd terminal?

回答1:

Update for Git 2.x (June 2017, Git 2.13.1)

You still don't have man:

> git -c help.format=man help add
warning: failed to exec 'man': No such file or directory
fatal: no man viewer handled the request

Same for git <verb> --help.
git <verb> -h does not print the man page, only the short usage section (nothing to do with man)


No, even though an alternative, based on a 'cat' of the htlp txt files, is suggested in "how do I get git to show command-line help in windows?".

There man.<tool>.cmd config introduced in 2008, allows to set a custom command, but msys shell isn't shipped with man.exe.



回答2:

It works for particular commands: git <command> -h

Edit, thanks to @the-happy-hippo

But it shows only a brief description, not the full one, as git help <command> or git <command> --help gives on Windows.



回答3:

git <verb> -h shows a command usage in the same terminal window.

On the other hand, git <verb> --help and git help <verb> open a browser.



回答4:

World's most overengineered workaround for this problem: use WSL

(that is, unless you already are a WSL user, in which case it's merely an ordinary workaround)

  1. Install one of the linux distros via Windows Store
  2. Go in and ensure it has the git package installed
  3. From the Windows command line, bash -c 'git help fetch' etc.

Here's an alias for that last one:

[alias]
    hep = "!f() { $SYSTEMROOT/System32/bash -c \"git help $1\"; }; f"

(And no you can't override git built-ins, but you can make a shell command to intercept and reroute help.)