写了那么多笔记还是使用的过程中,因为脑容量有限还是出现断片的情况,当然也是因为不够熟练的原因,所以特写此对照录方便查漏补缺,不断加深印象,提高自己的使用效率,!
 1. Git cheat sheet🔥

 2. 最起码的,安装Git这个神器
- Linux:
sudo apt-get install git-core 
- Windows:官网下载安装包
 
 3. 首先得配置本台设备使用的Git账号
1 2 3
   | git config --global user.mail "980298390@qq.com"
  git config --global user.name "MCUheart"
   | 
 
 3.1. 创建SSH部署公钥
ssh-keygen -t rsa -C “980298390@qq.com”,生成ssh。然后按下图的方式找到用户目录.SSH下id_rsa.pub文件的内容。
在服务端添加公钥之后,验证公钥添加是否成功:
gitbash中验证是否添加成功:ssh -T 98xx98x90@qq.com(ssh -T git@github.com)
 4. 最基础的,初始化本地仓库,生成相应.git配置文件
 5. tag-release正式版本快捷操作
1 2 3 4 5 6 7 8 9 10 11
   | ----创建tag---- $ git tag -a 1.0.2 -m "1.0.2版本:xxxxx" $ git push origin 1.0.2
 
 
  ----删除tag---- $ git tag -d 1.0.2   $ git push origin :1.0.2 / git push origin --delete tag 1.0.2 
 
 
   | 
 
 6. 各服务商目前版本操作的差异(总结这个我觉得  我是真的闲,因为我踩了他们挖了一地的坑🙀😢)
 6.1. 地址差异:
 6.1.1. Github 地址
github.com
 6.1.2. Gitee 地址
gitee.com
 6.1.3. Coding 地址
e.coding.net
 6.2. Pages差异:
 6.2.1. Github Pages
格式为xxxx.github.io
 6.2.2. Gitee Pages
格式为xxxx,xxxx必须与用户名同名,如果以Github pages的方式生成,需要在域名后面加上该仓库名为二级目录才是自己的个人主页,参考官方文档
 6.2.3. Coding Pages
格式为xxxx.coding.me,生成的主页网址会在设置后固定一个pages网址,域名绑定时不使用通用的e.coding.io这样的CNAME,而是分配给的固定的那个pages网址!
 6.3. Access token(个人令牌)使用差异:
 6.3.1. Github Access token
- 
https:<git command> https://<用户名>:<设置的个人令牌号>@github.com/<仓库名>/<用户名>.git/<git command> https://<设置的个人令牌号>@github.com/<仓库名>/<用户名>.git
 
- 
SSH:<git command> git@<用户名>:<设置的个人令牌号>@github.com/<仓库名>/<用户名>.git/<git command> git@<设置的个人令牌号>@github.com/<仓库名>/<用户名>.git
亲测以上另种方式都可。
 
 6.3.2. Gitee Access token
- https:
<git command> https://<用户名>:<设置的个人令牌号>@gitee.com/<仓库名>/<用户名>.git 
- SSH:
<git command> git@<用户名>:<设置的个人令牌号>@gitee.com/<仓库名>/<用户名>.git 
 6.3.3. Coding Access token
注意一下命令所使用的<用户名>是coding创建一个个人令牌时专门使用这个令牌的用户名!
你所使用的个人令牌
- https:
<git command> https://<用户名>:<设置的个人令牌号>@e.coding.net/<仓库名>/<用户名>.git 
- SSH:
<git command> git@<用户名>:<设置的个人令牌号>@e.coding.net/<仓库名>/<用户名>.git 
看完是不是觉得很坑爹哈!!!应该让他们打一架让个大哥统一一下使用格式!💩
 7. 命令分类
| 设置和配置 | 
获取和创建项目 | 
基本快照 | 
分支和合并 | 
git config help | 
init clone | 
add status diff commit reset rm mv | 
branch checkout merge mergetool log stash tag worktree | 
| 共享和更新项目 | 
检查和比较 | 
修补 | 
调试 | 
fetch pull push remote submodule | 
show log diff shortlog describe | 
apply cherry-pick diff rebase revert | 
bisect blame grep | 
 8. 各子命令详细示例🌞
 8.1. git
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
   | 语法:   git [--version] [--help] [-C <path>] [-c <name>=<value>]       [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]       [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]       [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]       [--super-prefix=<path>]       <command> [<args>]
  选项:     --version                    --help                       -C <path>                    -c <name>=<value>            --exec-path[=<path>]         --html-path                  --man-path                   --info-path                  -p, --paginate               --no-pager                   --no-replace-objects         --bare                       --git-dir=<path>             --work-tree=<path>           --namespace=<path>           --super-prefix=<path>        --literal-pathspecs          --glob-pathspecs             --noglob-pathspecs           --icase-pathspecs            --no-optional-locks     
   | 
 
 8.2. git config
配置 Git 的相关参数。
Git 一共有3个配置文件:
\1. 仓库级的配置文件:在仓库的 .git/.gitconfig,该配置文件只对所在的仓库有效。
\2. 全局配置文件:Mac 系统在 ~/.gitconfig,Windows 系统在 C:\Users\<用户名>\.gitconfig。
\3. 系统级的配置文件:在 Git 的安装目录下(Mac 系统下安装目录在 /usr/local/git)的 etc 文件夹中的 gitconfig。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
   | 
  $ git config <--local | --global | --system> -l
 
  $ git config -l
 
 
  $ git config <--local | --global | --system> -e
 
 
  $ git config <--local | --global | --system> --add <name> <value>
 
  $ git config <--local | --global | --system> --get <name>
 
  $ git config <--local | --global | --system> --unset <name>
 
  $ git config --global user.name <用户名> $ git config --global user.email <邮箱地址>
 
 
 
  $ git config --global http.postBuffer <缓存大小>
 
  $ git config --global color.ui true
 
  $ git config --global credential.helper cache
 
 
  $ git config --global credential.helper 'cache --timeout=<缓存时间>'
 
  $ git config --global credential.helper store
  语法:   git config [<file-option>] [type] [--show-origin] [-z|--null] name [value [value_regex]]   git config [<file-option>] [type] --add name value   git config [<file-option>] [type] --replace-all name value [value_regex]   git config [<file-option>] [type] [--show-origin] [-z|--null] --get name [value_regex]   git config [<file-option>] [type] [--show-origin] [-z|--null] --get-all name [value_regex]   git config [<file-option>] [type] [--show-origin] [-z|--null] [--name-only] --get-regexp name_regex [value_regex]   git config [<file-option>] [type] [-z|--null] --get-urlmatch name URL   git config [<file-option>] --unset name [value_regex]   git config [<file-option>] --unset-all name [value_regex]   git config [<file-option>] --rename-section old_name new_name   git config [<file-option>] --remove-section name   git config [<file-option>] [--show-origin] [-z|--null] [--name-only] -l | --list   git config [<file-option>] --get-color name [default]   git config [<file-option>] --get-colorbool name [stdout-is-tty]   git config [<file-option>] -e | --edit
  选项:     --system                                 --global                                 --local                                  -f <filename>, --file <filename>         --blob <blob-id>                         --int                                    --bool                                   --bool-or-int                            --path                                   --replace-all                            --add                                    --get                                    --get-all                                --get-regexp                             --get-urlmatch name URL                  --remove-section                         --rename-section                         --unset                                  --unset-all                              -l, --list                               --expiry-date                            -z, --null                               --name-only                              --show-origin                            --get-colorbool name [stdout-is-tty]     --get-color name [default]               -e, --edit                               --[no-]includes                     
 
  | 
 
 8.3. git help
