git 列出所有可用命令

发布于 2024-12-11 08:10:21 字数 1739 浏览 0 评论 0 原文

是否有命令可以显示 GIT 中所有可用命令的列表?有 git help 但它显示:

usage: git [--version] [--exec-path[=<path>]] [--html-path]
           [-p|--paginate|--no-pager] [--no-replace-objects]
           [--bare] [--git-dir=<path>] [--work-tree=<path>]
           [-c name=value] [--help]
           <command> [<args>]

The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and merge with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG

See 'git help <command>' for more information on a specific command.

而且我只想列出没有描述的内容。

Is there command which can show me list of all available commands in GIT? There is git help but it shows:

usage: git [--version] [--exec-path[=<path>]] [--html-path]
           [-p|--paginate|--no-pager] [--no-replace-objects]
           [--bare] [--git-dir=<path>] [--work-tree=<path>]
           [-c name=value] [--help]
           <command> [<args>]

The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and merge with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG

See 'git help <command>' for more information on a specific command.

And I want just list without description.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

伪心 2024-12-18 08:10:21

尝试:

git help -a

Try:

git help -a

勿忘心安 2024-12-18 08:10:21

正如 @CharlesBailey 已经建议的那样,git help -a 是列出 git 提供的所有子命令的好方法。但是,如果您想删除 git 打印的一些格式,也可以这样做:

获取所有 git 子命令列表的最简单方法如下:

git help -a | grep "^  [a-z]" | tr ' ' '\n' | grep -v "^$"

这需要 git help -a 的输出code>,仅选择缩进的行,将空格转换为换行符,然后删除空行。

你为什么想要这样的东西?想要列出命令的子命令的一个常见原因是在 Bash 中启用自动补全:

complete -W "$(git help -a | grep "^  [a-z]")" git

现在,当您输入 git br 并按 TAB 时,它会自动补全为 git 分支。享受!

As @CharlesBailey already suggested, git help -a is a great way to list all of the subcommands that git offers. However, if you want to remove some of the formatting that git prints, that can be done too:

The easiest way to get a list of all git subcommands is as follows:

git help -a | grep "^  [a-z]" | tr ' ' '\n' | grep -v "^$"

This takes the output of git help -a, selects only the lines that are indented, converts spaces to newline characters, and then removes the empty lines.

Why would you want something like this? A common reason for wanting to list the subcommands of a command is to enable autocompletion in Bash:

complete -W "$(git help -a | grep "^  [a-z]")" git

Now, when you type git br and press TAB, it autocompletes to git branch. Enjoy!

夜雨飘雪 2024-12-18 08:10:21

您可以使用 git--listcmds 参数:

$ git --list-cmds=main,nohelpers | sort
add
am
annotate
apply
archive
bisect
...

制表符补全引用在另一个答案中似乎使用以下内容来生成其列表(在/usr/share/bash-completion/completions/git中找到):

git --list-cmds=main,others,alias,nohelper

请注意此参数的文档:

这是一个内部/实验选项,将来可能会更改或删除。

You can use the --listcmds argument to git:

$ git --list-cmds=main,nohelpers | sort
add
am
annotate
apply
archive
bisect
...

The tab completion referred to in another answer seems to use the following to generate its list (found in /usr/share/bash-completion/completions/git):

git --list-cmds=main,others,alias,nohelper

Do note the caveat in the documentation of this parameter:

This is an internal/experimental option and may change or be removed in the future.

装纯掩盖桑 2024-12-18 08:10:21

如果您使用的是 Linux (BASH)。你可以尝试

`$ git [TAB] [TAB]`

然后我得到了这样的东西:

$ git 
add                 fetch               rebase 
am                  fetchavs            reflog 
annotate            filter-branch       relink 
apply               format-patch        remote 
archive             fsck                repack 
bisect              gc                  replace 
blame               get-tar-commit-id   request-pull 
br                  grep                reset 
branch              gui                 revert 
bundle              help                rm 
checkout            imap-send           shortlog 
cherry              init                show 
cherry-pick         instaweb            show-branch 
ci                  log                 st 
citool              log1                stage 
clean               merge               stash 
clone               mergetool           status 
co                  mv                  submodule 
commit              name-rev            svn 
config              notes               tag 
describe            pull                whatchanged 
diff                push                
difftool            pushav              

