①命令
| 命令 | 功能 |
|---|---|
| config | 获取并设置存储库或全局选项 |
| help | 显示有关Git的帮助信息 |
| clone | 将存储库克隆到新目录中 |
| init | 创建一个空的Git存储库或重新初始化现有的存储库 |
| add | 将文件内容添加到索引(暂存区)中 |
| mv | 移动或重命名文件、目录或符号链接 |
| restore | 恢复工作树(工作区)文件 |
| rm | 从工作树(工作区)和索引中删除文件 |
| bisect | 使用二进制搜索来查找引入错误的提交 |
| diff | 显示提交之间的更改、提交和工作树(工作区) |
| grep | 打印匹配模式行 |
| log | 显示提交日志 |
| stash | 暂存修改进行隔离 |
| show | 显示各种类型的对象 |
| status | 显示工作树(工作区)状态 |
| branch | 显示、创建或删除分支 |
| checkout | 切换分支或恢复工作树(工作区)文件 |
| commit | 提交记录到存储库 |
| merge | 将两个或多个开发历史记录合并 |
| mergetool | 运行合并冲突解决工具来解决合并冲突 |
| rebase | 在另一个分支基础之上重新应用提交 |
| reset | 将当前HEAD重置为指定状态 |
| switch | 切换分支 |
| tag | 创建、列出、删除或验证使用GPG签名的标签对象 |
| fetch | 从另一个存储库下载对象和引用 |
| pull | 从另一个存储库或本地分支获取并合并 |
| push | 更新远程引用以及关联的对象 |
| remote | 管理一组跟踪的存储库 |
| submodule | 初始化、更新或检查子模块 |
| shortlog | 概括"git log"输出 |
| describe | 根据可用的引用给对象一个可读的名称 |
| sparse-checkout | 稀疏检出 |
②详细内容
config
语法:
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
参数:
<file-option> :
| 参数 | 说明 |
|---|---|
| --global | 使用全局配置文件 |
| --system | 使用系统配置文件 |
| --local | 使用存储库配置文件(默认) |
| --worktree | 使用per-worktree配置文件 |
| -f, --file <file> | 使用给定的配置文件 |
| --blob <blob-id> | 从给定的blob对象读取配置 |
方法:
| 参数 | 说明 |
|---|---|
| --get | 获取值: name [value-regex] |
| --get-all | 获取所有值: key [value-regex] |
| --get-regexp | 获取regexp值: name-regex [value-regex] |
| --get-urlmatch | 获取特定于URL的值: section[.var] URL |
| --replace-all | 替换所有匹配的变量: name value [value_regex] |
| --add | 添加一个新变量: name value |
| --unset | 删除变量: name [value-regex] |
| --unset-all | 删除所有匹配: name [value-regex] |
| --rename-section | 重命名: old-name new-name |
| --remove-section | 删除: name |
| -l, --list | 显示全部 |
| -e, --edit | 打开一个编辑 |
| --get-color | 查找颜色配置: slot [default] |
| --get-colorbool | 查找颜色设置: slot [stdout-is-tty] |
type:
| 参数 | 说明 |
|---|---|
| -t, --type <> | value是特定类型 |
| --bool | value是 “true” 或 “false” |
| --int | value是十进制数 |
| --bool-or-int | value是--bool或--int |
| --path | value是一个路径(文件或目录名称) |
| --expiry-date | value是限用日期 |
其他:
| 参数 | 说明 |
|---|---|
| -z, --null | 用NUL字节终止值 |
| --name-only | 仅显示变量名称 |
| --includes | 在查找时遵守include指令 |
| --show-origin | show origin of config(文件,标准输入,blob,命令行) |
| --default <value> | 使用--get,在缺少条目时使用默认值 |
描述:
git config命令用于获取并设置存储库或全局选项。
Git 自带一个 git config 的工具来帮助设置控制 Git 外观和行为的配置变量。 这些变量存储在三个不同的位置:
--global:~/.gitconfig 或 ~/.config/git/config,只针对当前用户。--system:/etc/gitconfig,Windows在Git安装目录mingw64/etc/下--local: 当前Git仓库 .git/config
注意: 每一个级别覆盖上一级别的配置,所以 .git/config 的配置变量会覆盖 /etc/gitconfig 中的配置变量。
常用命令:
-
配置用户信息
git config --global user.name "you name"
git config user.email "you email"注意: 如果使用了 --global 选项,那么该命令只需要运行一次,因为之后无论你在该系统上做任何事情, Git 都会使用那些信息。 当你想针对特定项目使用不同的用户名称与邮件地址时,可以在那个项目目录下运行没有 --global 选项的命令来配置。
-
配置编辑器
git config --global core.editor <editor>注意: 配置默认的编辑器,Windows可以是一个路径用于指定编辑器, 像这样 :
git config --global core.editor "'C:/Program Files/Sublime Text 3/subl.exe' -n -w"
其中-n表示在一个新窗口启动编辑器,-w表示命令行将等待直到保存并关闭提交消息。更多内容请阅读这里 -
配置比较工具
git config --global merge.tool <merge tool>注意: Git可以接受 kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, 和 opendiff 作为有效的合并工具。也可以设置一个客户端的工具。
-
检查配置
git config --list -
配置别名(快捷方式)
git config --global alias.<alias> <command>注意: 有参数的命令需要使用双引号
-
删除别名
git config [--global] --unset alias.<alias>
其他:
-
添加配置
git config [–local|–global|–system] –add section.key value -
删除配置
git config [–local|–global|–system] –unset section.key
help
语法:
git help [-a|--all [--[no-]verbose]] [-g|--guide]
[-i|--info|-m|--man|-w|--web] [COMMAND|GUIDE]
参数:
| 参数 | 说明 |
|---|---|
| -a,--all | 打印标准输出上的所有可用命令。此选项会覆盖任何给定的命令或指南名称。 |
| --verbose | 与--all打印描述一起使用时,用于所有已识别的命令。这是默认值。 |
| -c,--config | 列出所有可用的配置变量。 |
| -g,--guides | 打印标准输出上的有用指南列表。此选项会覆盖任何给定的命令或指南名称。 |
| -i,--info | 以信息格式显示命令的手册页。 |
| -m,--man | 以手册格式显示命令的手册页。此选项可用于覆盖help.format配置变量中设置的值。 |
| -w,--web | 以Web(HTML)格式显示命令的手册页。 Web浏览器将用于此目的。 |
clone
语法:
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>]
参数:
| 参数 | 说明 |
|---|---|
| -v, --verbose | 更加详细运行 |
| --quiet, -q | 静默操作 |
| --progress | 强制进度报告 |
| -n, --no-checkout | 不创建检查 |
| --bare | 创建一个空仓库 |
| --mirror | 创建一个镜像仓库 |
| -l, --local | 从本地存储库克隆 |
| --no-hardlinks | 不使用本地硬链接,请始终复制文件 |
| -s, --shared | 设置为共享存储库 |
| --recurse-submodules[=<pathspec>] | 初始化克隆中的子模块 |
| -j, --jobs | 并行克隆的子模块数量 |
| --template <template-directory> | 将使用模板的目录 |
| --reference <repo> | 参考存储库 |
| --reference-if-able <repo> | 参考存储库 |
| --dissociate | 仅在克隆时使用--reference |
| -o, --origin <name> | 使用代替’origin’来跟踪上游 |
| -b, --branch <branch> | checkout <branch> 而不是远程HEAD |
| -u, --upload-pack <path> | 远程git-upload-pack的路径 |
| --depth <depth> | 创建一个深度的浅层克隆 |
| --shallow-since <time> | 从特定时间开始创建一个浅层克隆 |
| --shallow-exclude <revision> | 加深浅层克隆的历史,排除rev |
| --single-branch | 只克隆一个分支, HEAD或 --branch |
| --no-tags | 不要克隆任何标记,并使以后的提取不遵循它们 |
| --shallow-submodules | 任何克隆的子模块都会很浅 |
| --separate-git-dir <gitdir> | 将git dir与工作树分开 |
| -c, --config <key=value> | 在新存储库中设置config |
| -4, --ipv4 | 仅使用IPv4地址 |
| -6, --ipv6 | 仅使用IPv6地址 |
| --filter <args> | 对象过滤 |
描述:
git clone命令将存储库克隆到新目录中。
将存储库克隆到新创建的目录中,为克隆的存储库中的每个分支创建远程跟踪分支,并从克隆检出的存储库作为当前活动分支的初始分支。
常用命令:
-
克隆远程仓库到当前目录
git clone <版本库的网址> -
克隆远程仓库到指定目录
git clone <版本库的网址> <本地目录名>
init
语法:
git init [-q | --quiet] [--bare] [--template=<template_directory>]
[--separate-git-dir <git dir>]
[--shared[=<permissions>]] [directory]
参数:
| 参数 | 说明 |
|---|---|
| --template <template-directory> | 使用模板的目录 |
| --bare | 创建空存储库 |
| --shared[=<permissions>] | 指定git存储库将在多个用户之间共享 |
| -q, --quiet | 仅打印错误和警告消息 |
| --separate-git-dir <gitdir> | 将git dir与工作树分离 |
描述:
git init命令创建一个空的Git仓库或重新初始化一个现有仓库。
该命令创建一个空的Git仓库 - 基本上是创建一个具有objects,refs/head,refs/tags和模板文件的.git目录。 还创建了引用主分支的HEAD初始的一个HEAD文件。
常用命令:
- 当前目录创建仓库
git init - 指定目录创建仓库
git inti <dir>
add
语法:
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>...]
参数:
| 参数 | 说明 |
|---|---|
| -n, --dry-run | 该指令只是用于测试文件是否存在,不会将文件暂存 |
| -v, --verbose | 显示添加详细信息 |
| -i, --interactive | 在工作树中交互添加修改的内容到索引 |
| -p, --patch | 在索引和工作树之间交互地选择补丁块,并将它们添加到索引中 |
| -e, --edit | 编辑当前差异并应用 |
| -f, --force | 允许添加其他忽略的文件 |
| -u, --update | 更新跟踪文件 |
| --renormalize | 重新规范跟踪文件的EOL(表示 -u) |
| -N, --intent-to-add | 仅记录稍后将添加路径的真实情况 |
| -A, --all | 从所有跟踪和未跟踪的文件中添加更改 |
| --ignore-removal | 忽略工作树中删除的路径(与--no-all相同) |
| --refresh | 不添加,只刷新索引 |
| --ignore-errors | 只是跳过因错误而无法添加的文件 |
| --ignore-missing | 检查是否,甚至丢失,在dry-run中忽略文件 |
| --chmod (+|-)x | 覆盖列出文件的可执行位 |
描述:
git add命令将文件内容添加到索引(将修改添加到暂存区)。
此命令将要提交的文件的信息添加到索引库中(将修改添加到暂存区),以准备为下一次提交分段的内容。 它通常将现有路径的当前内容作为一个整体添加,但是通过一些选项,它也可以用于添加内容,只对所应用的工作树文件进行一些更改,或删除工作树中不存在的路径了。
常用命令:
- 提交目录或文件
git add <dir|file> - 提交所有变化
git add -A - 提交被修改和被删除文件,不包括新文件
git add -u - 提交新文件和被修改文件,不包括被删除文件
git add .
mv
语法:
git mv [-v] [-f] [-n] [-k] <source> <destination>
git mv [-v] [-f] [-n] [-k] <source> ... <destination directory>
参数:
| 参数 | 说明 |
|---|---|
| -v, --verbose | 移动文件的详细信息 |
| -n, --dry-run | 只显示会发生什么 |
| -f, --force | 即使目标存在,也要强制重命名或移动文件 |
| -k | 跳过移动或重命名会导致错误情况的操作 |
描述:
git mv命令用于移动或重命名文件,目录或符号链接。
在第一种形式中,它将 <source> 重命名为 <destination> ,它必须存在,并且可以是文件,符号链接或目录。在第二种形式中,最后一个参数必须是现有目录; 给定的源将被移动到这个目录中。
成功完成后更新索引,但仍必须提交更改。
常用命令:
- 重命名文件
git mv <filename> <new_filename> - 移动文件
git mv <filename> <dir>
restore
语法:
git restore [<options>] [--source=<tree>] [--staged] [--worktree] <pathspec>...
git restore (-p|--patch) [<options>] [--source=<tree>] [--staged] [--worktree] [<pathspec>...]
参数:
| 参数 | 说明 |
|---|---|
| -s, --source | 从那个tree-ish还原 |
| -S, --staged | 恢复索引 |
| -W, --worktree | 恢复工作树(默认) |
| --ignore-unmerged | 忽略未合并的条目 |
| --overlay | 使用覆盖模式 |
| -q, --quiet | 关闭进度信息 |
| --recurse-submodules[=<checkout>] | 控制子模块的递归更新 |
| --progress | 强制进度信息 |
| -m, --merge | 执行与新分支的3方法合并 |
| --conflict <style> | 冲突样式(merge或diff3) |
| -2, --ours | 检查2版本以获取未合并的文件 |
| -3, --theirs | 检查3版本以获取未合并的文件 |
| -p, --patch | 以交互方式选择hunks |
| --ignore-skip-worktree-bits | 此选项忽略稀疏模式,并无条件地恢复任何文件pathspecs |
描述:
git restore 恢复工作树文件
使用还原源中的某些内容还原工作树中的指定路径。如果跟踪路径但在还原源中不存在,则将删除该路径以匹配源。
该命令还可用于恢复索引中的内容 --staged,或使用恢复工作树和索引 --staged --worktree。
默认情况下,工作树和索引的还原源HEAD分别是索引。--source可用于将提交指定为还原源。
常用命令:
- 还原当前目录中的所有文件
git restore . - 还原文件
git restore <file>
rm
语法:
git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>…
参数:
| 参数 | 说明 |
|---|---|
| -n, --dry-run | 切勿删除任何文件 |
| -q, --quiet | 不列出已删除的文件 |
| –cached | 只从索引中删除 |
| -f, --force | 覆盖最新的检查 |
| -r | 覆盖最新的检查 |
| –ignore-unmatch | 即使没有匹配的文件,也可以用零状态退出 |
描述:
git rm命令用于从工作区和索引中删除文件。
从索引中删除文件,或从工作树和索引中删除文件。git rm不会从您的工作目录中删除文件。
常用命令:
- 删除文件
git rm <file> - 删除文件夹
git rm -r <dir> - 从索引(暂存区)中删除文件
git rm --cached <file>
bisect
语法:
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
参数:
| 参数 | 说明 |
|---|---|
| start | 启动查错 |
| bad | 标识本次提交有问题 |
| good | 标识本次提交没有问题 |
| new | 标识本次为新的提交 |
| old | 标识本次为旧的提交 |
| terms | 获取当前使用项的提醒 |
| skip | 跳过提交 |
| reset | 退出查错,回到最近一次的代码提交 |
| visualize | 使用gitk查看当前bisect过程中剩余的提交信息 |
| view | 同visualize |
| replay | 回退并重新进行标记 |
| log | 查看当前使用bisect的记录 |
| run | 运行bisect |
| help | 帮助 |
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>
参数:
| 参数 | 说明 |
|---|
stash
语法:
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 save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]
[-u|--include-untracked] [-a|--all] [<message>]
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>
参数:
| 参数 | 说明 |
|---|---|
| list | 列出您当前拥有的存储项 |
| show | 显示存储项中记录的更改 |
| drop | 从存储项列表中删除单个存储项 |
| pop | 恢复工作区并从stash列表删除 |
| apply | 恢复工作区且不从stash列表删除 |
| branch | 这条命令会根据最近的 stash 创建一个新的分支,然后删除最近的 stash |
| save | 不推荐使用此选项,而使用git stash push |
| push | 将您的本地修改保存为新的stash项并将它们回滚到 HEAD(在工作树和索引中) |
| clear | 删除所有缓存的stash |
| create | 创建一个存储项 |
| store | 将通过git stash create创建的给定存储,更新存储引用日志 |
描述:
git stash命令用于将更改储藏项在stash工作目录中。
当要记录工作目录和索引的当前状态,但想要返回到干净的工作目录时,则使用git stash。 该命令保存本地修改,并恢复工作目录以匹配HEAD提交。
调用没有任何参数的git stash相当于git stash save。
常用命令:
- 所有未提交的修改暂存
git stash - 查看现有所有stash
git stash list - 恢复工作目区
git stash pop / apply
1030

被折叠的 条评论
为什么被折叠?



