git列出所有可用命令

qv7cva1a  于 2023-01-15  发布在  Git
关注(0)|答案(8)|浏览(139)

是否有命令可以显示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.

我只想要没有描述的清单。

t0ybt7op

t0ybt7op1#

试试看:

git help -a
bd1hkmkf

bd1hkmkf2#

正如@CharlesBailey所建议的,git help -a是一个列出git提供的所有子命令的好方法,但是,如果你想删除git打印的一些格式,你也可以这么做:
获取所有git子命令列表的最简单方法如下:

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

它接受git help -a的输出,只选择缩进的行,将空格转换为换行符,然后删除空行。
为什么你会想要这样的东西?想要列出一个命令的子命令的一个常见原因是在Bash中启用自动完成:

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

现在,当您键入git br并按TAB时,它会自动完成为git branch

qrjkbowd

qrjkbowd3#

如果您使用的是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
gwo2fgha

gwo2fgha4#

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

git help -a

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

git aliases
b1payxdu

b1payxdu5#

在Git 2.36(Q2 2022)中,"git help -a"(man)有了新的选项来帮助过滤/澄清命令列表。
请参见第Ævar Arnfjörð Bjarmason ( avar )条的第commit 93de1b6条、第commit 1ce5901条、第commit 503cdda条、第commit 5e8068b条、第commit d7f817d条、第commit 6fb427a条、第commit bf7eed7条、第commit cd87ce7条、第commit 4bf5cda条(2022年2月21日)。
(由Junio C Hamano -- gitster --合并至commit 1f3c5f3,2022年3月9日)

help:添加--no-[external-commands|aliases]以与--all一起使用

签署人:埃瓦尔·阿恩菲约德·比亚尔马森
--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现在在其手册页中包括:

--no-external-commands

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

--no-aliases

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

nhaq1z21

nhaq1z216#

可以将--listcmds参数用于git

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

tab completion referred to in another answer似乎使用以下内容来生成其列表(在/usr/share/bash-completion/completions/git中找到):

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

请注意此参数文档中的警告:
这是一个内部/实验选项,将来可能会更改或删除。

k3bvogb1

k3bvogb17#

来源: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 "nucleargeeks18@gmail.com"
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>
uqcuzwp8

uqcuzwp88#

用于克隆url的命令:git clone url
检查状态的命令:git status
添加文件命令:x1米2英寸x1米3英寸
命令提交代码,消息为:git commit -m "initial version"
要推送的命令:git push -u origin master
清除git终端的命令:clear
checkout 不同分支命令:git checkout -b branch-name
添加文件命令:git add src/main/java/com/rest/mongo/UserExample.java
从不同分支提取更新命令:git pull origin develop
命令通过上游推送:git push --set-upstream origin 11111feature-234
合并分支到develop/master分支的步骤:一个月十一个月一个月一个月一个月十二个月一个月

    • 请使用以下链接作为参考:(逐步说明)**

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

相关问题