1 2 3 4 5 6 7 8 9 10
   | 语法:   git help [-a|--all] [-g|--guide]          [-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE]
  选项:     -a, --all                -g, --guide              -i, --info               -m, --man                -w, --web           
   | 
 
 8.4. git clone
从远程仓库克隆一个版本库到本地。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
   |  $ git clone <远程仓库的网址>
 
  $ git clone <远程仓库的网址> <本地目录>
 
  $ git clone <远程仓库的网址> -b <分支名称> <本地目录>
  语法:     git clone [--template=<template_directory>]         [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]         [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]         [--dissociate] [--separate-git-dir <git dir>]         [--depth <depth>] [--[no-]single-branch] [--no-tags]         [--recurse-submodules[=<pathspec>]] [--[no-]shallow-submodules]         [--jobs <n>] [--] <repository> [<directory>]
  选项:             -l, --local                             --no-hardlinks                          -s, --shared                            --reference[-if-able] <repository>      --dissociate                            -q, --quiet                             -v, --verbose                           --progress                              -n, --no-checkout                       --bare                                  --mirror                                -o <name>, --origin <name>              -b <name>, --branch <name>              -u <upload-pack>, --upload-pack <upload-pack>       --template=<template_directory>                     -c <key>=<value>, --config <key>=<value>            --depth <depth>                                     --shallow-since=<date>                              --shallow-exclude=<revision>                        --[no-]single-branch                      --no-tags                             --recurse-submodules[=<pathspec]                    --[no-]shallow-submodules                           --separate-git-dir=<git dir>                        -j <n>, --jobs <n>                                  <repository>                                        <directory>                                    
 
  | 
 
 8.5. git init
初始化项目所在目录,初始化后会在当前目录下出现一个名为 .git 的目录。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
   |  $ git init
  语法:         git init [-q | --quiet] [--bare] [--template=<template_directory>]         [--separate-git-dir <git dir>]         [--shared[=<permissions>]] [directory]
  选项:     -q, --quiet                                    --bare                                         --template=<template_directory>                --separate-git-dir=<git dir>                   --shared[=(false|true|umask|group|all|world|everybody|0xxx)]          umask (or false)                               group (or true)                                all (or world or everybody)                    0xxx                                                                   0640将创建一个组可读的存储库, 但不能对其他组进行写入或访问。0660将创建一个对当前用户和组可读可写的回购, 但其他人无法访问。
 
  | 
 
 8.6. git status
查看本地仓库的状态。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
   |  $ git status
 
 
 
  $ git status -s
  语法:     git status [<options>…] [--] [<pathspec>…]
  选项:     -s, --short                                    -b, --branch                                   --show-stash                                   --porcelain[=<version>]                        --long                                         -v, --verbose                                  -u[<mode>], --untracked-files[=<mode>]         --ignore-submodules[=<when>]                   --ignored[=<mode>]                                 traditional                                    no                                             matching                                   -z                                             --no-column, --column[=<options>]              --ahead-behind, --no-ahead-behind              <pathspec>…                               
 
  | 
 
 8.7. git remote
操作远程库。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
   |  $ git remote
 
  $ git remote -v $ git remote --verbose
 
  $ git remote add <远程仓库的别名> <远程仓库的URL地址>
 
  $ git remote rename <原远程仓库的别名> <新的别名>
 
  $ git remote remove <远程仓库的别名>
 
  $ git remote set-url <远程仓库的别名> <新的远程仓库URL地址>
  语法:     git remote [-v | --verbose]     git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>     git remote rename <old> <new>     git remote remove <name>     git remote set-head <name> (-a | --auto | -d | --delete | <branch>)     git remote set-branches [--add] <name> <branch>…     git remote get-url [--push] [--all] <name>     git remote set-url [--push] <name> <newurl> [<oldurl>]     git remote set-url --add [--push] <name> <newurl>     git remote set-url --delete [--push] <name> <url>     git remote [-v | --verbose] show [-n] <name>…     git remote prune [-n | --dry-run] <name>…     git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)…]
  选项:     -v, --verbose            add                      rename                   rm,    remove            set-head                 set-branches             get-url                  set-url                  show                     prune                    update              
 
  | 
 
 8.8. git branch
