\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{arthurmilchior} \pdfinfo{ /Title (chrome-git.pdf) /Creator (Cheatography) /Author (arthurmilchior) /Subject (Chrome-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}{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{Chrome-git Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{arthurmilchior} via \textcolor{DarkBackground}{\uline{cheatography.com/188825/cs/39386/}}} \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}arthurmilchior \\ \uline{cheatography.com/arthurmilchior} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 28th June, 2023.\\ Updated 29th June, 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} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Tricks}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{To see change of last commits in your IDE, cancel last commit with `git reset HEAD\textasciitilde{}`. Last commit's will be highlighted similarly to change your are making right now.} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{To work on a gerrit CL you don't have locally, use gerrit's download feature, then `git cl issue ClNumber`, so that any change you made is pushed back on the same CL} \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{If you think you may have lost data, do NOT do `rebase-update`, as it triggers a garbage collection} \tn % Row Count 10 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{rm -f .git/index; git reset` if git output inconsistent information, that recompute the index that is used to detect local change} \tn % Row Count 13 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{git reflog example}} \tn % Row 0 \SetRowColor{LightBackground} After `git commit -{}-amend` I realized I prefered the last version of the branch.\{\{nl\}\}How do I get it back? & `git reflog myBranch` to find the hash,\{\{nl\}\}then `git reset -{}-hard HASH` \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} After `git pull`, I got a merge conflict. I resolved it incorrectly.\{\{nl\}\}Now, I realise I'd prefer to undo the pull and resolve again. & `git reflog myBranch` to find the hash,\{\{nl\}\}then `git reset -{}-hard origin/main; git rebase HASH` \tn % Row Count 13 (+ 7) % Row 2 \SetRowColor{LightBackground} I used `git commit` but can't find back the branch with my commit. & `git reflog` to find the hash,\{\{nl\}\}then `git branch recoveredBranch HASH` \tn % Row Count 17 (+ 4) \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}{Git log examples}} \tn % Row 0 \SetRowColor{LightBackground} git log -p -1 & Show all change in last commit \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git log -G "myFunction(" folder & Show all places `myFunction` was called in `folder`\{\{nl\}\}Extremely costly if not restricted to some folder \tn % Row Count 7 (+ 5) % Row 2 \SetRowColor{LightBackground} git log -L 15:25:myFile & If `myFunction` is currently defined in line 15-25 of `myFile`,\{\{nl\}\}this show all commits changing `myFunction`, including file rename (but not move inside the file) \tn % Row Count 15 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Branch edition}} \tn % Row 0 \SetRowColor{LightBackground} git new-branch branch\_name & New branch tracking origin/main \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git new-branch branch\_name -{}-upstream\_curent & New branch tracking current branch \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} git branch branch\_name commitHash; git switch branch\_name & New branch starting at commitHash \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} git branch child -{}-set-upstream-to parent & Ensure `child` tracks `parent` with `rebase-update` and `pull` \tn % Row Count 12 (+ 4) % Row 4 \SetRowColor{LightBackground} git branch child -{}-set-upstream-to origin/main & Ensure child does not depends on another branch and gets updated with \seqsplit{`pull`/`rebase-update`} \tn % Row Count 17 (+ 5) \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}{Information on current branches}} \tn % Row 0 \SetRowColor{LightBackground} git map-branches & The tree \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} git map-branches -v & with number of commits \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} git map-branches -vv & and hash and url \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} git map-branches -vvv & and gerrit status \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.64 cm} x{5.36 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Change branch}} \tn % Row 0 \SetRowColor{LightBackground} git switch myBranch & Switch to myBranch \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git cl checkout 1234 & Switch to branch linked to gerrit CL 1234 \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.08 cm} x{3.92 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{File edition}} \tn % Row 0 \SetRowColor{LightBackground} ./tools/boilerplate.py\{\{nl\}\}file.\{h,mm\} & Create files\{\{nl\}\}require `git add` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{./tools/git/move\_source\_file}.py\{\{nl\}\}old\_file.ext new\_file.ext & Move file\{\{nl\}\}edit imports and guards \tn % Row Count 6 (+ 4) \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}{Commit all current changes}} \tn % Row 0 \SetRowColor{LightBackground} git add . & if new/renamed files \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} git commit -a\{\{nl\}\}-m "Commit message" & New commit \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} git commit -a -{}-amend\{\{nl\}\}-{}-no-edit & Edit the commit \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} git reset HEAD\textasciitilde{} & Cancel last commit\{\{nl\}\}Keep all changes \tn % Row Count 7 (+ 2) \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}{Update to lastest version of the code}} \tn % Row 0 \SetRowColor{LightBackground} git rebase-update & fetch latest version of chrome code, update all branches that has upstream-set (see map-branch) \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} git rebase-update -n & Restart rebase-update after a conflict. Does not fetch \tn % Row Count 8 (+ 3) % Row 2 \SetRowColor{LightBackground} git pull origin main & Fetch latest version of chrome code and put your change on top of it \tn % Row Count 12 (+ 4) % Row 3 \SetRowColor{white} git pull & Apply your code on top of latest version of the tracked branch; (usually origin/main) \tn % Row Count 17 (+ 5) % Row 4 \SetRowColor{LightBackground} git add .;\{\{nl\}\}git rebase -{}-continue & To use after conflict resolution \tn % Row Count 19 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.32 cm} x{5.68 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Pause and restart current changes}} \tn % Row 0 \SetRowColor{LightBackground} git stash & save for later \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} git stash list & show all stashes \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} git stash pop & reapply last stash \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} git stash pop 3 & reapply stash 3 from `list` \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} git stash show 3 & display content of stash 3\{\{nl\}\}Works as `git log` \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Clean changes}} \tn % Row 0 \SetRowColor{LightBackground} git cl format & Format edited code \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \seqsplit{./ios/build/tools/update\_deps.py} out/FOLDER . & Add missing dependencies\{\{nl\}\}Not ios specific. Beta \tn % Row Count 4 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.48 cm} x{5.52 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Gerrit upload}} \tn % Row 0 \SetRowColor{LightBackground} git cl upload & Upload diff between current branch and upstream \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} -d & start dry-run \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} -r googler & add `googler` as reviewer \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} -{}-r-owners & automatically choose reviewers for all files \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} -t "patch message" & (not on first upload) \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.64 cm} x{5.36 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Gerrit}} \tn % Row 0 \SetRowColor{LightBackground} git cl web & open this cl on gerrit \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} git cl issue & the gerrit cl number \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} git cl issue 1234 & Link this branch to gerrit cl 1234 \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{git cl lol} \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.64 cm} x{5.36 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{See local changes}} \tn % Row 0 \SetRowColor{LightBackground} git diff HEAD & Change since last commit \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} git diff & changes that are not `git add`ed \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} git diff origin/main & Change from origin/main \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} git diff HEAD\textasciitilde{} & The commit you'd get with `get commit -a -{}-no-edit` \tn % Row Count 8 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{git log}} \tn % Row 0 \SetRowColor{LightBackground} git log & list current commit and its parents \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git log branchName & list last commit of branchName and its parents \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} git log commitHash & list commit commitHash and its parents \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} -p & Show the change in each files \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} -2 & Only show two last commits \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} -L 12:15:file & Restrict to commits touching lines 12 to 15 of `file` \tn % Row Count 13 (+ 3) % Row 6 \SetRowColor{LightBackground} -G "myRegexp" & Restrict to commits adding a change matching `myRegexp` \tn % Row Count 16 (+ 3) % Row 7 \SetRowColor{white} file\_1 file\_2 ... file\_n & restrict to commits editing some of file\_i \tn % Row Count 18 (+ 2) % Row 8 \SetRowColor{LightBackground} -{}-author name & restrict to commit authored by `name`\{\{nl\}\}You only need to enter a small part of the name \tn % Row Count 22 (+ 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}{reflog}} \tn % Row 0 \SetRowColor{LightBackground} git reflog & List all recent commits. Even those that are not in branches anymore. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} git reflog branchName & List all past and present version of branchName \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.44 cm} x{4.56 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Working with a commit}} \tn % Row 0 \SetRowColor{LightBackground} git show commitHash & Show the content of `commitHash` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} git show commitHash:file & show `file` at commit commitHash \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} git cherry-pick commitHash & Apply commitHash on top of current branch \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} git restore -s commitHash file & Change `file` to the version at commitHash \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.12 cm} x{4.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Navigating commits}} \tn % Row 0 \SetRowColor{LightBackground} commitRef\textasciitilde{} & The parent of commitRef \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} commitRef\textasciitilde{}3 & The grand-grand-parent of commitRef \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} branchName@\{yesterday\} & The commit of branchName yesterday \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}