If you are using linux (BASH). You can try

`$ git [TAB] [TAB]`

Then I got something like this:

$ git 
add                 fetch               rebase 
am                  fetchavs            reflog 
annotate            filter-branch       relink 
apply               format-patch        remote 
archive             fsck                repack 
bisect              gc                  replace 
blame               get-tar-commit-id   request-pull 
br                  grep                reset 
branch              gui                 revert 
bundle              help                rm 
checkout            imap-send           shortlog 
cherry              init                show 
cherry-pick         instaweb            show-branch 
ci                  log                 st 
citool              log1                stage 
clean               merge               stash 
clone               mergetool           status 
co                  mv                  submodule 
commit              name-rev            svn 
config              notes               tag 
describe            pull                whatchanged 
diff                push                
difftool            pushav              
坚持沉默 2024-12-18 08:10:21

要列出 git 命令,包括 $PATH 上其他地方可用的 git 命令

git help -a

要列出用户配置的别名,请使用

git aliases

To list git commands, inluding git commands available from elsewhere on your $PATH

git help -a

To list user-configured aliases use

git aliases

淤浪 2024-12-18 08:10:21

使用 Git 2.36(2022 年第 2 季度),“git help -a"(man) 有新选项,有助于过滤/澄清命令列表。

请参阅 提交 93de1b6提交 1ce5901, 提交 503cdda, 提交 5e8068b, 提交 d7f817d, 提交 6fb427a, 提交 bf7eed7, 提交 cd87ce7, 提交 4bf5cda(2022 年 2 月 21 日),作者:Ævar Arnfjörð Bjarmason (avar)
(由 Junio C Hamano -- gitster -- 合并于 提交 1f3c5f3,2022 年 3 月 9 日)

帮助:添加-- no-[external-commands|aliases] 用于使用--全部

签字人:Ævar Arnfjörð Bjarmason

添加在 --all 下仅发出 git 自己的使用信息的功能。

这还允许我们扩展之前提交中添加的 "test_section_spacing" 测试来测试“git help --all"(man) 输出。

以前我们无法这样做,因为测试可能会在“$PATH”中找到 git-* 命令,这会使输出因设置而异。

git help 现在包含在其 手册页

'git help' [-a|--all] [--[no-]verbose] [--[no-]external-commands] [--[no-]aliases]

git help 现在包含在其 手册页

--无外部命令

--all 一起使用时,排除外部“git-*”的列表
$PATH 中找到的命令。

--无别名

--all一起使用时,排除已配置的列表
别名。

With Git 2.36 (Q2 2022), "git help -a"(man) has new options which helps filter/clarify the list of commands.

See commit 93de1b6, commit 1ce5901, commit 503cdda, commit 5e8068b, commit d7f817d, commit 6fb427a, commit bf7eed7, commit cd87ce7, commit 4bf5cda (21 Feb 2022) by Ævar Arnfjörð Bjarmason (avar).
(Merged by Junio C Hamano -- gitster -- in commit 1f3c5f3, 09 Mar 2022)

help: add --no-[external-commands|aliases] for use with --all

Signed-off-by: Ævar Arnfjörð Bjarmason

Add the ability to only emit git's own usage information under --all.

This also allows us to extend the "test_section_spacing" tests added in a preceding commit to test "git help --all"(man) output.

Previously we could not do that, as the tests might find a git-* command in the "$PATH", which would make the output differ from one setup to another.

git help now includes in its man page:

'git help' [-a|--all] [--[no-]verbose] [--[no-]external-commands] [--[no-]aliases]

git help now includes in its man page:

--no-external-commands

When used with --all, exclude the listing of external "git-*"
commands found in the $PATH.

--no-aliases

When used with --all, exclude the listing of configured
aliases.

始终不够爱げ你 2024-12-18 08:10:21

来源:https://thenucleargeeks.com/2020/01/20 /git-commands-cheat-sheet/

Windows: Use Chocolatey and in powershell type

choco install git
Linux:

ubuntu: sudo apt-get update && sudo apt-get install git -redhat: sudo yum install git -h
Mac OS:

install Homebrew and Xcode
Set a user name which can be seen or associated with every commit