操作 Git 的分支命令。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
   |  $ git branch
 
  $ git branch -v
 
  $ git branch <分支名>
 
 
  $ git branch -m [<原分支名称>] <新的分支名称>
  $ git branch -M [<原分支名称>] <新的分支名称>
 
  $ git branch -d <分支名称>
 
  $ git branch -D <分支名称>
  语法:     git branch [--color[=<when>] | --no-color] [-r | -a]         [--list] [-v [--abbrev=<length> | --no-abbrev]]         [--column[=<options>] | --no-column] [--sort=<key>]         [(--merged | --no-merged) [<commit>]]         [--contains [<commit]] [--no-contains [<commit>]]         [--points-at <object>] [--format=<format>] [<pattern>…]     git branch [--track | --no-track] [-l] [-f] <branchname> [<start-point>]     git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]     git branch --unset-upstream [<branchname>]     git branch (-m | -M) [<oldbranch>] <newbranch>     git branch (-c | -C) [<oldbranch>] <newbranch>     git branch (-d | -D) [-r] <branchname>…     git branch --edit-description [<branchname>]
  选项:     -d, --delete                                      -D                                                -l, --create-reflog                               -f, --force                                       -m, --move                                        -M                                                -c, --copy                                        -C                                                --color[=<when>]                                  --no-color                                        -i, --ignore-case                                 --column[=<options>], --no-column                 -r, --remotes                                     -a, --all                                         --list                                            -v, -vv, --verbose                                -q, --quiet                                       --abbrev=<length>                                 --no-abbrev                                       -t, --track                                       --no-track                                        --set-upstream                                    -u <upstream>, --set-upstream-to=<upstream>       --unset-upstream                                  --edit-description                                --contains [<commit>]                             --no-contains [<commit>]                          --merged [<commit>]                               --no-merged [<commit>]                            <branchname>                                      <start-point>                                     <oldbranch>                                       <newbranch>                                       --sort=<key>                                      --points-at <object>                              --format <format>                            
 
  | 
 
 8.9. git checkout
检出命令,用于创建、切换分支等。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
   |  $ git checkout <分支名称>
 
 
  $ git checkout -b <分支名称>
 
  $ git checkout --orphan <分支名称>
 
  $ git checkout <文件路径>
  语法:     git checkout [-q] [-f] [-m] [<branch>]     git checkout [-q] [-f] [-m] --detach [<branch>]     git checkout [-q] [-f] [-m] [--detach] <commit>     git checkout [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>]     git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>…     git checkout [<tree-ish>] [--] <pathspec>…     git checkout (-p|--patch) [<tree-ish>] [--] [<paths>…]
  选项:     -q, --quiet                          --[no-]progress                      -f, --force                          --ours, --theirs                     -b <new_branch>                      -B <new_branch>                      -t, --track                          --no-track                           -l                                   --detach                             --orphan <new_branch>                --ignore-skip-worktree-bits          -m, --merge                          --conflict=<style>                   -p, --patch                          --ignore-other-worktrees             --[no-]recurse-submodules            <branch>                             <new_branch>                         <start_point>                        <tree-ish>                      
 
  | 
 
 8.10. git rebase
rebase命令执行后,实际上是将分支点从C移到了G,这样分支也就具有了从C到G的功能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
   | 语法:     git rebase [-i | --interactive] [options] [--exec <cmd>] [--onto <newbase>]         [<upstream> [<branch>]]     git rebase [-i | --interactive] [options] [--exec <cmd>] [--onto <newbase>]         --root [<branch>]     git rebase --continue | --skip | --abort | --quit | --edit-todo | --show-current-patch  
  选项:     --onto <newbase>                           <upstream>                                 <branch>                                   --continue                                 --abort                                    --quit                                     --keep-empty                               --allow-empty-message                      --skip                                     --edit-todo                                --show-current-patch                       -m, --merge                                -s <strategy>, --strategy=<strategy>       -X <strategy-option>, --strategy-option=<strategy-option>         -S[<keyid>], --gpg-sign[=<keyid>]                    -q, --quiet                                          -v, --verbose                                        -stat                                                -n, --no-stat                                        --no-verify                                          --verify                                             -C<n>                                                -f, --force-rebase                                   --fork-point, --no-fork-point                        --ignore-whitespace, --whitespace=<option>           --committer-date-is-author-date, --ignore-date       --signoff                                            -i, --interactive                                    -p, --preserve-merges                                -x <cmd>, --exec <cmd>                               --root                                               --autosquash, --no-autosquash                        --autostash, --no-autostash                          --no-ff                                         
   | 
 
 8.11. git revert
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
   | 语法:     git revert [--[no-]edit] [-n] [-m parent-number] [-s] [-S[<keyid>]] <commit>…     git revert --continue     git revert --quit     git revert --abort
  选项:     <commit>…                                         -e, --edit                                        -m parent-number, --mainline parent-number        --no-edit                                         -n, --no-commit                                   -S[<keyid>], --gpg-sign[=<keyid>]                 -s, --signoff                                     --strategy=<strategy>                             -X<option>, --strategy-option=<option>            --continue                                        --quit                                            --abort                                      
   | 
 
 8.12. git bisect
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
   | 语法:     git bisect <subcommand> <options>     git bisect start [--term-{old,good}=<term> --term-{new,bad}=<term>]         [--no-checkout] [<bad> [<good>...]] [--] [<paths>...]     git bisect (bad|new|<term-new>) [<rev>]     git bisect (good|old|<term-old>) [<rev>...]     git bisect terms [--term-good | --term-bad]     git bisect skip [(<rev>|<range>)...]     git bisect reset [<commit>]     git bisect (visualize|view)     git bisect replay <logfile>     git bisect log     git bisect run <cmd>...     git bisect help
  选项:     --no-checkout                      
   | 
 
 8.13. git blame
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
   | 语法:     git blame [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental]             [-L <range>] [-S <revs-file>] [-M] [-C] [-C] [-C] [--since=<date>]             [--progress] [--abbrev=<n>] [<rev> | --contents <file> | --reverse <rev>..<rev>]             [--] <file>
  选项:     -b                                       --root                                   --show-stats                             -L <start>, <end>, -L :<funcname>        -l                                       -t                                       -S <revs-file>                           --reverse <rev>..<rev>                   -p, --porcelain                          --line-porcelain                         --incremental                            --encoding=<encoding>                    --contents <file>                        --date <format>                          --[no-]progress                          -M[<num>]                                -C[<num>]                                -h                                       -c                                       --score-debug                            -f, --show-name                          -n, --show-number                        -s                                       -e, --show-email                         -w                                       --abbrev=<n>                        
   | 
 
 8.14. git grep
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
   | 语法:     git grep [-a | --text] [-I] [--textconv] [-i | --ignore-case] [-w | --word-regexp]            [-v | --invert-match] [-h|-H] [--full-name]            [-E | --extended-regexp] [-G | --basic-regexp]            [-P | --perl-regexp]            [-F | --fixed-strings] [-n | --line-number]            [-l | --files-with-matches] [-L | --files-without-match]            [(-O | --open-files-in-pager) [<pager>]]            [-z | --null]            [-c | --count] [--all-match] [-q | --quiet]            [--max-depth <depth>]            [--color[=<when>] | --no-color]            [--break] [--heading] [-p | --show-function]            [-A <post-context>] [-B <pre-context>] [-C <context>]            [-W | --function-context]            [--threads <num>]            [-f <file>] [-e] <pattern>            [--and|--or|--not|(|)|-e <pattern>…]            [--recurse-submodules] [--parent-basename <basename>]            [ [--[no-]exclude-standard] [--cached | --no-index | --untracked] | <tree>…]            [--] [<pathspec>…]
  选项:     --cached                                          --no-index                                        --untracked                                       --no-exclude-standard                             --exclude-standard                                --recurse-submodules                              -a, --text                                        --textconv                                        --no-textconv                                     -i, --ignore-case                                 -I                                                --max-depth <depth>                               -w, --word-regexp                                 -v, --invert-match                                -h, -H                                            --full-name                                       -E, --extended-regexp, -G, --basic-regexp         -P, --perl-regexp                                 -F, --fixed-strings                               -n, --line-number                                 -l, --files-with-matches, --name-only, -L, --files-without-match         -O[<pager>], --open-files-in-pager[=<pager>]      -z, --null                                        -c, --count                                       --color[=<when>]                                  --no-color                                        --break                                           --heading                                         -p, --show-function                               -<num>, -C <num>, --context <num>                 -A <num>, --after-context <num>                   -B <num>, --before-context <num>                  -W, --function-context                            --threads <num>                                   -f <file>                                         -e                                                --and, --or, --not, ( … )                         --all-match                                       -q, --quiet                                       <tree>…                                           --                                                <pathspec>…                                  
   | 
 
 8.15. git stash
