git 列出所有可用的命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7866353/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:09:03  来源:igfitidea点击:

git list all available commands

gitubuntu

提问by skowron-line

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

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

And I want just list without description.

我只想列出而没有描述。

回答by CB Bailey

Try:

尝试:

git help -a


回答by Adam Stewart

As @CharlesBailey already suggested, git help -ais 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:

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

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

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

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.

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

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:

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

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

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

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

回答by Enze Chi

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

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

`$ 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              

回答by reducing activity

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

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

git help -a


To list user-configured aliases use

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

git aliases


回答by Dheeraj kumar

command for clone url: git clone url

克隆 url 命令: git clone url

command to check status: git status

检查状态的命令: git status

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

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

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

使用消息提交代码的命令: git commit -m "initial version"

command to push: git push -u origin master

推送命令: git push -u origin master

command to clear git terminal: clear

清除git终端的命令: clear

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

结帐不同分支的命令: git checkout -b branch-name

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

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

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

从不同分支拉取更新的命令: git pull origin develop

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

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

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

将分支合并到开发/主分支的步骤: git checkout -b developgit merge your-branch-name

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

以下链接供参考使用:(分步说明)

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

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

回答by Aditya

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

来源: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>