git config --global user.name "nuclear geeks"
Set a user email which can we seen or associated with every commit

git config --global user.email "[email protected]"
Clone an existing repository

git clone url
Check the modified file in working directory.

git status
Add a modified file to staging area.

git add <file_name>
Add all the modified file to staging area

git add . 
Commit message

git commit -m "commit_message"
Difference between working area and staging

git diff <file_name>
Difference between working area and last commit or repository

git diff HEAD <file_name>
Difference between staging area and repository

git diff --staged 
git diff --staged <file_name>
List all your branches

git branch 
Create new branch

git checkout -b <branch_name>
Push the branch to origin

git push origin <branch_name>
Switch to another branch

git checkout <branch_name>
Merge branches

git merge <branch_name>
Backout File, If you want to move your file from stage area to working or unstage area

git reset HEAD <file_name>
Discard changes in working directory

git checkout <file_name>
Delete file

git rm <file_name>
Rename a file

git mv <current_name> <new_name>
Move a file

git mv <file_name> <dir_name>
Git alias, renaming command to new name

git config -global alias. <short_command> <"long command">
Find hidden file

git ls -al 
Stash your changes

git stash
To apply your changed from stash

git stash apply
To delete your stash from the list

git stash drop
To list your stash list

git stash list 
To apply the changes and delete from the listt

git stash pop
Git stash with message

git stash save "msg"
Find change done in specific index

git stash show stash@{id}
Apply

git stash apply stash@{id}
Tag creation

git tag <tag_name>
Annotated tag creation

git tag -a <tag_name>
Push tag to remote

git push origin <tag_name>
List all the tags

git tag --list
Delete tags

git tag --delete <tag_name>
Create a branch from the tag

git checkout -b <branch_name> <tagname>
Create a tag from past commit

git tag <tag_name> <reference_of_commit>

Source: https://thenucleargeeks.com/2020/01/20/git-commands-cheat-sheet/

Windows: Use Chocolatey and in powershell type

choco install git
Linux:

ubuntu: sudo apt-get update && sudo apt-get install git -redhat: sudo yum install git -h
Mac OS:

install Homebrew and Xcode
Set a user name which can be seen or associated with every commit

git config --global user.name "nuclear geeks"
Set a user email which can we seen or associated with every commit

git config --global user.email "[email protected]"
Clone an existing repository

git clone url
Check the modified file in working directory.

git status
Add a modified file to staging area.

git add <file_name>
Add all the modified file to staging area

git add . 
Commit message

git commit -m "commit_message"
Difference between working area and staging

git diff <file_name>
Difference between working area and last commit or repository

git diff HEAD <file_name>
Difference between staging area and repository

git diff --staged 
git diff --staged <file_name>
List all your branches

git branch 
Create new branch

git checkout -b <branch_name>
Push the branch to origin

git push origin <branch_name>
Switch to another branch

git checkout <branch_name>
Merge branches

git merge <branch_name>
Backout File, If you want to move your file from stage area to working or unstage area

git reset HEAD <file_name>
Discard changes in working directory

git checkout <file_name>
Delete file

git rm <file_name>
Rename a file

git mv <current_name> <new_name>
Move a file

git mv <file_name> <dir_name>
Git alias, renaming command to new name

git config -global alias. <short_command> <"long command">
Find hidden file

git ls -al 
Stash your changes

git stash
To apply your changed from stash

git stash apply
To delete your stash from the list

git stash drop
To list your stash list

git stash list 
To apply the changes and delete from the listt

git stash pop
Git stash with message

git stash save "msg"
Find change done in specific index

git stash show stash@{id}
Apply

git stash apply stash@{id}
Tag creation

git tag <tag_name>
Annotated tag creation

git tag -a <tag_name>
Push tag to remote

git push origin <tag_name>
List all the tags

git tag --list
Delete tags

git tag --delete <tag_name>
Create a branch from the tag

git checkout -b <branch_name> <tagname>
Create a tag from past commit

git tag <tag_name> <reference_of_commit>
苍风燃霜 2024-12-18 08:10:21

我知道这是一个古老的问题并且已经得到了解答,但我最近在寻找一些操纵器时遇到了这个难题,并发现它们没有被 git 的 bash 补全列出。

传递参数:

列表主瓷器、列表辅助询问器、列表辅助操纵器、列表管道操纵器、列表管道询问器、列表同步存储库、列表同步帮助器、列表纯帮助器

到“git --list-cmds”将生成 git 可用的每个命令的列表如下例所示。

 git --list-cmds=list-mainporcelain,list-ancillaryinterrogators,list-ancillarymanipulators,list-plumbingmanipulators,list-plumbinginterrogators,list-synchingrepositories,list-synchelpers,list-purehelpers|sort -u

我还为 bash 补全编写了一个补丁,因此当您输入 git [tab][tab] 时,它实际上会显示所有可用的命令,即使并非每个命令都有特定命令的参数补全.

--- /tmp/bash-completions-git   2024-01-16 13:30:01.068501500 -0500
+++ /usr/share/bash-completion/completions/git  2024-01-16 13:55:30.857304100 -0500
@@ -1131,11 +1131,16 @@
    return 1
 }
 
-__git_all_commands=
+
+#__git_all_commands=
 __git_compute_all_commands ()
 {
-   test -n "$__git_all_commands" ||
-   __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
+   test -n "$__git_all_commands" || (
+   # Their original code
+   # __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
+   # my much better command that actually gets ALL git commands.
+   __git_all_commands=$(git help -a | grep -P '^\s+[a-z]' | awk '{print $1}' | sort -u)
+   )
 }
 
 # Lists all set config variables starting with the given section prefix,
@@ -3562,13 +3567,13 @@
            then
                __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
            else
-               local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
+               local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config,list-ancillaryinterrogators,list-ancillarymanipulators,list-plumbingmanipulators,list-plumbinginterrogators
 
                if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1"
                then
                    list_cmds=builtins,$list_cmds
                fi
-               __gitcomp "$(__git --list-cmds=$list_cmds)"
+               __gitcomp "$(__git --list-cmds=$list_cmds|sort -u)"
            fi
            ;;
        esac

当你忘记像 ls-tree 这样的东西时,它非常方便。

$ git       
Display all 116 possibilities? (y or n)
add                 commit-tree         gitk                merge-tree          replace             submodule 
am                  config              gitweb              mktag               request-pull        switch 
annotate            count-objects       grep                mktree              rerere              symbolic-ref 
apply               describe            gui                 multi-pack-index    reset               tag 
archive             diagnose            hash-object         mv                  restore             unpack-file 
bisect              diff                help                name-rev            revert              unpack-objects 
blame               diff-files          index-pack          notes               rev-list            update-index 
branch              diff-index          init                pack-objects        rev-parse           update-ref 
bugreport           difftool            instaweb            pack-redundant      rm                  var 
bundle              diff-tree           lfs                 pack-refs           scalar              verify-commit 
cat-file            fast-export         log                 prune               send-email          verify-pack 
checkout            fast-import         ls-files            prune-packed        shortlog            verify-tag 
checkout-index      fetch               ls-remote           pull                show                version 
cherry              filter-branch       ls-tree             push                show-branch         whatchanged 
cherry-pick         for-each-ref        maintenance         range-diff          show-index          worktree 
citool              for-each-repo       merge               read-tree           show-ref            write-tree 
clean               format-patch        merge-base          rebase              sparse-checkout     
clone               fsck                merge-file          reflog              stage               
commit              gc                  merge-index         remote              stash               
commit-graph        get-tar-commit-id   mergetool           repack              status 

I know this is an ancient question and it has already been answered, but I recently ran into this conundrum while looking for some of the manipulators and saw that they weren't being listed by the bash completions for git.

Passing the arguments:

list-mainporcelain,list-ancillaryinterrogators,list-ancillarymanipulators,list-plumbingmanipulators,list-plumbinginterrogators,list-synchingrepositories,list-synchelpers,list-purehelpers

to "git --list-cmds" will produce a list of every command git has available as seen in the example below.

 git --list-cmds=list-mainporcelain,list-ancillaryinterrogators,list-ancillarymanipulators,list-plumbingmanipulators,list-plumbinginterrogators,list-synchingrepositories,list-synchelpers,list-purehelpers|sort -u

I've also written a patch for the bash completions as well so when you type out git [tab][tab] it will actually show all the commands available even if not every one of them has argument completion for the specific command.