将当前未提交的工作存入Git工作栈中,时机成熟的时候再应用回来
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   | 语法:     git stash list [<options>]     git stash show [<stash>]     git stash drop [-q|--quiet] [<stash>]     git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]     git stash branch <branchname> [<stash>]     git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]              [-u|--include-untracked] [-a|--all] [-m|--message <message>]              [--] [<pathspec>…]]     git stash clear     git stash create [<message>]     git stash store [-m|--message <message>] [-q|--quiet] <commit>
  选项:     push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]                 [-u|--include-untracked] [-a|--all] [-m|--message <message>]         [--] [<pathspec>…]                      list [<options>]                            show [<stash>]                              pop [--index] [-q|--quiet] [<stash>]        apply [--index] [-q|--quiet] [<stash>]      branch <branchname> [<stash>]               clear                                       drop [-q|--quiet] [<stash>]                 create                                      store                                  
   | 
 
 8.16. git cherry-pick
把已经提交的记录合并到当前分支。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
   |  $ git cherry-pick <commit ID>
  语法:     git cherry-pick [--edit] [-n] [-m parent-number] [-s] [-x] [--ff]               [-S[<keyid>]] <commit>…     git cherry-pick --continue     git cherry-pick --quit     git cherry-pick --abort
  选项:     <commit>…                                         -e, --edit                                        -x                                                -r                                                -m parent-number, --mainline parent-number        -n, --no-commit                                   -s, --signoff                                     -S[<keyid>], --gpg-sign[=<keyid>]                 --ff                                              --allow-empty                                     --allow-empty-message                             --keep-redundant-commits                          --strategy=<strategy>                             -X<option>, --strategy-option=<option>            --continue                                        --quit                                            --abort                                      
 
  | 
 
 8.17. git add
把要提交的文件的信息添加到暂存区中。当使用 git commit 时,将依据暂存区中的内容来进行文件的提交。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
   |  $ git add <文件路径>
 
  $ git add -u [<文件路径>] $ git add --update [<文件路径>]
 
  $ git add -A [<文件路径>] $ git add --all [<文件路径>]
 
  $ git add -i [<文件路径>] $ git add --interactive [<文件路径>]
  语法:     git add [--verbose | -v] [--dry-run | -n] [--force | -f] [--interactive | -i] [--patch | -p]         [--edit | -e] [--[no-]all | --[no-]ignore-removal | [--update | -u]]         [--intent-to-add | -N] [--refresh] [--ignore-errors] [--ignore-missing] [--renormalize]         [--chmod=(+|-)x] [--] [<pathspec>…]
  选项:     -v, --verbose                        -n, --dry-run                        -f, --force                          -i, --interactive                    -p, --patch                          -e, --edit                           -u, --update                         -A, --all, --no-ignore-removal       --no-all, --ignore-removal           -N, --intent-to-add                  --refresh                            --ignore-errors                      --ignore-missing                     --no-warn-embedded-repo              --renormalize                        --chmod=(+|-)x                       --                                   <pathspec>…                     
 
  | 
 
 8.18. git commit
将暂存区中的文件提交到本地仓库中。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
   |  $ git commit
 
  $ git commit -m "<提交的描述信息>"
 
 
  $ git commit -a -m "<提交的描述信息>"
 
  $ git commit --amend
 
  $ git commit -m "updated files at `date +'%Y-%m-%d %H:%M:%S'`"
  语法:     git commit [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]        [--dry-run] [(-c | -C | --fixup | --squash) <commit>]        [-F <file> | -m <msg>] [--reset-author] [--allow-empty]        [--allow-empty-message] [--no-verify] [-e] [--author=<author>]        [--date=<date>] [--cleanup=<mode>] [--[no-]status]        [-i | -o] [-S[<keyid>]] [--] [<file>…]
  选项:     -a, --all                                    -p, --patch                                  -C <commit>, --reuse-message=<commit>        -c <commit>, --reedit-message=<commit>       --fixup=<commit>                             --squash=<commit>                            --reset-author                               --short                                      --branch                                     --porcelain                                  --long                                       -z, --null                                   -F <file>, --file=<file>                     --author=<author>                            --date=<date>                                -m <msg>, --message=<msg>                    -t <file>, --template=<file>                 -s, --signoff                                -n, --no-verify                              --allow-empty                                --allow-empty-message                        --cleanup=<mode>                             strip                                        whitespace                                   verbatim                                     scissors                                     default                                      -e, --edit                                   --no-edit                                    --amend                                      --no-post-rewrite                            -i, --include                                -o, --only                                   -u[<mode>], --untracked-files[=<mode>]                               当-u未被使用时,默认是正常的,即显示未跟踪的文件和目录。所述<模式>可以是no, normal,all     -v, --verbose                                -q, --quiet                                  --dry-run                                    --status                                     --no-status                                  -S[<keyid>], --gpg-sign[=<keyid>]            --no-gpg-sign                                --                                           <file>…                                 
 
  | 
 
 8.19. git fetch
