Git - 获取帮助



Git 自带一个内置的帮助系统,可以直接从命令行访问。这些命令对于快速查找有关特定 Git 命令和选项的信息非常有用。

git help 命令

git help 命令是访问 Git 命令文档最直接的方法。它提供了可用命令的概述以及如何使用它们。

$ git help

输出消息如下

usage: git [-v | --version] [-h | --help] [-C ] [-c =]
    [--exec-path[=]] [--html-path] [--man-path] [--info-path]
    [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
    [--git-dir=] [--work-tree=] [--namespace=]
    [--config-env==]  []

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
clone     Clone a repository into a new directory
init      Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
add       Add file contents to the index
mv        Move or rename a file, a directory, or a symlink
restore   Restore working tree files
rm        Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
bisect    Use binary search to find the commit that introduced a bug
diff      Show changes between commits, commit and working tree, etc
grep      Print lines matching a pattern
log       Show commit logs
show      Show various types of objects
status    Show the working tree status

grow, mark and tweak your common history
branch    List, create, or delete branches
commit    Record changes to the repository
merge     Join two or more development histories together
rebase    Reapply commits on top of another base tip
reset     Reset current HEAD to the specified state
switch    Switch branches
tag       Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
fetch     Download objects and refs from another repository
pull      Fetch from and integrate with another repository or a local branch
push      Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help ' or 'git help '
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.

此命令显示常用 Git 命令及其简短说明的列表。您可以使用此列表来确定您需要帮助的命令。

列出所有 Git 命令

以下命令列出所有可能的 Git 命令,包括常用和不常用的命令,并为每个命令提供简短说明。

$ git help -a
$ git help --all

输出消息如下

See 'git help ' to read about a specific subcommand

Main Porcelain Commands
    add                     Add file contents to the index
    am                      Apply a series of patches from a mailbox
    archive                 Create an archive of files from a named tree
    bisect                  Use binary search to find the commit that introduced a bug
    branch                  List, create, or delete branches
    bundle                  Move objects and refs by archive
    checkout                Switch branches or restore working tree files
    cherry-pick             Apply the changes introduced by some existing commits
    citool                  Graphical alternative to git-commit
    clean                   Remove untracked files from the working tree
    clone                   Clone a repository into a new directory
    commit                  Record changes to the repository
    describe                Give an object a human readable name based on an available ref
    diff                    Show changes between commits, commit and working tree, etc
    fetch                   Download objects and refs from another repository
    format-patch            Prepare patches for e-mail submission
    gc                      Cleanup unnecessary files and optimize the local repository
    gitk                    The Git repository browser
    grep                    Print lines matching a pattern
    gui                     A portable graphical interface to Git
    init                    Create an empty Git repository or reinitialize an existing one
    log                     Show commit logs
    maintenance             Run tasks to optimize Git repository data
    merge                   Join two or more development histories together
    mv                      Move or rename a file, a directory, or a symlink
    notes                   Add or inspect object notes
    pull                    Fetch from and integrate with another repository or a local branch
    push                    Update remote refs along with associated objects
    range-diff              Compare two commit ranges (e.g. two versions of a branch)
    rebase                  Reapply commits on top of another base tip
    reset                   Reset current HEAD to the specified state
    restore                 Restore working tree files
    revert                  Revert some existing commits
    rm                      Remove files from the working tree and from the index
    scalar                  A tool for managing large Git repositories
    shortlog                Summarize 'git log' output
    show                    Show various types of objects
:

获取特定命令的帮助

要获取特定 Git 命令的帮助,您可以使用“git help” 命令后跟命令名称。此命令将在浏览器中显示手册页 (manpage)。

有三种等效的方法可以获取完整的 Git 命令手册页

要访问git commit 命令的手册页帮助,您可以使用以下任何方法

使用git help <command>

要获取有关特定 Git 命令的详细帮助,请使用以下语法

$ git help <command>

例如,要获取有关commit 命令的帮助,请运行

$ git help commit

使用man git-<command>

您可以使用man 命令后跟git-<command> 来查看特定 Git 命令的手册页。

$ man git-commit

使用 git <command> --help

您可以对任何git <command> 使用--help 来获取特定于该命令的帮助。

$ git commit --help

运行上述命令后,浏览器将显示如下所示的手册页。

git list show origin

要简要概述 Git 命令的选项,请使用git <command> -h(或 git help <command> -h)。这将简要概述命令的选项以及如何使用它们,而不会深入探讨手册页。

$ git commit -h
usage: git commit [-a | --interactive | --patch] [-s] [-v] [-u] [--amend]
    [--dry-run] [(-c | -C | --squash)  | --fixup [(amend|reword):])]
    [-F  | -m ] [--reset-author] [--allow-empty]
    [--allow-empty-message] [--no-verify] [-e] [--author=]
    [--date=] [--cleanup=] [--[no-]status]
    [-i | -o] [--pathspec-from-file= [--pathspec-file-nul]]
    [(--trailer [(=|:)])...] [-S[]]
    [--] [...]