--- /tmp/bash-completions-git   2024-01-16 13:30:01.068501500 -0500
+++ /usr/share/bash-completion/completions/git  2024-01-16 13:55:30.857304100 -0500
@@ -1131,11 +1131,16 @@
    return 1
 }
 
-__git_all_commands=
+
+#__git_all_commands=
 __git_compute_all_commands ()
 {
-   test -n "$__git_all_commands" ||
-   __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
+   test -n "$__git_all_commands" || (
+   # Their original code
+   # __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers)
+   # my much better command that actually gets ALL git commands.
+   __git_all_commands=$(git help -a | grep -P '^\s+[a-z]' | awk '{print $1}' | sort -u)
+   )
 }
 
 # Lists all set config variables starting with the given section prefix,
@@ -3562,13 +3567,13 @@
            then
                __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST"
            else
-               local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
+               local list_cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config,list-ancillaryinterrogators,list-ancillarymanipulators,list-plumbingmanipulators,list-plumbinginterrogators
 
                if test "${GIT_COMPLETION_SHOW_ALL_COMMANDS-}" = "1"
                then
                    list_cmds=builtins,$list_cmds
                fi
-               __gitcomp "$(__git --list-cmds=$list_cmds)"
+               __gitcomp "$(__git --list-cmds=$list_cmds|sort -u)"
            fi
            ;;
        esac

It's quite handy when you forget things like ls-tree.

$ git       
Display all 116 possibilities? (y or n)
add                 commit-tree         gitk                merge-tree          replace             submodule 
am                  config              gitweb              mktag               request-pull        switch 
annotate            count-objects       grep                mktree              rerere              symbolic-ref 
apply               describe            gui                 multi-pack-index    reset               tag 
archive             diagnose            hash-object         mv                  restore             unpack-file 
bisect              diff                help                name-rev            revert              unpack-objects 
blame               diff-files          index-pack          notes               rev-list            update-index 
branch              diff-index          init                pack-objects        rev-parse           update-ref 
bugreport           difftool            instaweb            pack-redundant      rm                  var 
bundle              diff-tree           lfs                 pack-refs           scalar              verify-commit 
cat-file            fast-export         log                 prune               send-email          verify-pack 
checkout            fast-import         ls-files            prune-packed        shortlog            verify-tag 
checkout-index      fetch               ls-remote           pull                show                version 
cherry              filter-branch       ls-tree             push                show-branch         whatchanged 
cherry-pick         for-each-ref        maintenance         range-diff          show-index          worktree 
citool              for-each-repo       merge               read-tree           show-ref            write-tree 
clean               format-patch        merge-base          rebase              sparse-checkout     
clone               fsck                merge-file          reflog              stage               
commit              gc                  merge-index         remote              stash               
commit-graph        get-tar-commit-id   mergetool           repack              status 
§普罗旺斯的薰衣草 2024-12-18 08:10:21

克隆 url 的命令:git clone url

检查状态的命令:git status

添加文件的命令:git add pom.xml git添加 src/

命令提交代码并带有消息:git commit -m "initial version"

命令推送:git push -u origin master

命令清除 git终端: clear

命令来签出不同的分支: git checkout -bbranch-name

命令添加文件: git add src/main/java/com/rest/mongo/UserExample.java

命令从不同分支提取更新:git pull origindevelop

命令推送到上游:git push --set-upstream origin 11111feature-234

将分支合并到develop/master分支的步骤: git 结帐-b开发
git merge your-branch-name

参考以下链接:(逐步说明)

https://www.youtube.com/watch?v=tzZj-bnjX6w&t=17s

command for clone url: git clone url

command to check status: git status

command to add file: git add pom.xml git add src/

command to commit code with message: git commit -m "initial version"

command to push: git push -u origin master

command to clear git terminal: clear

command to checkout different branch: git checkout -b branch-name

command to add file: git add src/main/java/com/rest/mongo/UserExample.java

command to pull updates from different branch: git pull origin develop

command to push through upstream: git push --set-upstream origin 11111feature-234

steps to merge your branch to develop/master branch: git checkout -b develop
git merge your-branch-name

for reference use below link:(step by step explanation)

https://www.youtube.com/watch?v=tzZj-bnjX6w&t=17s

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文