从远程仓库获取最新的版本到本地的 tmp 分支上。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
   |  $ git fetch <远程仓库的别名>
 
  $ git fetch <远程主机名> <分支名>
  语法:     git fetch [<options>] [<repository> [<refspec>…]]     git fetch [<options>] <group>     git fetch --multiple [<options>] [(<repository> | <group>)…]     git fetch --all [<options>]
  选项:     --all                                         -a, --append                                  --depth=<depth>                               --deepen=<depth>                              --shallow-since=<date>                        --shallow-exclude=<revision>                  --unshallow                                   --update-shallow                              --dry-run                                     -f, --force                                                                              <lbranch>除非<rbranch>它获取的远程分支是子孙的后代<lbranch>     -k, --keep                                    --multiple                                    -p, --prune                                   -P, --prune-tags                              -n, --no-tags                                 --refmap=<refspec>                            -t, --tags                                    --recurse-submodules[=yes|on-demand|no]       -j, --jobs=<n>                                --no-recurse-submodules                       --submodule-prefix=<path>                     --recurse-submodules-default=[yes|on-demand]      -u, --update-head-ok                              --upload-pack <upload-pack>                       -q, --quiet                                       -v, --verbose                                     --progress                                        -4, --ipv4                                        -6, --ipv6                                        <repository>                                      <group>                                           <refspec>                                    
 
  | 
 
 8.20. git merge
合并分支。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
   |  $ git merge <分支名称>
  语法:     git merge [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]         [-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]         [--[no-]allow-unrelated-histories]         [--[no-]rerere-autoupdate] [-m <msg>] [<commit>…]     git merge --abort     git merge --continue
  选项:     --commit, --no-commit                            -e, --edit, --no-edit                            --ff                                             --no-ff                                          --ff-only                                        -S[<keyid>], --gpg-sign[=<keyid>]                --log[=<n>], --no-log                            --signoff, --no-signoff                          --stat, -n, --no-stat                            --squash, --no-squash                            -s <strategy>, --strategy=<strategy>             -X <option>, --strategy-option=<option>          --verify-signatures, --no-verify-signatures                                                    这意味着签名密钥已由可信密钥签名。如果侧分支的提示提交未使用有效密钥进行签名,则会中止合并     --summary, --no-summary                          -q, --quiet                                      -v, --verbose                                    --progress, --no-progress                        --allow-unrelated-histories                      -m <msg>                                         --[no-]rerere-autoupdate                         --abort                                          --continue                                       <commit>…                                   
 
  | 
 
1 2 3 4 5 6 7 8 9
   | 语法:     git mergetool [--tool=<tool>] [-y | --[no-]prompt] [<file>…]      选项:     -t <tool>, --tool=<tool>  # 使用<tool>指定的合并解析程序。有效值包括emerge,gvimdiff,kdiff3,meld,vimdiff和tortoisemerge。 运行git mergetool --tool-help 有效的<工具>设置列表     --tool-help               # 打印可能使用的合并工具列表--tool     -y, --no-prompt           # 在每次调用合并解析程序之前不要提示。如果通过--tool或 merge.tool配置变量显式指定合并解析程序(默认值)     --prompt                  # 在每次调用合并解决方案之前提示,以使用户有机会跳过该路径     -O<orderfile>             # 按照<orderfile>中指定的顺序处理文件,每行有一个shell glob模式
   | 
 
 8.22. git diff
比较版本之间的差异。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
   |  $ git diff
 
  $ git diff --cached $ git diff --staged
 
  $ git diff HEAD
 
  $ git diff <commit ID>
 
  $ git diff <分支名称> <分支名称>
 
  $ git diff <分支名称>...<分支名称>
  语法:     git diff [options] [<commit>] [--] [<path>…]     git diff [options] --cached [<commit>] [--] [<path>…]     git diff [options] <commit> <commit> [--] [<path>…]     git diff [options] <blob> <blob>     git diff [options] [--no-index] [--] <path> <path>
  选项:     -p, -u, --patch                                          -s, --no-patch                                           -U<n>, --unified=<n>                                     --raw                                                    --patch-with-raw                                         --indent-heuristic, --no-indent-heuristic                --minimal                                                --patience                                               --histogram                                              --diff-algorithm={patience|minimal|histogram|myers}          default, myers                                           minimal                                                  patience                                                 histogram                                            --stat[=<width>[,<name-width>[,<count>]]]                --numstat                                                --shortstat                                              --dirstat[=<param1,param2,…>]                                changes                                                  lines                                                    files                                                    cumulative                                               <limit>                                              --summary                                                --patch-with-stat                                        -z                                                       --name-only                                              --name-status                                            --submodule[=<format>]                                   --color[=<when>]                                         --no-color                                               --word-diff[=<mode>]                                     color                                                    plain                                                    porcelain                                                none                                                     --word-diff-regex=<regex>                                --color-words[=<regex>]                                  --no-renames                                             --check                                                  --ws-error-highlight=<kind>                              --full-index                                             --binary                                                 --abbrev[=<n>]                                           -B[<n>][/<m>], --break-rewrites[=[<n>][/<m>]]            -M[<n>], --find-renames[=<n>]                            -C[<n>], --find-copies[=<n>]                             --find-copies-harder                                     -D, --irreversible-delete                                -l<num>                                                  --diff-filter=[(A|C|D|M|R|T|U|X|B)…[*]]                                                                        可以使用任何过滤字符的组合(包括无)当*(全部或无)添加到组合中时,如果有任何文件与比较中的其他条件匹配,则选择所有路径; 如果没有与其他标准匹配的文件,则不会选择任何内容     -S<string>                                               -G<regex>                                                --pickaxe-all                                            --pickaxe-regex                                          -O<orderfile>                                            -R                                                       --relative[=<path>]                                      -a, --text                                               --ignore-space-at-eol                                    -b, --ignore-space-change                                -w, --ignore-all-space                                   --ignore-blank-lines                                     --inter-hunk-context=<lines>                             -W, --function-context                                   --exit-code                                              --quiet                                                  --ext-diff                                               --no-ext-diff                                            --textconv, --no-textconv                                --ignore-submodules[=<when>]                             --src-prefix=<prefix>                                    --dst-prefix=<prefix>                                    --no-prefix                                              --line-prefix=<prefix>                                   --ita-invisible-in-index                                 -1 --base, -2 --ours, -3 --theirs                        -0                                                       <path>…                                             
 
  | 
 
 8.23. git pull
