\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{milefashi} \pdfinfo{ /Title (git-cheatssheet.pdf) /Creator (Cheatography) /Author (milefashi) /Subject (git cheatssheet 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}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \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 cheatssheet Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{milefashi} via \textcolor{DarkBackground}{\uline{cheatography.com/125430/cs/24139/}}} \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}milefashi \\ \uline{cheatography.com/milefashi} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 27th August, 2020.\\ Updated 27th August, 2020.\\ 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*}{3} \begin{tabularx}{5.377cm}{x{3.13551 cm} x{1.84149 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{创建git库}} \tn % Row 0 \SetRowColor{LightBackground} git init & \seqsplit{创建本地库} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git clone \textless{}respority\_addr\textgreater{} & \seqsplit{克隆远程库} \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.78712 cm} x{2.18988 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{添加文件}} \tn % Row 0 \SetRowColor{LightBackground} git add \textless{}filename\textgreater{} & \seqsplit{将修改提交至修改区} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git commit -m "\textless{}message\textgreater{}" & \seqsplit{将修改保存至本地库} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} git commit -amend {[}-m "\textless{}message\textgreater{}"{]} & \seqsplit{修改上一次提交} \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.28942 cm} x{2.68758 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{查看状态}} \tn % Row 0 \SetRowColor{LightBackground} git status & 查看仓库状态 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} git status -s & \seqsplit{查看工作区状态} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} git diff \textless{}filename\textgreater{} & \seqsplit{查看文件修改内容} \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} git diff \textless{}commit\_id\textgreater{} & \seqsplit{查看特定提交与工作区的差异} \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} git diff \textless{}commit\_id1\textgreater{} \textless{}commit\_id2\textgreater{} & \seqsplit{查看两次提交的区别} \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} git log -{}-oneline & \seqsplit{查看每个log首行} \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} git log -graph -{}-all & \seqsplit{查看所有log,并以提交图形显示} \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.94103 cm} x{3.03597 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{文件删除}} \tn % Row 0 \SetRowColor{LightBackground} git rm -cached \textless{}filename\textgreater{} & \seqsplit{从暂存区删除,不改变工作区} \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.23965 cm} x{2.73735 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{分支管理}} \tn % Row 0 \SetRowColor{LightBackground} git branch \textless{}branch\_name\textgreater{} & 创建分支 \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git checkout/switch \textless{}branch\_name\textgreater{} & 切换到指定分支 \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} git checkout -b \textless{}branch\_name\textgreater{} & 创建并切换分支 \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} git branch -D/d \textless{}branch\_name\textgreater{} & (强制)删除分支 \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} git branch {[}-r|-a{]} & -r \seqsplit{查看远程分支;-a} 查看本地分支 \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} git cherry-pick \textless{}commit\_id\textgreater{} & \seqsplit{将指定提交的改变复制到当前分支} \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} git merge \textless{}branch\_name\textgreater{} & \seqsplit{合并指定分支到当前分支上} \tn % Row Count 16 (+ 2) % Row 7 \SetRowColor{white} git rebase & \seqsplit{简介为push的历史提交记录,使其log成直线} \tn % Row Count 19 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.83689 cm} x{2.14011 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{标签管理}} \tn % Row 0 \SetRowColor{LightBackground} git tag -a \textless{}tag\_name\textgreater{} -m "\textless{}message\textgreater{}" & \seqsplit{指定标签信息} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git tag & \seqsplit{查看所有标签} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} git push origin \textless{}tag\_name\textgreater{} & \seqsplit{推送本地标签至远程} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} git push origin -{}-tags & \seqsplit{推送所有标签} \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.34379 cm} x{3.63321 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{保存与恢复工作}} \tn % Row 0 \SetRowColor{LightBackground} git stash & 保存工作状态 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} git stash pop & \seqsplit{恢复并删除已保存工作状态} \tn % Row Count 3 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{远程库操作}} \tn % Row 0 \SetRowColor{LightBackground} git remote add origin \textless{}url\textgreater{} & 关联远程库 \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git remote add \textless{}short\_name\textgreater{} \textless{}url\textgreater{} & 添加远程仓库 \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} git remote {[}-v{]} & 查看远程库信息{[}显示url{]} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} git push -u origin master & \seqsplit{第一次推送到远程master分支} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} git push origin \textless{}branch\_name\textgreater{} & \seqsplit{推送本地分支到远程对应分支上} \tn % Row Count 11 (+ 3) % Row 5 \SetRowColor{white} git push {[}remote{]} {[}local\_branch{]}:{[}remote\_branch{]} & \seqsplit{推送数据至远程版本库} \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} git pull {[}remote{]} {[}remote\_branch{]} & \seqsplit{抓取远程库分支并与本地分支合并} \tn % Row Count 17 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.04057 cm} x{2.93643 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{版本回退}} \tn % Row 0 \SetRowColor{LightBackground} git reset -{}-soft & \seqsplit{回到之前版本,该版本之后的改变保存在缓存去(已执行add操作)} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} git reset -{}-mixed & \seqsplit{回到之前版本,该版本之后的改变未丢失(未执行add操作)} \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} git reset -{}-hard & \seqsplit{回到之前版本,该版本之后的改变消失,完全回退} \tn % Row Count 11 (+ 3) % Row 3 \SetRowColor{white} git reset -{}-hard \textless{}commit\_id\textgreater{} & 回退到指定版本 \tn % Row Count 13 (+ 2) % Row 4 \SetRowColor{LightBackground} git reflog & \seqsplit{查看历史提交命令及commit} id \tn % Row Count 15 (+ 2) % Row 5 \SetRowColor{white} git checkout -{}- \textless{}filename\textgreater{} & 暂存区回退 \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}