(window.webpackJsonp=window.webpackJsonp||[]).push([[124],{450:function(s,a,t){"use strict";t.r(a);var e=t(3),n=Object(e.a)({},(function(){var s=this,a=s._self._c;return a("ContentSlotsDistributor",{attrs:{"slot-key":s.$parent.slotKey}},[a("h1",{attrs:{id:"git基础与命令"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git基础与命令"}},[s._v("#")]),s._v(" Git基础与命令")]),s._v(" "),a("p",[s._v("官方文档(中文):https://git-scm.com/book/zh/v2")]),s._v(" "),a("blockquote",[a("p",[s._v("本文档是根据官方文档来编写的,以官方文档为准。")])]),s._v(" "),a("h2",{attrs:{id:"git基础"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git基础"}},[s._v("#")]),s._v(" Git基础")]),s._v(" "),a("h3",{attrs:{id:"全局配置"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#全局配置"}},[s._v("#")]),s._v(" 全局配置")]),s._v(" "),a("div",{staticClass:"language-bash line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--global")]),s._v(" user.name "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'your name'")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--global")]),s._v(" user.email "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'xxx@xx.com'")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("p",[s._v("自报家门")]),s._v(" "),a("h3",{attrs:{id:"检查配置信息"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#检查配置信息"}},[s._v("#")]),s._v(" 检查配置信息")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--list")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("h3",{attrs:{id:"获取帮助"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#获取帮助"}},[s._v("#")]),s._v(" 获取帮助")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 获取全局帮助手册")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("help")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 获取特定命令的详细版帮助手册 (两个命令是等价的)")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("help")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("某个命令"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("某个命令"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--help")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 两个横杠")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 获取特定命令的简明版帮助手册")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("某个命令"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-h")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 一个横杠")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br")])]),a("h3",{attrs:{id:"初始化仓库"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#初始化仓库"}},[s._v("#")]),s._v(" 初始化仓库")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 本地目录初始化仓库")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" init\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("p",[s._v("如果你是从远程仓库clone的项目,则该项目是已经初始化好的git仓库")]),s._v(" "),a("h3",{attrs:{id:"克隆远程仓库"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#克隆远程仓库"}},[s._v("#")]),s._v(" 克隆远程仓库")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 克隆")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" clone "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("url"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 克隆同时修改目录名")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" clone "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("url"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("name"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br")])]),a("p",[s._v("初次克隆某个仓库的时候,工作目录中的所有文件都属于已跟踪文件,并处于未修改状态,因为 Git 刚刚检出了它们, 而你尚未编辑过它们")]),s._v(" "),a("h3",{attrs:{id:"检查文件状态"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#检查文件状态"}},[s._v("#")]),s._v(" 检查文件状态")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 查看详细状态说明")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" status\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 查看简明状态说明")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" status "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-s")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# -s 或 --short")]),s._v("\n M README "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 已修改,但未暂存 (M的位置靠右,红色)")]),s._v("\nMM Rakefile "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 已修改,暂存后又作了修改(有暂存和未暂存)")]),s._v("\nA lib/git.rb "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 新添加到暂存区,未提交")]),s._v("\nM lib/simplegit.rb "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 已修改,已暂存 (M的位置靠左,绿色)")]),s._v("\n?? LICENSE.txt "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 新添加,未跟踪")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br")])]),a("ul",[a("li",[a("p",[s._v("git目录中的文件状态包含:是否跟踪、是否修改、是否已存入暂存区")])]),s._v(" "),a("li",[a("p",[s._v("参数的"),a("strong",[s._v("一个横杠表示缩写,两个横杠表示全称。")])])])]),s._v(" "),a("h3",{attrs:{id:"加入暂存区-跟踪文件"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#加入暂存区-跟踪文件"}},[s._v("#")]),s._v(" 加入暂存区 (跟踪文件)")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 文件加入暂存区(跟踪指定文件)")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("add")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("files"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("p",[a("code",[s._v("git add")]),s._v(" 命令使用文件或目录的路径作为参数;如果参数是目录的路径,该命令将递归地跟踪该目录下的所有文件。")]),s._v(" "),a("p",[a("code",[s._v("add")]),s._v(" 命令是将文件"),a("strong",[s._v("加入")]),s._v("到"),a("strong",[s._v("暂存区")]),s._v(","),a("code",[s._v("commit")]),s._v(" 命令的"),a("strong",[s._v("提交")]),s._v("到"),a("strong",[s._v("本地仓库")]),s._v(","),a("code",[s._v("push")]),s._v(" 命令是"),a("strong",[s._v("推送")]),s._v("到"),a("strong",[s._v("远程仓库")]),s._v("。")]),s._v(" "),a("h3",{attrs:{id:"忽略文件"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#忽略文件"}},[s._v("#")]),s._v(" 忽略文件")]),s._v(" "),a("p",[s._v("添加一个名为 "),a("code",[s._v(".gitignore")]),s._v(" 的文件,列出要忽略的文件的模式")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("*."),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("oa"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 忽略以 .o 或 .a 结尾的文件(一般这类文件是编译过程出现)")]),s._v("\n*~ "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 忽略以 ~ 结尾的文件(一般是文本编辑软件保存的副本)")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("p",[s._v("文件 "),a("code",[s._v(".gitignore")]),s._v(" 的"),a("strong",[s._v("格式规范")]),s._v("如下:")]),s._v(" "),a("ul",[a("li",[a("p",[s._v("所有空行或者以 "),a("code",[s._v("#")]),s._v(" 开头的行都会被 Git 忽略(注释符号)。")])]),s._v(" "),a("li",[a("p",[s._v("可以使用标准的 glob 模式匹配,它会递归地应用在整个工作区中。")]),s._v(" "),a("blockquote",[a("p",[s._v("glob 模式是指 shell 所使用的简化了的正则表达式")])])]),s._v(" "),a("li",[a("p",[s._v("匹配模式可以以("),a("code",[s._v("/")]),s._v(")开头防止递归。")])]),s._v(" "),a("li",[a("p",[s._v("匹配模式可以以("),a("code",[s._v("/")]),s._v(")结尾指定目录。")])]),s._v(" "),a("li",[a("p",[s._v("要忽略指定模式以外的文件或目录,可以在模式前加上叹号("),a("code",[s._v("!")]),s._v(")取反。")])])]),s._v(" "),a("hr"),s._v(" "),a("ul",[a("li",[s._v("星号("),a("code",[s._v("*")]),s._v(")匹配零个或多个任意字符")]),s._v(" "),a("li",[a("code",[s._v("[abc]")]),s._v(" 匹配任何一个列在方括号中的字符 (这个例子要么匹配一个 a,要么匹配一个 b,要么匹配一个 c)")]),s._v(" "),a("li",[s._v("问号("),a("code",[s._v("?")]),s._v(")只匹配一个任意字符")]),s._v(" "),a("li",[a("code",[s._v("[0-9]")]),s._v(" 表示匹配所有 0 到 9 的数字。在方括号中使用短划线分隔两个字符, 表示所有在这两个字符范围内的都可以匹配")]),s._v(" "),a("li",[s._v("使用两个星号("),a("code",[s._v("**")]),s._v(")表示匹配任意中间目录,比如 "),a("code",[s._v("a/**/z")]),s._v(" 可以匹配 "),a("code",[s._v("a/z")]),s._v(" 、 "),a("code",[s._v("a/b/z")]),s._v(" 或 "),a("code",[s._v("a/b/c/z")]),s._v(" 等。")])]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 忽略所有的 .a 文件")]),s._v("\n*.a\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 但跟踪所有的 lib.a,即便你在前面忽略了 .a 文件")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("!")]),s._v("lib.a\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 只忽略当前目录下的 TODO 文件,而不忽略 subdir/TODO")]),s._v("\n/TODO\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 忽略任何目录下名为 build 的文件夹")]),s._v("\nbuild/\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 忽略 doc/notes.txt,但不忽略 doc/server/arch.txt")]),s._v("\ndoc/*.txt\n\n"),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 忽略 doc/ 目录及其所有子目录下的 .pdf 文件")]),s._v("\ndoc/**/*.pdf\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br"),a("span",{staticClass:"line-number"},[s._v("15")]),a("br"),a("span",{staticClass:"line-number"},[s._v("16")]),a("br"),a("span",{staticClass:"line-number"},[s._v("17")]),a("br")])]),a("p",[s._v("GitHub 有一个十分详细的针对数十种项目及语言的 "),a("code",[s._v(".gitignore")]),s._v(" 文件列表, 你可以在 https://github.com/github/gitignore 找到它。")]),s._v(" "),a("h3",{attrs:{id:"查看修改的具体内容"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#查看修改的具体内容"}},[s._v("#")]),s._v(" 查看修改的具体内容")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("diff")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 比较修改之后还没有暂存起来的变化内容。")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("diff")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--staged")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 查看已暂存的将要添加到下次提交里的内容")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("p",[a("code",[s._v("git status")]),s._v(" 只能查看文件变动的状态,并不能查看具体修改了哪些内容。使用"),a("code",[s._v("git diff")]),s._v("可以看到具体变动的内容。")]),s._v(" "),a("h3",{attrs:{id:"提交更新"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#提交更新"}},[s._v("#")]),s._v(" 提交更新")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" commit "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 未带参数的会打开默认文本编辑器让你输入提交说明")]),s._v("\n\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" commit "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'提交说明'")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 带-m参数直接输入提交说明")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("p",[s._v("使用"),a("code",[s._v("git commit")]),s._v("提交更新,在此之前,务必确认所有变动已经被"),a("code",[s._v("git add")]),s._v("添加到暂存区。")]),s._v(" "),a("h3",{attrs:{id:"跳过使用暂存区域"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#跳过使用暂存区域"}},[s._v("#")]),s._v(" 跳过使用暂存区域")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" commit "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-a")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'提交说明'")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("p",[s._v("添加"),a("code",[s._v("-a")]),s._v("选项可以跳过"),a("code",[s._v("git add")]),s._v(" 步骤,把已经跟踪过的文件一并提交。")]),s._v(" "),a("p",[s._v("注意:这个操作"),a("strong",[s._v("无法提交未跟踪")]),s._v("的文件。")]),s._v(" "),a("h2",{attrs:{id:"git-基础-查看提交历史"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-基础-查看提交历史"}},[s._v("#")]),s._v(" Git 基础 - 查看提交历史")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" log\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("p",[s._v("不传入任何参数的默认情况下,"),a("code",[s._v("git log")]),s._v(" 会按时间先后顺序列出所有的提交,最近的更新排在最上面。")]),s._v(" "),a("p",[s._v("此命令打印的数据中有一项是一长串的 "),a("code",[s._v("SHA-1")]),s._v(" 校验码。")]),s._v(" "),a("p",[a("strong",[s._v("带入"),a("code",[s._v("-p")]),s._v("或"),a("code",[s._v("--patch")]),s._v("查看提交的具体差异:")])]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" log "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-p")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-2")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# -p显示差异 -2显示最近的提交次数")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("p",[a("code",[s._v("--stat")]),s._v(" 显示每次提交的差异统计")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" log "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--stat")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("p",[a("code",[s._v("--pretty")]),s._v(" 这个选项可以使用不同于默认格式的方式展示提交历史")]),s._v(" "),a("p",[s._v("这个选项有一些内建的子选项供你使用。 比如 "),a("code",[s._v("oneline")]),s._v(" 会将每个提交放在一行显示,在浏览大量的提交时非常有用。 另外还有 "),a("code",[s._v("short")]),s._v(","),a("code",[s._v("full")]),s._v(" 和 "),a("code",[s._v("fuller")]),s._v(" 选项,它们展示信息的格式基本一致,但是详尽程度不一:")]),s._v(" "),a("div",{staticClass:"language-fsharp line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-fsharp"}},[a("code",[s._v("$ git log "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("-")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("-")]),s._v("pretty"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("oneline\nca82a6dff817ec66f44342007202690a93763949 changed the version number\n085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 removed unnecessary test\na11bef06a3f659402fe7563abf99ad00de2209e6 first commit\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("p",[s._v("最有意思的是 "),a("code",[s._v("format")]),s._v(" ,可以定制记录的显示格式。 这样的输出对后期提取分析格外有用——因为你知道输出的格式不会随着 Git 的更新而发生改变:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" log "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--pretty")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("format:"),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"%h - %an, %ar : %s"')]),s._v("\nca82a6d - Scott Chacon, "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("6")]),s._v(" years ago "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v(":")]),s._v(" changed the version number\n085bb3b - Scott Chacon, "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("6")]),s._v(" years ago "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v(":")]),s._v(" removed unnecessary "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("test")]),s._v("\na11bef0 - Scott Chacon, "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("6")]),s._v(" years ago "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v(":")]),s._v(" first commit\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("p",[a("a",{attrs:{href:"https://git-scm.com/book/zh/v2/ch00/pretty_format",target:"_blank",rel:"noopener noreferrer"}},[a("code",[s._v("git log --pretty=format")]),s._v(" 常用的选项"),a("OutboundLink")],1),s._v(" 列出了 "),a("code",[s._v("format")]),s._v(" 接受的常用格式占位符的写法及其代表的意义。")]),s._v(" "),a("p",[a("strong",[s._v("当 "),a("code",[s._v("oneline")]),s._v(" 或 "),a("code",[s._v("format")]),s._v(" 与另一个 "),a("code",[s._v("log")]),s._v(" 选项 "),a("code",[s._v("--graph")]),s._v(" 结合使用时尤其有用。 这个选项添加了一些 ASCII 字符串来形象地展示你的分支、合并历史:")])]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" log "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--pretty")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("format:"),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"%h %s"')]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--graph")]),s._v("\n* 2d3acf9 ignore errors from SIGCHLD on "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("trap")]),s._v("\n* 5e3ee11 Merge branch "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'master'")]),s._v(" of git://github.com/dustin/grit\n"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("|")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("\\")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("|")]),s._v(" * 420eac9 Added a method "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" getting the current branch.\n* "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("|")]),s._v(" 30e367c "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("timeout")]),s._v(" code and tests\n* "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("|")]),s._v(" 5a09431 "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("add")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("timeout")]),s._v(" protection to grit\n* "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("|")]),s._v(" e1193f8 support "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" heads with slashes "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("in")]),s._v(" them\n"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("|")]),s._v("/\n* d6016bc require "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("time")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" xmlschema\n* 11d191e Merge branch "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'defunkt'")]),s._v(" into "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("local")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br")])]),a("h2",{attrs:{id:"git-基础-撤消操作"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-基础-撤消操作"}},[s._v("#")]),s._v(" Git 基础 - 撤消操作")]),s._v(" "),a("p",[s._v("你提交后发现忘记了暂存某些需要的修改,可以像下面这样操作:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" commit "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'initial commit'")]),s._v("\n$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("add")]),s._v(" forgotten_file\n$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" commit "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--amend")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 重新提交,且只有一次提交记录")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("p",[s._v("最终你只会有一个提交——第二次提交将代替第一次提交的结果。")]),s._v(" "),a("p",[s._v("更多撤销操作请了解 "),a("code",[s._v("reset")]),s._v("命令。")]),s._v(" "),a("h2",{attrs:{id:"git-基础-远程仓库的使用"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-基础-远程仓库的使用"}},[s._v("#")]),s._v(" Git 基础 - 远程仓库的使用")]),s._v(" "),a("h3",{attrs:{id:"查看远程仓库"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#查看远程仓库"}},[s._v("#")]),s._v(" 查看远程仓库")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" remote "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 仅显示远程仓库的名称")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" remote "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-v")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 显示远程仓库的名称 + 地址")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("h3",{attrs:{id:"添加远程仓库"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#添加远程仓库"}},[s._v("#")]),s._v(" 添加远程仓库")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" remote "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("add")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("远程仓库名"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("url"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("h3",{attrs:{id:"从远程仓库中抓取与拉取"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#从远程仓库中抓取与拉取"}},[s._v("#")]),s._v(" 从远程仓库中抓取与拉取")]),s._v(" "),a("p",[s._v("就如刚才所见,从远程仓库中获得数据,可以执行:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" fetch "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("remote"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("p",[s._v("这个命令会访问远程仓库,从中拉取所有你还没有的数据。 执行完成后,你将会拥有那个远程仓库中所有分支的引用,可以随时合并或查看。")]),s._v(" "),a("p",[s._v("注意: "),a("code",[s._v("git fetch")]),s._v(" 命令只会将数据下载到你的本地仓库——"),a("strong",[s._v("它并不会自动合并或修改你当前的工作")]),s._v("。 当准备好时你必须手动将其合并入你的工作。")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" pull\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("p",[s._v("用 "),a("code",[s._v("git pull")]),s._v(" 命令来自动抓取后合并该远程分支到当前分支。 这或许是个更加简单舒服的工作流程。默认情况下,"),a("code",[s._v("git clone")]),s._v(" 命令会自动设置本地 master 分支跟踪克隆的远程仓库的 "),a("code",[s._v("master")]),s._v(" 分支(或其它名字的默认分支)。 "),a("strong",[s._v("运行 "),a("code",[s._v("git pull")]),s._v(" 通常会从最初克隆的服务器上抓取数据并自动尝试合并到当前所在的分支。")])]),s._v(" "),a("h3",{attrs:{id:"推送到远程仓库"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#推送到远程仓库"}},[s._v("#")]),s._v(" 推送到远程仓库")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" push "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("remote"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("branch"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# git push origin master")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("h3",{attrs:{id:"查看某个远程仓库"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#查看某个远程仓库"}},[s._v("#")]),s._v(" 查看某个远程仓库")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v(" "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" remote show "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("remote"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# git remote show origin")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("p",[s._v("查看远程仓库的详细信息。这个命令列出了当你在特定的分支上执行 "),a("code",[s._v("git push")]),s._v(" 会自动地推送到哪一个远程分支")]),s._v(" "),a("h3",{attrs:{id:"远程仓库的重命名与移除"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#远程仓库的重命名与移除"}},[s._v("#")]),s._v(" 远程仓库的重命名与移除")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" remote "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("rename")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("原名"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("新名"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 重命名")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" remote remove paul "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("remote"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 移除远程仓库")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("h2",{attrs:{id:"git-基础-打标签"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-基础-打标签"}},[s._v("#")]),s._v(" Git 基础 - 打标签")]),s._v(" "),a("h3",{attrs:{id:"列出标签"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#列出标签"}},[s._v("#")]),s._v(" 列出标签")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" tag "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 完整标签列表")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" tag "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-l")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"v2.0*"')]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 只显示包含 v2.0 的标签。 注意加星号(*)")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("p",[a("code",[s._v("-l")]),s._v(" 或 "),a("code",[s._v("--list")]),s._v(" 都可以。")]),s._v(" "),a("h3",{attrs:{id:"创建标签"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#创建标签"}},[s._v("#")]),s._v(" 创建标签")]),s._v(" "),a("p",[s._v("Git 支持两种标签:"),a("strong",[s._v("轻量标签")]),s._v("(lightweight)与"),a("strong",[s._v("附注标签")]),s._v("(annotated)。")]),s._v(" "),a("p",[s._v("轻量标签很像一个不会改变的分支——它"),a("strong",[s._v("只是某个特定提交的引用")]),s._v("。")]),s._v(" "),a("p",[s._v("而附注标签是存储在 Git 数据库中的一个完整对象, 它们是可以被校验的,其中"),a("strong",[s._v("包含打标签者的名字、电子邮件地址、日期时间, 此外还有一个标签信息")]),s._v(",并且可以使用 GNU Privacy Guard (GPG)签名并验证。 通常会建议创建附注标签,这样你可以拥有以上所有信息。但是如果你只是想用一个临时的标签, 或者因为某些原因不想要保存这些信息,那么也可以用轻量标签。")]),s._v(" "),a("h3",{attrs:{id:"附注标签"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#附注标签"}},[s._v("#")]),s._v(" 附注标签")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" tag "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-a")]),s._v(" v1.4 "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-m")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v('"my version 1.4"')]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# -a表示add, -m 表示附件信息")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("p",[s._v("通过使用 "),a("code",[s._v("git show")]),s._v(" 命令可以看到标签信息和与之对应的提交信息:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" show v1.4\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("h3",{attrs:{id:"轻量标签"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#轻量标签"}},[s._v("#")]),s._v(" 轻量标签")]),s._v(" "),a("p",[s._v("轻量标签本质上是将提交校验和存储到一个文件中——没有保存任何其他信息。 创建轻量标签,不需要使用 "),a("code",[s._v("-a")]),s._v("、"),a("code",[s._v("-s")]),s._v(" 或 "),a("code",[s._v("-m")]),s._v(" 选项,只需要提供标签名字:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" tag v1.4-lw "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 不需要添加选项")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("p",[s._v("这时,如果在标签上运行 "),a("code",[s._v("git show")]),s._v(",你不会看到额外的标签信息。 命令只会显示出提交信息:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" show v1.4-lw\ncommit ca82a6dff817ec66f44342007202690a93763949\nAuthor: Scott Chacon "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("schacon@gee-mail.com"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\nDate: Mon Mar "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("17")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("21")]),s._v(":52:11 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2008")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-0700")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("h3",{attrs:{id:"后期打标签"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#后期打标签"}},[s._v("#")]),s._v(" 后期打标签")]),s._v(" "),a("p",[s._v("你也可以对过去的提交打标签。 假设提交历史是这样的:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" log "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--pretty")]),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("=")]),s._v("oneline\n166ae0c4d3f420721acbb115cc33848dfcc2121a started "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("write")]),s._v(" support\n9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile\n8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("p",[s._v("现在,假设在 v1.2 时你忘记给项目打标签,也就是在 “updated rakefile” 提交。 你可以在之后补上标签。 要在那个提交上打标签,你需要在命令的末尾指定提交的校验和(或部分校验和):")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" tag "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-a")]),s._v(" v1.2 9fceb02 "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 打的标签属于附注标签")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("h3",{attrs:{id:"共享标签"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#共享标签"}},[s._v("#")]),s._v(" 共享标签")]),s._v(" "),a("p",[a("code",[s._v("git push")]),s._v(" 命令并不会传送标签到远程仓库服务器上。 在创建完标签后你必须显式地推送标签到共享服务器上。 这个过程就像共享远程分支一样——你可以运行 "),a("code",[s._v("git push origin ")]),s._v("。")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" push origin v1.5 "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 显式地推送标签到远程仓库")]),s._v("\n"),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" push origin "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--tags")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("# 一次性推送所有不在远程仓库上的标签")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("p",[s._v("现在,当其他人从仓库中克隆或拉取,他们也能得到你的那些标签。")]),s._v(" "),a("h3",{attrs:{id:"删除标签"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#删除标签"}},[s._v("#")]),s._v(" 删除标签")]),s._v(" "),a("p",[s._v("要删除掉你本地仓库上的标签,可以使用命令 "),a("code",[s._v("git tag -d ")]),s._v("。 例如,可以使用以下命令删除一个轻量标签:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" tag "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-d")]),s._v(" v1.4-lw\nDeleted tag "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'v1.4-lw'")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("was e7d5add"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("p",[s._v("注意上述命令并不会从任何远程仓库中移除这个标签,你必须用 "),a("code",[s._v("git push :refs/tags/")]),s._v(" 来更新你的远程仓库:")]),s._v(" "),a("p",[s._v("第一种变体是 "),a("code",[s._v("git push :refs/tags/")]),s._v(" :")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" push origin :refs/tags/v1.4-lw\nTo /git@github.com:schacon/simplegit.git\n - "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("[")]),s._v("deleted"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("]")]),s._v(" v1.4-lw\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br")])]),a("p",[s._v("上面这种操作的含义是,将冒号前面的空值推送到远程标签名,从而高效地删除它。")]),s._v(" "),a("p",[s._v("第二种更直观的删除远程标签的方式是:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" push origin "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--delete")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("tagname"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("h3",{attrs:{id:"检出标签"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#检出标签"}},[s._v("#")]),s._v(" 检出标签")]),s._v(" "),a("p",[s._v("如果你想查看某个标签所指向的文件版本,可以使用 "),a("code",[s._v("git checkout")]),s._v(" 命令, 虽然这会使你的仓库处于“分离头指针(detached HEAD)”的状态——这个状态有些不好的副作用:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" checkout "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2.0")]),s._v(".0\nNote: checking out "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'2.0.0'")]),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v(".")]),s._v("\n\nYou are "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("in")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'detached HEAD'")]),s._v(" state. You can "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("look")]),s._v(" around, "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("make")]),s._v(" experimental\nchanges and commit them, and you can discard any commits you "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("make")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("in")]),s._v(" this\nstate without impacting any branches by performing another checkout.\n\nIf you want to create a new branch to retain commits you create, you may\n"),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("do")]),s._v(" so "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("(")]),s._v("now or later"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v(")")]),s._v(" by using "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-b")]),s._v(" with the checkout "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("command")]),s._v(" again. Example:\n\n "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" checkout "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-b")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("new-branch"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\n\nHEAD is now at 99ada87"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("..")]),s._v(". Merge pull request "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("#89 from schacon/appendix-final")]),s._v("\n\n$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" checkout "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2.0")]),s._v("-beta-0.1\nPrevious HEAD position was 99ada87"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("..")]),s._v(". Merge pull request "),a("span",{pre:!0,attrs:{class:"token comment"}},[s._v("#89 from schacon/appendix-final")]),s._v("\nHEAD is now at df3f601"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[s._v("..")]),s._v(". "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("add")]),s._v(" atlas.json and cover image\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br"),a("span",{staticClass:"line-number"},[s._v("9")]),a("br"),a("span",{staticClass:"line-number"},[s._v("10")]),a("br"),a("span",{staticClass:"line-number"},[s._v("11")]),a("br"),a("span",{staticClass:"line-number"},[s._v("12")]),a("br"),a("span",{staticClass:"line-number"},[s._v("13")]),a("br"),a("span",{staticClass:"line-number"},[s._v("14")]),a("br"),a("span",{staticClass:"line-number"},[s._v("15")]),a("br"),a("span",{staticClass:"line-number"},[s._v("16")]),a("br"),a("span",{staticClass:"line-number"},[s._v("17")]),a("br")])]),a("p",[s._v("在“分离头指针”状态下,如果你做了某些更改然后提交它们,标签不会发生变化, 但你的新提交将不属于任何分支,并且将无法访问,除非通过确切的提交哈希才能访问。 因此,如果你需要进行更改,比如你要修复旧版本中的错误,那么通常需要创建一个新分支:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" checkout "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("-b")]),s._v(" version2 v2.0.0\nSwitched to a new branch "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'version2'")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("p",[s._v("如果在这之后又进行了一次提交,"),a("code",[s._v("version2")]),s._v(" 分支就会因为这个改动向前移动, 此时它就会和 "),a("code",[s._v("v2.0.0")]),s._v(" 标签稍微有些不同,这时就要当心了。")]),s._v(" "),a("h2",{attrs:{id:"git-命令别名"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-命令别名"}},[s._v("#")]),s._v(" Git 命令别名")]),s._v(" "),a("p",[s._v("Git 并不会在你输入部分命令时自动推断出你想要的命令。 如果不想每次都输入完整的 Git 命令,可以通过 "),a("code",[s._v("git config")]),s._v(" 文件来轻松地为每一个命令设置一个别名。 这里有一些例子你可以试试:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--global")]),s._v(" alias.co checkout\n$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--global")]),s._v(" alias.br branch\n$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--global")]),s._v(" alias.ci commit\n$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--global")]),s._v(" alias.st status\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br")])]),a("p",[s._v("这意味着,当要输入 "),a("code",[s._v("git commit")]),s._v(" 时,只需要输入 "),a("code",[s._v("git ci")]),s._v("。")]),s._v(" "),a("p",[s._v("在创建你认为应该存在的命令时这个技术会很有用。 例如,为了解决取消暂存文件的易用性问题,可以向 Git 中添加你自己的取消暂存别名:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--global")]),s._v(" alias.unstage "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'reset HEAD --'")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("p",[s._v("这会使下面的两个命令等价:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" unstage fileA\n$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" reset HEAD -- fileA\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br")])]),a("p",[s._v("这样看起来更清楚一些。 通常也会添加一个 "),a("code",[s._v("last")]),s._v(" 命令,像这样:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--global")]),s._v(" alias.last "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'log -1 HEAD'")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])]),a("p",[s._v("这样,可以轻松地看到最后一次提交:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" last\ncommit 66938dae3329c7aebe598c2246a8e6af90d04646\nAuthor: Josh Goebel "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("dreamer3@example.com"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\nDate: Tue Aug "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("26")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("19")]),s._v(":48:51 "),a("span",{pre:!0,attrs:{class:"token number"}},[s._v("2008")]),s._v(" +0800\n\n "),a("span",{pre:!0,attrs:{class:"token builtin class-name"}},[s._v("test")]),s._v(" "),a("span",{pre:!0,attrs:{class:"token keyword"}},[s._v("for")]),s._v(" current "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("head")]),s._v("\n\n Signed-off-by: Scott Chacon "),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v("<")]),s._v("schacon@example.com"),a("span",{pre:!0,attrs:{class:"token operator"}},[s._v(">")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br"),a("span",{staticClass:"line-number"},[s._v("2")]),a("br"),a("span",{staticClass:"line-number"},[s._v("3")]),a("br"),a("span",{staticClass:"line-number"},[s._v("4")]),a("br"),a("span",{staticClass:"line-number"},[s._v("5")]),a("br"),a("span",{staticClass:"line-number"},[s._v("6")]),a("br"),a("span",{staticClass:"line-number"},[s._v("7")]),a("br"),a("span",{staticClass:"line-number"},[s._v("8")]),a("br")])]),a("p",[s._v("可以看出,Git 只是简单地将别名替换为对应的命令。 然而,你可能想要执行外部命令,而不是一个 Git 子命令。 如果是那样的话,可以在命令前面加入 "),a("code",[s._v("!")]),s._v(" 符号。 如果你自己要写一些与 Git 仓库协作的工具的话,那会很有用。 我们现在演示将 "),a("code",[s._v("git visual")]),s._v(" 定义为 "),a("code",[s._v("gitk")]),s._v(" 的别名:")]),s._v(" "),a("div",{staticClass:"language-sh line-numbers-mode"},[a("pre",{pre:!0,attrs:{class:"language-sh"}},[a("code",[s._v("$ "),a("span",{pre:!0,attrs:{class:"token function"}},[s._v("git")]),s._v(" config "),a("span",{pre:!0,attrs:{class:"token parameter variable"}},[s._v("--global")]),s._v(" alias.visual "),a("span",{pre:!0,attrs:{class:"token string"}},[s._v("'!gitk'")]),s._v("\n")])]),s._v(" "),a("div",{staticClass:"line-numbers-wrapper"},[a("span",{staticClass:"line-number"},[s._v("1")]),a("br")])])])}),[],!1,null,null,null);a.default=n.exports}}]);