从远程仓库获取最新版本并合并到本地。
首先会执行 git fetch,然后执行 git merge,把获取的分支的 HEAD 合并到当前分支。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
   |  $ git pull
  语法:     git pull [options] [<repository> [<refspec>…]]
  选项:     -q, --quiet                                         -v, --verbose                                       --[no-]recurse-submodules[=yes|on-demand|no]   
  与合并有关的选项:     --commit, --no-commit                         -e, --edit, --no-edit                               --ff                                                --no-ff                                             --ff-only                                           --log[=<n>], --no-log                               --stat, -n, --no-stat                               --squash, --no-squash                                                                                移动HEAD或记录$GIT_DIR/MERGE_HEAD (以导致下一个git commit命令创建合并提交)     -s <strategy>, --strategy=<strategy>                -X <option>, --strategy-option=<option>             --verify-signatures, --no-verify-signatures         --allow-unrelated-histories                         -r, --rebase[=false|true|preserve|interactive]      --no-rebase                                         --autostash, --no-autostash                    
  与抓取相关的选项:     --all                                               -a, --append                                        --depth=<depth>                                     --deepen=<depth>                                    --shallow-since=<date>                              --shallow-exclude=<revision>                        --unshallow                                         --update-shallow                                    -f, --force                                         -k, --keep                                          --no-tags                                           -u, --update-head-ok                                --upload-pack <upload-pack>                         --progress                                          -4, --ipv4                                          -6, --ipv6                                          <repository>                                        <refspec>                                      
 
  | 
 
 8.24. git push
把本地仓库的提交推送到远程仓库。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
   |  $ git push <远程仓库的别名> <本地分支名>:<远程分支名>
 
  $ git push <远程仓库的别名> :<远程分支名> $ git push <远程仓库的别名> --delete <远程分支名>
 
  $git push          [--all | --mirror | --tags]          [--follow-tags] [--atomic]          [-n | --dry-run]          [--receive-pack=<git-receive-pack>]         [--repo=<repository>]          [-f | --force]          [-d | --delete]          [--prune]          [-v | --verbose]         [-u | --set-upstream]          [--push-option=<string>]         [--[no-]signed|--sign=(true|false|if-asked)]         [--force-with-lease[=<refname>[:<expect>]]]         [--no-verify] [<repository> [<refspec>…]]          语法:     git push [--all | --mirror | --tags] [--follow-tags] [--atomic] [-n | --dry-run] [--receive-pack=<git-receive-pack>]            [--repo=<repository>] [-f | --force] [-d | --delete] [--prune] [-v | --verbose]            [-u | --set-upstream] [--push-option=<string>]            [--[no-]signed|--signed=(true|false|if-asked)]            [--force-with-lease[=<refname>[:<expect>]]]            [--no-verify] [<repository> [<refspec>…]]
  选项:     <repository>                                         <refspec>…                                           --all                                                --prune                                              --mirror                                             -n, --dry-run                                        --porcelain                                          --delete                                             --tags                                               --follow-tags                                        --[no-]signed, --signed=(true|false|if-asked)        --[no-]atomic                                        -o <option>, --push-option=<option>                  --receive-pack=<git-receive-pack>, --exec=<git-receive-pack>               --[no-]force-with-lease, --force-with-lease=<refname>,           --force-with-lease=<refname>:<expect>                                      -f, --force                                                                --repo=<repository>                                                        -u, --set-upstream                                                         --[no-]thin                                                                -q, --quiet                                                                -v, --verbose                                                              --progress                                                                 --no-recurse-submodules, --recurse-submodules=check|on-demand|only|no      --[no-]verify                                                              -4, --ipv4                                                                 -6, --ipv6                                                            
 
  | 
 
 8.25. git log
显示提交的记录。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
   |  $ git log
 
  $ git log <commit ID>
 
  $ git log -<指定的数量>
  语法:     git log [<options>] [<revision range>] [[\--] <path>…]      选项:     --follow                                                          --no-decorate, --decorate[=short|full|auto|no]                    --decorate-refs=<pattern>, --decorate-refs-exclude=<pattern>      --source                                                          --use-mailmap                                                     --full-diff                                                       --log-size                                                        -L <start>,<end>:<file>, -L :<funcname>:<file>                    <revision range>                                                  [\--] <path>…                                                      提交限制:                                             -<number>, -n <number>, --max-count=<number>              --skip=<number>                                           --since=<date>, --after=<date>                            --until=<date>, --before=<date>                           --author=<pattern>, --committer=<pattern>                 --grep-reflog=<pattern>                                   --grep=<pattern>                                          --all-match                                               --invert-grep                                             -i, --regexp-ignore-case                                  --basic-regexp                                            -E, --extended-regexp                                     -F, --fixed-strings                                       -P, --perl-regexp                                         --remove-empty                                            --merges                                                  --no-merges                                               --min-parents=<number>, --max-parents=<number>            --no-min-parents, --no-max-parents                        --first-parent                                            --not                                                     --all                                                     --branches[=<pattern>]                                    --tags[=<pattern>]                                        --remotes[=<pattern>]                                     --glob=<glob-pattern>                                     --exclude=<glob-pattern>                                  --reflog                                                  --single-worktree                                         --ignore-missing                                          --bisect                                                  --stdin                                                   --cherry-mark                                             --cherry-pick                                             --left-only, --right-only                                 --cherry                                                                                                         分叉历史的另一边的标记标记为 git log --cherry upstream...mybranch类似于 git cherry upstream mybranch     -g, --walk-reflogs                                        --merge                                                   --boundary                                                 历史简化:     <paths>                                                   --simplify-by-decoration                                      Default mode                                              --full-history                                            --dense                                                   --sparse                                                  --simplify-merges                                         --ancestry-path                                                                                              只直接存在于之间的祖先链显示提交commit1和 commit2,即提交属于的两个后代commit1,和祖先commit2
  提交订单:                                                     --date-order                                              --author-date-order                                       --topo-order                                              --reverse                                            
  对象遍历:                                                         --no-walk[=(sorted|unsorted)]                                                             则提交按照它们在命令行上的顺序显示。否则(如sorted没有给参数),提交按提交时间以反向时间顺序显示。不能与之结合--graph     --do-walk                                            
  提交格式:                                                     --pretty[=<format>], --format=<format>                    --abbrev-commit                                           --no-abbrev-commit                                        --oneline                                                 --encoding=<encoding>                                     --expand-tabs=<n>, --expand-tabs, --no-expand-tabs        --notes[=<treeish>]                                       --no-notes                                                --show-signature                                          --relative-date                                           --date=<format>                                           --parents                                                 --children                                                --left-right                                              --graph                                                   --show-linear-break[=<barrier>]                      
  区分格式:                                                     -c                                                        --cc                                                      -m                                                        -r                                                        -t                                                   
 
  | 
 
 8.26. git reset