-q, --[no-]quiet      suppress summary after successful commit
-v, --[no-]verbose    show diff in commit message template

Commit message options
-F, --[no-]file 
            read message from file
--[no-]author 
            override author for commit
--[no-]date     override date for commit
-m, --[no-]message 
            commit message
-c, --[no-]reedit-message 
            reuse and edit message from specified commit
-C, --[no-]reuse-message 
            reuse message from specified commit
--[no-]fixup [(amend|reword):]commit
            use autosquash formatted message to fixup or amend/reword specified commit
--[no-]squash 
            use autosquash formatted message to squash specified commit
--[no-]reset-author   the commit is authored by me now (used with -C/-c/--amend)
--trailer    add custom trailer(s)
-s, --[no-]signoff    add a Signed-off-by trailer
-t, --[no-]template 
            use specified template file
-e, --[no-]edit       force edit of commit
--[no-]cleanup  how to strip spaces and #comments from message
--[no-]status         include status in commit message template
-S, --[no-]gpg-sign[=]
            GPG sign commit

Commit contents options
-a, --[no-]all        commit all changed files
-i, --[no-]include    add specified files to index for commit
--[no-]interactive    interactively add files
-p, --[no-]patch      interactively add changes
-o, --[no-]only       commit only specified files
-n, --no-verify       bypass pre-commit and commit-msg hooks
--verify              opposite of --no-verify
--[no-]dry-run        show what would be committed
--[no-]short          show status concisely
--[no-]branch         show branch information
--[no-]ahead-behind   compute full ahead/behind values
--[no-]porcelain      machine-readable output
--[no-]long           show status in long format (default)
-z, --[no-]null       terminate entries with NUL
--[no-]amend          amend previous commit
--no-post-rewrite     bypass post-rewrite hook
--post-rewrite        opposite of --no-post-rewrite
-u, --[no-]untracked-files[=]
            show untracked files, optional modes: all, normal, no. (Default: all)
--[no-]pathspec-from-file 
            read pathspec from file
--[no-]pathspec-file-nul
            with --pathspec-from-file, pathspec elements are separated with NUL character

从 Git bash 获取 Git 指南

您可以使用以下命令从 Git Bash 访问 Git 指南。Git Bash 将显示各种概念,帮助您开始使用 Git。

$ git help -g

输出消息如下

The Git concept guides are:
core-tutorial    A Git core tutorial for developers
credentials      Providing usernames and passwords to Git
cvs-migration    Git for CVS users
diffcore         Tweaking diff output
everyday         A useful minimum set of commands for Everyday Git
faq              Frequently asked questions about using Git
glossary         A Git Glossary
namespaces       Git namespaces
remote-helpers   Helper programs to interact with remote repositories
submodules       Mounting one repository inside another
tutorial         A tutorial introduction to Git
tutorial-2       A tutorial introduction to Git: part two
workflows        An overview of recommended workflows with Git
 
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help ' or 'git help '
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system. 

您可以使用git help 命令后跟指南名称来访问 Git Bash 中的任何特定指南。

要访问git workflows 命令的手册指南页,可以使用以下命令

$ git help workflows

运行上述命令后,浏览器将显示如下所示的手册页。

git list show origin
广告