\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{ooze} \pdfinfo{ /Title (git.pdf) /Creator (Cheatography) /Author (ooze) /Subject (Git Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{3399FF} \definecolor{LightBackground}{HTML}{F2F8FF} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Git Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{ooze} via \textcolor{DarkBackground}{\uline{cheatography.com/185867/cs/38824/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}ooze \\ \uline{cheatography.com/ooze} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 24th May, 2023.\\ Updated 24th May, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{2.64 cm} x{5.36 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{基础命令}} \tn % Row 0 \SetRowColor{LightBackground} git init\{\{width=40\}\} & \seqsplit{将当前文件夹初始化为一个} git \seqsplit{仓库,可以在后面指定目录} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} git clone \textless{}repo\textgreater{} & clone 代码仓库到本地 \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} git status & 查看本地仓库状态 \tn % Row Count 6 (+ 1) % Row 3 \SetRowColor{white} git log & \seqsplit{查看历史记录,有很多参数可以选择} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} git \textless{}command\textgreater{} -h & \seqsplit{查看帮助信息,使用} -{}-help \seqsplit{可查看完整的帮助文档} \tn % Row Count 11 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.96 cm} x{3.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Git 配置}} \tn % Row 0 \SetRowColor{LightBackground} git config -{}-list\{\{width=75\}\} & 查看 Git 配置 \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git config -{}-global user.name \textless{}name\textgreater{} & \seqsplit{设置用户名} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} git config -{}-global user.email \textless{}email\textgreater{} & \seqsplit{设置用户邮箱} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} git config -{}-global core.editor \textless{}editor\textgreater{} & \seqsplit{设置文本编辑器} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} git config -{}-global alias.\textless{}alias-name\textgreater{} \textless{}command\textgreater{} & 设置 Git 命令别名 \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} git config -{}-global commit.template \textless{}file\textgreater{} & \seqsplit{设置提交模板} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} git config -{}-global core.autocrlf {[}true|false|input{]} & \seqsplit{跨平台换行符配置} \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{-{}-system 系统级,-{}-global 用户级(推荐),-{}-local \seqsplit{仓库级。每一个级别会覆盖前一级别的配置。}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.8 cm} x{5.2 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Git 分支}} \tn % Row 0 \SetRowColor{LightBackground} git branch\{\{width=40\}\} & \seqsplit{查看本地分支,后面添加分支名即可创建新分支} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} git checkout \textless{}branch\textgreater{} & 切换分支 \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Git \seqsplit{分支的本质是一个指向提交对象的可变指针,有一个名为} HEAD \seqsplit{的指针会指向当前所在的本地分支。}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.72 cm} x{5.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{拉取代码}} \tn % Row 0 \SetRowColor{LightBackground} git fetch\{\{width=40\}\} & \seqsplit{从远程仓库取回所有分支的更新,但不会修改本地工作目录的内容} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} git pull & \seqsplit{拉取代码并自动合并,=} git fetch + git merge \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} git pull -{}-rebase & 拉取代码并以 rebase 模式合并代码,= git fetch + git rebase \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.84 cm} x{4.16 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{合并代码}} \tn % Row 0 \SetRowColor{LightBackground} git merge \textless{}branch\textgreater{} \{\{width=55\}\} & \seqsplit{合并分支,使用} --no-ff \seqsplit{采用非快进合并} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} git cherry-pick -x \textless{}commit\textgreater{} & 合并提交,-x \seqsplit{在提交信息末尾追加来源,-s} \seqsplit{追加操作者签名} \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} git cherry-pick \textless{}commit1\textgreater{}..\textless{}commit2\textgreater{} & \seqsplit{合并多个连续的提交,左开右闭区间} \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} git cherry-pick \textless{}commit1\textgreater{}\textasciicircum{}..\textless{}commit2\textgreater{} & \seqsplit{合并多个连续的提交,左闭右闭区间} \tn % Row Count 13 (+ 3) % Row 4 \SetRowColor{LightBackground} git format-patch HEAD\textasciitilde{}n & 生成最近 n 次提交的补丁 \tn % Row Count 15 (+ 2) % Row 5 \SetRowColor{white} git am -{}-keep-cr \textless{}patch\textgreater{} & 打入补丁,-{}-keep-cr \seqsplit{防止回车符被移除导致打补丁失败,冲突时可使用} -{}-reject 查看冲突 \tn % Row Count 21 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{历史记录}} \tn % Row 0 \SetRowColor{LightBackground} git log -S \textless{}string\textgreater{}\{\{width=40\}\} & \seqsplit{查看与某个字符串} string 相关的改动 \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} git log -{}- \textless{}path\textgreater{} & \seqsplit{查看一个文件或目录的历史记录,可以此查询某个文件是何时被删除的} \tn % Row Count 8 (+ 5) % Row 2 \SetRowColor{LightBackground} git reflog & 查看本地仓库 HEAD \seqsplit{指针的所有变更,可用于恢复丢失的代码。} \tn % Row Count 12 (+ 4) % Row 3 \SetRowColor{white} git blame & 追踪代码改动 \tn % Row Count 13 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.4 cm} x{5.6 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{查看改动}} \tn % Row 0 \SetRowColor{LightBackground} git diff & \seqsplit{查看已修改文件的改动} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git diff -{}-staged & \seqsplit{查看已暂存文件的改动} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} git diff HEAD\textasciitilde{} & \seqsplit{查看最近一次已提交文件的改动} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{提交代码}} \tn % Row 0 \SetRowColor{LightBackground} git add \textless{}directory\textgreater{}\{\{width=42\}\} & \seqsplit{暂存指定目录或文件的改动,git} add . \seqsplit{会暂存当前目录的所有修改} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} git commit & \seqsplit{提交暂存区的代码,并打开文本编辑器编写提交信息} \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} git commit -m \textless{}message\textgreater{} & \seqsplit{提交暂存区的代码,将提交信息与命令放在同一行} \tn % Row Count 11 (+ 3) % Row 3 \SetRowColor{white} git commit -a & \seqsplit{跳过暂存区直接提交修改的代码,即跳过} git add 的操作 \tn % Row Count 15 (+ 4) % Row 4 \SetRowColor{LightBackground} git commit -{}-amend & \seqsplit{修改最后一次提交,可用来修改提交信息} \tn % Row Count 18 (+ 3) % Row 5 \SetRowColor{white} git push & \seqsplit{推送代码到远程仓库} \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\seqsplit{将已修改(Modified)的文件或未跟踪(Untracked)的文件添加(add)到暂存区(Staged),再将暂存区的文件提交(commit)到本地分支,最后将本地的提交推送(push)到远程仓库。}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.92 cm} x{4.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{撤消改动}} \tn % Row 0 \SetRowColor{LightBackground} git clean -f\{\{width=45\}\} & \seqsplit{删除未跟踪的文件,-f} \seqsplit{后面可以指定路径,如果不指定路径就是当前目录,-d} \seqsplit{可以移除文件夹} \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} git clean -ndf & -n \seqsplit{显示会被删除的文件,并不会执行移除操作,可使用该参数防止误删} \tn % Row Count 12 (+ 5) % Row 2 \SetRowColor{LightBackground} git checkout -{}- \textless{}filename\textgreater{} & \seqsplit{撤消指定文件的修改} \tn % Row Count 14 (+ 2) % Row 3 \SetRowColor{white} git checkout . & \seqsplit{撤消所有文件的修改} \tn % Row Count 16 (+ 2) % Row 4 \SetRowColor{LightBackground} git reset HEAD \textless{}filename\textgreater{} & \seqsplit{将指定文件从暂存区撤消} \tn % Row Count 18 (+ 2) % Row 5 \SetRowColor{white} git reset HEAD . & \seqsplit{将所有暂存区的文件撤消,即回退到} git add 之前 \tn % Row Count 22 (+ 4) % Row 6 \SetRowColor{LightBackground} git reset -{}-{[}mixed|soft|hard{]} \textless{}commit\textgreater{} & \seqsplit{撤消本地提交,默认参数是} -{}-mixed,使用 -{}-hard 时需小心 \tn % Row Count 26 (+ 4) % Row 7 \SetRowColor{white} git revert \textless{}commit\textgreater{} & \seqsplit{回滚提交,会创建一个新提交撤消} \textless{}commit\textgreater{} 的改动 \tn % Row Count 30 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.72 cm} x{5.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{贮藏改动}} \tn % Row 0 \SetRowColor{LightBackground} git stash\{\{width=40\}\} & \seqsplit{贮藏文件的修改,使用} -u \seqsplit{也会贮藏未跟踪的文件} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} git stash list & \seqsplit{列出所有贮藏的改动} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} git stash apply & \seqsplit{应用最近一次贮藏的改动,后面跟上} stash@\{n\} 可指定对应的记录 \tn % Row Count 9 (+ 4) % Row 3 \SetRowColor{white} git stash pop & \seqsplit{应用最近一次贮藏的改动,并将这条贮藏丢弃} \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} git stash drop & \seqsplit{丢弃最近一次贮藏的改动,后面跟上} stash@\{n\} 可指定对应的记录 \tn % Row Count 16 (+ 4) % Row 5 \SetRowColor{white} git stash clear & \seqsplit{丢弃所有的贮藏改动} \tn % Row Count 18 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\seqsplit{贮藏的改动使用栈存储}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{调整历史记录}} \tn % Row 0 \SetRowColor{LightBackground} git rebase -i HEAD\textasciitilde{}n\{\{width=40\}\} & \seqsplit{以交互方式重新应用最近} n \seqsplit{次的提交,可对提交进行修改} \tn % Row Count 4 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Git \seqsplit{并没有一个修改历史记录的工具,但是却可以利用变基命令来变基一系列提交,从而达到修改历史记录的目的。}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}