还原提交记录。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
   | 
 
  $ git reset [<文件路径>] $ git reset --mixed [<文件路径>]
 
  $ git reset <commit ID> $ git reset --mixed <commit ID>
 
 
  $ git reset --soft <commit ID>
 
  $ git reset --hard <commit ID>
  语法:     git reset [-q] [<tree-ish>] [--] <paths>…     git reset (--patch | -p) [<tree-ish>] [--] [<paths>…]     git reset [--soft | --mixed [-N] | --hard | --merge | --keep] [-q] [<commit>]
  选项:     -q, --quiet           --soft                --mixed               --hard                --merge               --keep           
 
  | 
 
 8.27. git revert
生成一个新的提交来撤销某次提交,此次提交之前的所有提交都会被保留。
1 2
   |  $ git revert <commit ID>
 
  | 
 
 8.28. git tag
操作标签的命令。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
   |  $ git tag
 
  $ git tag <标签名称> [<commit ID>]
 
  $ git tag -a <标签名称> -m <标签描述信息> [<commit ID>]
 
  $ git checkout <标签名称>
 
  $ git show <标签名称>
 
  $ git tag -d <标签名称>
 
  $ git push <远程仓库的别名> <标签名称>
 
  $ git push <远程仓库的别名> -tags
  语法:     git tag [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>] [-e]         <tagname> [<commit> | <object>]     git tag -d <tagname>…     git tag [-n[<num>]] -l [--contains <commit>] [--no-contains <commit>]         [--points-at <object>] [--column[=<options>] | --no-column]         [--create-reflog] [--sort=<key>] [--format=<format>]         [--[no-]merged [<commit>]] [<pattern>…]     git tag -v [--format=<format>] <tagname>…
  选项:     -a, --annotate                               -s, --sign                                   -u <keyid>, --local-user=<keyid>             -f, --force                                  -d, --delete                                 -v, --verify                                 -n<num>                                      -l, --list                                   --sort=<key>                                 -i, --ignore-case                            --column[=<options>], --no-column            --contains [<commit>]                        --no-contains [<commit>]                     --merged [<commit>]                          --no-merged [<commit>]                       --points-at <object>                         -m <msg>, --message=<msg>                    -F <file>, --file=<file>                     -e, --edit                                   --cleanup=<mode>                             --create-reflog                              <tagname>                                    <commit>, <object>                           <format>                                
 
  | 
 
 8.29. git worktree
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
   | 语法:     git worktree add [-f] [--detach] [--checkout] [--lock] [-b <new-branch>] <path> [<commit-ish>]     git worktree list [--porcelain]     git worktree lock [--reason <string>] <worktree>     git worktree move <worktree> <new-path>     git worktree prune [-n] [-v] [--expire <expire>]     git worktree remove [--force] <worktree>     git worktree unlock <worktree>
  选项:     add <path> [<commit-ish>]          # 创建<path>并签<commit-ish>出     list                               # 列出每个工作树的详细信息     lock                               # 如果工作树位于便携式设备或网络共享上,且该共享并非始终挂载,请将其锁定以防止其管理文件被自动修剪     move                               # 将工作树移到新位置     prune                              # 修剪$ GIT_DIR / worktrees中的修剪树信息     remove                             # 删除一棵工作树。只有干净的工作树(没有未跟踪的文件,并且没有修改跟踪的文件)可以被删除     unlock                             # 解锁一个工作树,允许它被修剪,移动或删除     -f, --force                        # 默认情况下,add拒绝创建一个新的工作树,当它 <commit-ish>是一个分支名称并且已经被另一个工作树签出并remove拒绝删除不干净的工作树时     -b <new-branch>, -B <new-branch>   # 用add,创建一个名为<new-branch>起始处 的新分支<commit-ish>,并检查<new-branch>新的工作树     --detach                           # 随着add,在新的工作树中分离HEAD     --[no-]checkout                    # 默认情况下,add检查出来<commit-ish>,但--no-checkout可以用来抑制,以进行自定义,如配置稀疏结帐结帐     --[no-]guess-remote                # 与worktree add <path>没有,<commit-ish>而不是创建从HEAD一个新的分支,如果存在在恰好一个远程匹配的                                         基本名称的跟踪分支<path>,立足于远程跟踪分支的新分支,并标记远程跟踪分支为“上游”来自新的分支     --[no-]track                       # 创建新分支时,如果<commit-ish>是分支,则将其标记为新分支中的“上游”     --lock                             # 创建后保持工作树锁定     -n, --dry-run                      # 随着prune,不要删除任何东西; 只是报告它会删除什么     --porcelain                        # 使用list,输出脚本的易于解析的格式     -v, --verbose                      # 随着prune,报告所有清除     --expire <time>                    # 使用时prune,只会使<age>以前的未使用的工作树过期     --reason <string>                  # 随着lock,为什么工作树被锁定的解释     <worktree>                         # 工作树可以通过相对路径或绝对路径来标识
   | 
 
 8.30. git submodule
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
   | 语法:     git submodule [--quiet] add [<options>] [--] <repository> [<path>]     git submodule [--quiet] status [--cached] [--recursive] [--] [<path>…]     git submodule [--quiet] init [--] [<path>…]     git submodule [--quiet] deinit [-f|--force] (--all|[--] <path>…)     git submodule [--quiet] update [<options>] [--] [<path>…]     git submodule [--quiet] summary [<options>] [--] [<path>…]     git submodule [--quiet] foreach [--recursive] <command>     git submodule [--quiet] sync [--recursive] [--] [<path>…]     git submodule [--quiet] absorbgitdirs [--] [<path>…]
  选项:     -q, --quiet                     --all                           -b, --branch                    -f, --force                     --cached                        --files                         -n, --summary-limit             --remote                        -N, --no-fetch                  --checkout                      --merge                         --rebase                        --init                          --name                          --reference <repository>        --recursive                     --depth                         --[no-]recommend-shallow        -j <n>, --jobs <n>              <path>…                    
   | 
 
 8.31. git show
1 2 3 4 5 6 7 8 9 10 11 12 13 14
   | 语法:     git show [options] [<object>…]
  选项:     <object>…                                                --pretty[=<format>], --format=<format>                   --abbrev-commit                                          --no-abbrev-commit                                       --oneline                                                --encoding=<encoding>                                    --expand-tabs=<n>, --expand-tabs, --no-expand-tabs       --notes[=<treeish>]                                      --no-notes                                               --show-signature                                    
   | 
 
 8.32. git shortlog
1 2 3 4 5 6 7 8 9 10 11 12 13
   | 语法:     git log --pretty=short | git shortlog [<options>]     git shortlog [<options>] [<revision range>] [[\--] <path>…]
  选项:     -n, --numbered                              -s, --summary                               -e, --email                                 --format[=<format>]                         -c, --committer                             -w[<width>[,<indent1>[,<indent2>]]]         <revision range>                            [\--] <path>…                          
   | 
 
 8.33. git describe
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
   | 语法:     git describe [--all] [--tags] [--contains] [--abbrev=<n>] [<commit-ish>…]     git describe [--all] [--tags] [--contains] [--abbrev=<n>] --dirty[=<mark>]     git describe <blob>
  选项:     <commit-ish>…                             --dirty[=<mark>], --broken[=<mark>]       --all                                     --tags                                    --contains                                --abbrev=<n>                              --candidates=<n>                          --exact-match                             --debug                                   --long                                    --match <pattern>                         --exclude <pattern>                       --always                                  --first-parent                       
   | 
 
 8.33.1. git apply
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
   | 语法:     git apply [--stat] [--numstat] [--summary] [--check] [--index] [--3way]           [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse]           [--allow-binary-replacement | --binary] [--reject] [-z]           [-p<n>] [-C<n>] [--inaccurate-eof] [--recount] [--cached]           [--ignore-space-change | --ignore-whitespace]           [--whitespace=(nowarn|warn|fix|error|error-all)]           [--exclude=<path>] [--include=<path>] [--directory=<root>]           [--verbose] [--unsafe-paths] [<patch>…]
  选项:     <patch>…                                         --stat                                           --numstat                                        --summary                                        --check                                          --index                                          --cached                                         -3, --3way                                       --build-fake-ancestor=<file>                     -R, --reverse                                    --reject                                         -z                                               -p<n>                                            -C<n>                                            --unidiff-zero                                   --apply                                          --no-add                                         --allow-binary-replacement, --binary             --exclude=<path-pattern>                         --include=<path-pattern>                         --ignore-space-change, --ignore-whitespace       --whitespace=<action>                            --inaccurate-eof                                 -v, --verbose                                    --recount                                        --directory=<root>                               --unsafe-paths                              
   | 
 
 8.34. git mv
重命名文件或者文件夹。
1 2 3 4 5 6 7 8 9 10 11
   |  $ git mv <源文件/文件夹> <目标文件/文件夹>
  语法:     git mv <options>… <args>…
  选项:     -f, --force                  -k                           -n, --dry-run                -v, --verbose           
 
  | 
 
 8.35. git rm
删除文件或者文件夹。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
   |  $ git rm <文件路径>
 
  $ git rm -r <文件夹路径>
 
  $ git rm --cached
  语法:     git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>…
  选项:     <file>…                      -f, --force                  -n, --dry-run                -r                           --                           --cached                     --ignore-unmatch             -q, --quiet             
 
  | 
 
 8.36. Git操作场景示例
 8.36.1. 删除掉本地不存在的远程分支
多人合作开发时,如果远程的分支被其他开发删除掉,在本地执行 git branch --all 依然会显示该远程分支,可使用下列的命令进行删除:
1 2 3 4 5 6
   |  $ git pull -p
 
  $ git fetch -p $ git fetch --prune origin
 
  | 
 
 9. 错误提示
"Updates were rejected because the remote contains work that you do"
此错误提示遇到过的有有两种情况:
- 
当你所推送的文件内有子.git分支,也就是可能你下载别人的包下来放在你的此文件夹内使用的时候,从远程仓库同时down下来有.git文件,所以此时Git会认为你在本地有新的分支,因为从原理上一个.git仓库准许有一个.git配置文件夹。
解决办法:删除多余的.git配置文件夹即可
 
- 
当你所推送的本地仓库与远程仓库不匹配时,也就是说远程仓库的信息在远程自己手动更改过文件,或者有其他用户更改过文件,没有同步的话就会存在冲突。
解决办法:先用pull命令把本地仓库的变化连接到远程仓库主分支,同步远端仓库的变化,然后再进行push操作,或者在push 后直接加上 –force的选项 / -f或者参数,选择强制覆盖远程仓库的信息变化记录;
也就是:
- git init //初始化仓库
 
- git add .(文件name) //添加文件到本地仓库
 
- git commit -m “first commit” //添加文件描述信息
 
- git remote add origin + 远程仓库地址 //链接远程仓库,创建主分支
 
- git pull origin master // 把本地仓库的变化连接到远程仓库主分支
 
- git push -u origin master //把本地仓库的文件推送到远程仓库
 
或者:
- git init //初始化仓库
 
- git add .(文件name) //添加文件到本地仓库
 
- git commit -m “first commit” //添加文件描述信息
 
- git remote add origin + 远程仓库地址 //链接远程仓库,创建主分支
 
- git push -f origin master //把本地仓库的文件推送到远程仓库