├── LICENSE ├── Makefile ├── README.md ├── git-handout.pdf ├── git.pdf ├── git.tex └── img └── lifecycle.png /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License 2 | 3 | Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible. 4 | 5 | By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. 6 | 7 | Section 1 – Definitions. 8 | 9 | Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. 10 | Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. 11 | BY-NC-SA Compatible License means a license listed at creativecommons.org/compatiblelicenses, approved by Creative Commons as essentially the equivalent of this Public License. 12 | Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 13 | Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. 14 | Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. 15 | License Elements means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution, NonCommercial, and ShareAlike. 16 | Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License. 17 | Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. 18 | Licensor means the individual(s) or entity(ies) granting rights under this Public License. 19 | NonCommercial means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange. 20 | Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. 21 | Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. 22 | You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. 23 | Section 2 – Scope. 24 | 25 | License grant. 26 | Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: 27 | reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and 28 | produce, reproduce, and Share Adapted Material for NonCommercial purposes only. 29 | Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. 30 | Term. The term of this Public License is specified in Section 6(a). 31 | Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. 32 | Downstream recipients. 33 | Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. 34 | Additional offer from the Licensor – Adapted Material. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply. 35 | No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 36 | No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). 37 | Other rights. 38 | 39 | Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 40 | Patent and trademark rights are not licensed under this Public License. 41 | To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes. 42 | Section 3 – License Conditions. 43 | 44 | Your exercise of the Licensed Rights is expressly made subject to the following conditions. 45 | 46 | Attribution. 47 | 48 | If You Share the Licensed Material (including in modified form), You must: 49 | 50 | retain the following if it is supplied by the Licensor with the Licensed Material: 51 | identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); 52 | a copyright notice; 53 | a notice that refers to this Public License; 54 | a notice that refers to the disclaimer of warranties; 55 | a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 56 | indicate if You modified the Licensed Material and retain an indication of any previous modifications; and 57 | indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 58 | You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 59 | If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. 60 | ShareAlike. 61 | In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply. 62 | 63 | The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-NC-SA Compatible License. 64 | You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material. 65 | You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply. 66 | Section 4 – Sui Generis Database Rights. 67 | 68 | Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: 69 | 70 | for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only; 71 | if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and 72 | You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. 73 | For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. 74 | Section 5 – Disclaimer of Warranties and Limitation of Liability. 75 | 76 | Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You. 77 | To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You. 78 | The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. 79 | Section 6 – Term and Termination. 80 | 81 | This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. 82 | Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: 83 | 84 | automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 85 | upon express reinstatement by the Licensor. 86 | For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. 87 | For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. 88 | Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 89 | Section 7 – Other Terms and Conditions. 90 | 91 | The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. 92 | Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. 93 | Section 8 – Interpretation. 94 | 95 | For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. 96 | To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. 97 | No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. 98 | Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. 99 | Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” The text of the Creative Commons public licenses is dedicated to the public domain under the CC0 Public Domain Dedication. Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at creativecommons.org/policies, Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. 100 | 101 | Creative Commons may be contacted at creativecommons.org. 102 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ALL: git.pdf 2 | 3 | %.pdf: %.tex 4 | xelatex $^ 5 | xelatex $^ 6 | xelatex $^ 7 | make clean 8 | 9 | clean : 10 | rm -f *.aux *.log *.nav *.out *.snm *.toc 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # learn git the not so super hard way 2 | 3 | Credit to [learn git the super hard way](https://github.com/b1f6c1c4/learn-git-the-super-hard-way) 4 | 5 | A simplified version of the super hard way, not so super hard. 6 | 7 | This talk is given in a TA session for the *Introduction to Computer Systems* course. 8 | 9 | Presentation version at [git.pdf](git.pdf) 10 | 11 | Handout version at [git-handout.pdf](git-handout.pdf) 12 | 13 | ## LICENSE 14 | 15 | CC BY-NC-SA 4.0 16 | -------------------------------------------------------------------------------- /git-handout.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZenithalHourlyRate/learn-git-the-not-so-super-hard-way/8319a239e51eb2d55bec721bbb4ce06d0fd5e5e8/git-handout.pdf -------------------------------------------------------------------------------- /git.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZenithalHourlyRate/learn-git-the-not-so-super-hard-way/8319a239e51eb2d55bec721bbb4ce06d0fd5e5e8/git.pdf -------------------------------------------------------------------------------- /git.tex: -------------------------------------------------------------------------------- 1 | \documentclass[aspectratio=169]{beamer} 2 | 3 | \usetheme{Madrid} 4 | \beamertemplatenavigationsymbolsempty 5 | 6 | %\usecolortheme{beaver} 7 | % the following colors are modified from beaver 8 | \definecolor{tuna}{rgb}{0.098,0.51,0.996} 9 | \definecolor{thu}{rgb}{0.50,0.36,0.71} 10 | 11 | \setbeamercolor{section in toc}{fg=black,bg=white} 12 | \setbeamercolor{item}{fg=tuna,bg=white} 13 | \setbeamercolor{alerted text}{fg=tuna!80!gray} 14 | \setbeamercolor*{palette primary}{fg=tuna!60!black,bg=gray!30!white} 15 | \setbeamercolor*{palette secondary}{fg=tuna!70!black,bg=gray!15!white} 16 | \setbeamercolor*{palette tertiary}{bg=tuna!80!black,fg=gray!10!white} 17 | \setbeamercolor*{palette quaternary}{fg=tuna,bg=gray!5!white} 18 | 19 | \setbeamercolor*{sidebar}{fg=tuna,bg=gray!15!white} 20 | 21 | \setbeamercolor*{palette sidebar primary}{fg=tuna!10!black} 22 | \setbeamercolor*{palette sidebar secondary}{fg=white} 23 | \setbeamercolor*{palette sidebar tertiary}{fg=tuna!50!black} 24 | \setbeamercolor*{palette sidebar quaternary}{fg=gray!10!white} 25 | 26 | %\setbeamercolor*{titlelike}{parent=palette primary} 27 | \setbeamercolor{titlelike}{parent=palette primary,fg=tuna} 28 | \setbeamercolor{frametitle}{bg=gray!10!white} 29 | \setbeamercolor{frametitle right}{bg=gray!60!white} 30 | 31 | \setbeamercolor*{separation line}{} 32 | \setbeamercolor*{fine separation line}{} 33 | 34 | \setbeamertemplate{sections/subsections in toc}[square] 35 | \setbeamertemplate{items}[square] 36 | 37 | % https://tex.stackexchange.com/questions/248131/delete-institute-space-in-title-page-beamer-class 38 | \defbeamertemplate{title page}{noinstitute}[1][] 39 | { 40 | \vbox{} 41 | \vfill 42 | \begingroup 43 | \centering 44 | \begin{beamercolorbox}[sep=8pt,center,#1]{title} 45 | \usebeamerfont{title}\inserttitle\par% 46 | \ifx\insertsubtitle\@empty% 47 | \else% 48 | \vskip0.25em% 49 | {\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}% 50 | \fi% 51 | \end{beamercolorbox}% 52 | \vskip1em\par 53 | \begin{beamercolorbox}[sep=8pt,center,#1]{author} 54 | \usebeamerfont{author}\insertauthor 55 | \end{beamercolorbox} 56 | \begin{beamercolorbox}[sep=8pt,center,#1]{date} 57 | \usebeamerfont{date}\insertdate 58 | \end{beamercolorbox}\vskip0.5em 59 | {\usebeamercolor[fg]{titlegraphic}\inserttitlegraphic\par} 60 | \endgroup 61 | \vfill 62 | } 63 | 64 | \makeatletter 65 | \setbeamertemplate{title page}[noinstitute][colsep=-4bp,rounded=true,shadow=\beamer@themerounded@shadow] 66 | \makeatother 67 | 68 | \AtBeginSection[]{ 69 | \begin{frame} 70 | \vfill 71 | \centering 72 | \begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title} 73 | \usebeamerfont{title}\insertsectionhead\par% 74 | \end{beamercolorbox} 75 | \vfill 76 | \end{frame} 77 | } 78 | 79 | \usepackage{tikz} 80 | \usetikzlibrary{calc} 81 | \usetikzlibrary{arrows} 82 | \usetikzlibrary{shapes} 83 | \usepackage{hyperref} 84 | 85 | \newcommand{\T}[1]{\texttt{#1}} 86 | 87 | \title[Learn Git]{Learn Git The Not So Super Hard Way\footnote{Credit to https://github.com/b1f6c1c4/learn-git-the-super-hard-way}} 88 | \author[zenithal]{Zenithal} 89 | \date{2022-03-31} 90 | 91 | \begin{document} 92 | 93 | \begin{frame} 94 | \titlepage 95 | \end{frame} 96 | 97 | \begin{frame}{Why this} 98 | \begin{itemize} 99 | \item<1-> Learning git is painful\begin{itemize} 100 | \item Too many concepts (commit, branch, stage, index) 101 | \item Too many commands (clone, pull, push) 102 | \end{itemize} 103 | \item<2-> State machine too complex\begin{itemize} 104 | \item You often do not know what state you are in 105 | \item Conflict! Help me ERIN! 106 | \end{itemize} 107 | \item<3-> Learning about commands is not enough\begin{itemize} 108 | \item You often do not know what's going on 109 | \item Let's break it down to basic elements 110 | \end{itemize} 111 | \item<4-> The super hard way is super easy\begin{itemize} 112 | \item You change the file, you know what's going on 113 | \end{itemize} 114 | \end{itemize} 115 | \end{frame} 116 | 117 | \section{init} 118 | \begin{frame}{git repo structure} 119 | \begin{itemize} 120 | \item git repo\begin{itemize} 121 | \item often the \T{.git} 122 | \item often contains HEAD, config 123 | \end{itemize} 124 | \item worktree\begin{itemize} 125 | \item the file 126 | \item often contains README.md, main.c, main.h 127 | \item worktree is just a checkout of the git repo 128 | \item you can re-contruct your worktree from the git repo 129 | \item the git repo is essential, but worktree is not 130 | \end{itemize} 131 | \end{itemize} 132 | \end{frame} 133 | 134 | \begin{frame}{git init} 135 | \begin{itemize} 136 | \item \T{mkdir .git} 137 | \item \T{mkdir .git/objects}\begin{itemize} 138 | \item Must have 139 | \end{itemize} 140 | \item \T{mkdir .git/refs}\begin{itemize} 141 | \item Must have 142 | \end{itemize} 143 | \item \T{echo 'ref: refs/heads/master' > .git/HEAD}\begin{itemize} 144 | \item Establish {HEAD} ref 145 | \item HEAD points to \T{.git/refs/heads/master} (Even though it does not exist now) 146 | \item Side note: \T{refs/heads/main} 147 | \end{itemize} 148 | \item config, hooks, info, etc are not necessary 149 | \item Now you can \T{git status} to check the status 150 | \end{itemize} 151 | \end{frame} 152 | 153 | \section{objects} 154 | \begin{frame}{objects} 155 | \begin{itemize} 156 | \item<1-> You have created \T{.git/objects}, then what are objects 157 | \item<2-> Four types of objects\begin{itemize} 158 | \item<3-> blob: file content 159 | \item<4-> tree: folder\begin{itemize} 160 | \item Side note: what's in folder in file system 161 | \item filename (stored here instead of in blob!) 162 | \item hash of blobs/trees (folder structure!) 163 | \end{itemize} 164 | \item<5-> commit: a state of the root folder\begin{itemize} 165 | \item contains one specific tree 166 | \item parent(s): other commit(s) 167 | \item author/committer/commit message: meta data 168 | \end{itemize} 169 | \item<6-> tag: will not introduce today 170 | \end{itemize} 171 | \end{itemize} 172 | \end{frame} 173 | 174 | \begin{frame}[fragile]{blob} 175 | \begin{itemize} 176 | \item<1-> blob: file content 177 | \item<2-> \T{echo 'hello' | git hash-object -t blob --stdin -w}\begin{itemize} 178 | \item Write a blob/file whose content is \T{'hello'} 179 | \item hash that content to an object in type \T{blob} from \T{stdin} then \T{w}rite to the object database 180 | \item Output: \T{ce013625030ba8dba906f756967f9e9ca394464a}, the hash of the object 181 | \end{itemize} 182 | \item<3-> \T{cat .git/objects/ce/013625030ba8dba906f756967f9e9ca394464a}\begin{itemize} 183 | \item Output: \T{xKOR0cH}, compressed content of hello 184 | \item note the object path! 185 | \end{itemize} 186 | \item<4-> Check the actual content\begin{verbatim} 187 | $ printf '\x1f\x8b\x08\x00\x00\x00\x00\x00' \ 188 | | cat - .git/objects/ce/013625030ba8dba906f756967f9e9ca394464a \ 189 | | gunzip -dc 2>/dev/null | xxd 190 | # 00000000: 626c 6f62 2036 0068 656c 6c6f 0a blob 6.hello. 191 | \end{verbatim} 192 | \end{itemize} 193 | \end{frame} 194 | 195 | \begin{frame}{blob (cont'd)} 196 | \begin{itemize} 197 | \item Painful using raw command? Of course we have higher level instructions 198 | \item \T{git cat-file blob ce01}\begin{itemize} 199 | \item Output: \T{hello} 200 | \end{itemize} 201 | \item \T{git show ce01}\begin{itemize} 202 | \item Output: \T{hello} 203 | \end{itemize} 204 | \end{itemize} 205 | \end{frame} 206 | 207 | \begin{frame}[fragile]{tree} 208 | \begin{itemize} 209 | \item<1-> tree: folder 210 | \item<2-> Create a tree\begin{verbatim} 211 | (printf '100644 name.ext\x00'; 212 | echo '0: ce013625030ba8dba906f756967f9e9ca394464a' | xxd -rp -c 256; 213 | printf '100755 name2.ext\x00'; 214 | echo '0: ce013625030ba8dba906f756967f9e9ca394464a' | xxd -rp -c 256) \ 215 | | git hash-object -t tree --stdin -w 216 | # 58417991a0e30203e7e9b938f62a9a6f9ce10a9a 217 | \end{verbatim} 218 | \item<3-> You can also (another format)\begin{verbatim} 219 | git mktree --missing < Directly inspect file content\begin{verbatim} 231 | printf '\x1f\x8b\x08\x00\x00\x00\x00\x00' \ 232 | | cat - .git/objects/58/417991a0e30203e7e9b938f62a9a6f9ce10a9a \ 233 | | gunzip -dc 2>/dev/null | xxd 234 | \end{verbatim} 235 | \item<2-> \T{git cat-file tree 5841 | xxd} 236 | \item<3-> \T{git ls-tree 5841} (Compare with mktree above) 237 | \item<4-> \T{git show 5841} (A more simple version) 238 | \end{itemize} 239 | \end{frame} 240 | 241 | \begin{frame}[fragile]{commit} 242 | Directly create file\begin{verbatim} 243 | git hash-object -t commit --stdin -w < 1514736000 +0800 246 | committer b1f6c1c4 1514736000 +0800 247 | 248 | The commit message 249 | May have multiple 250 | lines! 251 | EOF 252 | # d4dafde7cd9248ef94c0400983d51122099d312a 253 | \end{verbatim} 254 | \end{frame} 255 | 256 | \begin{frame}[fragile]{commit (cont'd)} 257 | Or from high level command\begin{verbatim} 258 | GIT_AUTHOR_NAME=b1f6c1c4 \ 259 | GIT_AUTHOR_EMAIL=b1f6c1c4@gmail.com \ 260 | GIT_AUTHOR_DATE='1600000000 +0800' \ 261 | GIT_COMMITTER_NAME=b1f6c1c4 \ 262 | GIT_COMMITTER_EMAIL=b1f6c1c4@gmail.com \ 263 | GIT_COMMITTER_DATE='1600000000 +0800' \ 264 | git commit-tree 5841 -p d4da < Directly inspect file content\begin{verbatim} 277 | printf '\x1f\x8b\x08\x00\x00\x00\x00\x00' \ 278 | | cat - ./objects/ef/d4f82f6151bd20b167794bc57c66bbf82ce7dd \ 279 | | gunzip -dc 2>/dev/null | xxd 280 | \end{verbatim} 281 | \item<2-> \T{git cat-file commit efd4} 282 | \item<3-> \T{git show efd4~} (A more simple version, in diff format) 283 | \item<3-> Note: commits are snapshots, not diffs/patchs\footnote{https://github.blog/2020-12-17-commits-are-snapshots-not-diffs/} 284 | \end{itemize} 285 | \end{frame} 286 | 287 | \begin{frame}[fragile]{Lucky commit} 288 | \begin{itemize} 289 | \item Feeling hash too boring? 290 | \item Try lucky commit!\footnote{https://github.com/not-an-aardvark/lucky-commit} 291 | \item \begin{verbatim} 292 | $ git log 293 | 1f6383a Some commit 294 | $ lucky_commit 295 | $ git log 296 | 0000000 Some commit 297 | \end{verbatim} 298 | \item Note the commit msg in the prev slide, we can change it to mine a lucky hash 299 | \end{itemize} 300 | \end{frame} 301 | 302 | \section{ref} 303 | \begin{frame}{ref} 304 | \begin{itemize} 305 | \item ref is a convenient reference to one specific commit/other ref 306 | \item in \T{.git/ref} 307 | \item two types of ref\begin{itemize} 308 | \item direct ref 309 | \item indirect ref, e.g. \T{HEAD} (often the case) 310 | \end{itemize} 311 | \item two common refs we will introduce today\begin{itemize} 312 | \item heads: local branch 313 | \item remotes: remote branch 314 | \end{itemize} 315 | \end{itemize} 316 | \end{frame} 317 | 318 | \begin{frame}[fragile]{local branch and direct ref} 319 | \begin{itemize} 320 | \item<1-> Create file (not recommended as no reflog)\begin{verbatim} 321 | mkdir -p .git/refs/heads/ 322 | echo d4dafde7cd9248ef94c0400983d51122099d312a > .git/refs/heads/br1 323 | \end{verbatim} 324 | \item<2-> The following command will leave reflog in \T{.git/log/refs/heads/br1} 325 | \item<2-> \T{git update-ref --no-deref -m 'Reason for update' refs/heads/br1 d4da} 326 | \item<2-> \T{git branch -f br1 d4da} 327 | \end{itemize} 328 | \end{frame} 329 | 330 | \begin{frame}{about reflog} 331 | \begin{itemize} 332 | \item Record all the changes to your ref 333 | \item Useful when you accidently switch to another place\begin{itemize} 334 | \item \T{git rebase master} 335 | \item \T{git checkout -B master origin/master} 336 | \item then you want to switch to old tree for some reason 337 | \item reflog shows the commit that one ref \textbf{was} 338 | \end{itemize} 339 | \item Demo of my working dir: lots of reflogs 340 | \end{itemize} 341 | \end{frame} 342 | 343 | \begin{frame}{indirect ref} 344 | \begin{itemize} 345 | \item Remember when you init\begin{itemize} 346 | \item \T{echo 'ref: refs/heads/master' > .git/HEAD} 347 | \end{itemize} 348 | \item This format is indirect ref 349 | \end{itemize} 350 | \end{frame} 351 | 352 | \section{index} 353 | \begin{frame}{index} 354 | \begin{figure} 355 | \centering 356 | \includegraphics[width=0.7\textwidth]{img/lifecycle.png} 357 | \end{figure} 358 | \begin{itemize} 359 | % stage figure here 360 | \item index stores what to be commited when you \T{git commit} 361 | \item file at \T{.git/index} 362 | \item often we call things in index as staged (the figure above) 363 | \item a complex database 364 | \item contains many things, like filename, mode, hash, mtime, etc 365 | \end{itemize} 366 | \end{frame} 367 | 368 | \begin{frame}{manipulate index} 369 | \begin{itemize} 370 | \item<1-> it is hard to manupulate index 371 | \item<1-> we study common cases here 372 | \item<1-> \T{git add} stores the content into index 373 | \item<1-> mark them ready for commit 374 | \item<2-> 1. \T{git add; git status}\begin{itemize} 375 | \item the file you added is ready for commit 376 | \end{itemize} 377 | \item<3-> 2. \T{git add; modify; git status}\begin{itemize} 378 | \item the file content you added is ready for commit 379 | \item the new file content you did not add is not visible to index 380 | \item \T{modify} will not be contained in commit 381 | \end{itemize} 382 | \item<4-> 3. \T{git add; rm; git status; git restore}\begin{itemize} 383 | \item even though file is deleted, it has a copy in \T{index} 384 | \item if you accidently \T{rm -rf *}, you can restore your file! 385 | \end{itemize} 386 | \end{itemize} 387 | \end{frame} 388 | 389 | \section{switch/checkout} 390 | \begin{frame}{switch/checkout} 391 | \begin{itemize} 392 | \item Recall that \T{.git/HEAD} is a ref 393 | \item This ref is for your worktree 394 | \item Recall your worktree is your actual content 395 | \item Change the content of your worktree by manipulating HEAD 396 | \end{itemize} 397 | \end{frame} 398 | 399 | \begin{frame}{switch/checkout (cont'd)} 400 | \begin{itemize} 401 | \item<1-> Most famous: \T{git checkout master}\begin{itemize} 402 | \item Make HEAD point to \T{refs/heads/master} 403 | \item Then checkout the content to your worktree 404 | \item That's why it is named checkout 405 | \item Actually an old syntax, recommend using switch now 406 | \item \T{git switch master} 407 | \end{itemize} 408 | \item<2-> Yet most famous: \T{git reset --hard HEAD$\sim$1}\begin{itemize} 409 | \item Change HEAD to HEAD$\sim$1 (the former commit of HEAD) 410 | \item Checkout the content to your worktree 411 | \item Note: there are \T{reset --soft/--mixed}, learn them by yourself 412 | \end{itemize} 413 | \end{itemize} 414 | \end{frame} 415 | 416 | \section{pull/clone/push} 417 | \begin{frame}{remotes} 418 | \begin{itemize} 419 | \item Recall that we have talked about \T{.git/refs/remotes} 420 | \item Since we have local ref(branch), we can also have remote ref(branch) 421 | \item If no remote branch, it is not a distributed version control system 422 | \item How to sync them? 423 | \item pull commit from remote to local 424 | \item push commit from local to remote 425 | \item So the concept of commit is very useful 426 | \end{itemize} 427 | \end{frame} 428 | 429 | \begin{frame}{config remote} 430 | \begin{itemize} 431 | \item If you want to have remote branch, you must have a remote first 432 | \item edit \T{.git/config} to add them 433 | \item or \T{git remote add origin git@github.com:xxx/yyy}\begin{itemize} 434 | \item \T{origin} is a convention, you can use other name 435 | \item You can have multiple remote 436 | \end{itemize} 437 | \item Demo of my repo 438 | \end{itemize} 439 | \end{frame} 440 | 441 | \begin{frame}{fetch remote} 442 | \begin{itemize} 443 | \item<1-> \T{git fetch origin master}\begin{itemize} 444 | \item Fetch the \T{master} ref from \T{origin} 445 | \item You can check \T{.git/refs/remotes/origin/master} now 446 | \end{itemize} 447 | \item<2-> \T{git pull origin master}\begin{itemize} 448 | \item despite \T{git fetch}, it tries to update your local ref 449 | \item Update \T{.git/refs/remotes/origin/master} 450 | \item and update \T{.git/refs/heads/master} accordingly 451 | \item The relationship is recorded in \T{.git/config} 452 | \end{itemize} 453 | \item<3-> \T{git pull}\begin{itemize} 454 | \item short hand for the above, according to your \T{.git/config} 455 | \end{itemize} 456 | \item<4-> \T{git clone}\begin{itemize} 457 | \item Actually a short hand for 458 | \item \T{git init} 459 | \item \T{git remote add} 460 | \item \T{git pull} 461 | \end{itemize} 462 | \end{itemize} 463 | \end{frame} 464 | 465 | \begin{frame}{push remote} 466 | \begin{itemize} 467 | \item<1-> \T{git push origin master}\begin{itemize} 468 | \item Sync your local branch master to remote branch master 469 | \end{itemize} 470 | \item<2-> \T{git push}\begin{itemize} 471 | \item short hand for the above, according to your \T{.git/config} 472 | \end{itemize} 473 | \item<3-> New branch then \T{git push -u origin :new-branch}\begin{itemize} 474 | \item Add a new ref in the remote 475 | \item At the same time set the upstream to new-branch 476 | \item Check your \T{.git/config} now 477 | \end{itemize} 478 | \end{itemize} 479 | \end{frame} 480 | 481 | \section{merge} 482 | \begin{frame}{merge} 483 | \begin{itemize} 484 | \item Now you have commits, you have refs 485 | \item How do you merge refs/branches together? 486 | \item recall that a branch points to a commit, a commit contains a specific tree 487 | \item Namely we need to merge tree, then we need to merge blob first 488 | \item How to merge blob? 489 | \end{itemize} 490 | \end{frame} 491 | 492 | \begin{frame}{two way merge} 493 | \begin{itemize} 494 | \item Two way means the algo can only see two files (our and their) 495 | \item Let's setup the file as \T{chapter6.md} 496 | \item Two way merge of \T{fileB} and \T{fileC}\begin{itemize} 497 | \item The change can be fileC has removed B in the first line and added C in the last line 498 | \item The change can be fileB has added B in the first line and deleted C in the last line 499 | \item Do not know how to merge, abort 500 | \end{itemize} 501 | \item It is not useful 502 | \end{itemize} 503 | \end{frame} 504 | 505 | \begin{frame}[fragile]{three way merge} 506 | \begin{itemize} 507 | \item Three way merge means the algo can see three files (base, our and their) 508 | \item Three way merge of \T{fileB} and \T{fileC} with \T{fileA} as base\begin{itemize} 509 | \item Compared with \T{fileA}, \T{fileB} added B in the first line 510 | \item Compared with \T{fileA}, \T{fileC} added C in the last line 511 | \item No conflict in changes 512 | \item \T{git merge-file --stdout } 513 | \item \T{git merge-file --stdout fileC fileA fileB}\begin{verbatim} 514 | lineBB 515 | ...some stuff... 516 | lineCC 517 | \end{verbatim} 518 | \end{itemize} 519 | \end{itemize} 520 | \end{frame} 521 | 522 | \begin{frame}[fragile]{three way merge (cont'd)} 523 | \begin{itemize} 524 | \item What if they both modify the same line? Conflict! 525 | \item Usually need manual involvement 526 | \item E.g. \T{git merge-file --stdout fileD fileA fileB}\begin{itemize} 527 | \item Compared with \T{fileA}, \T{fileD} added D in the first line 528 | \item Compared with \T{fileA}, \T{fileB} added B in the first line 529 | \item Output\begin{verbatim} 530 | <<<<<<< fileD 531 | lineBD 532 | ======= 533 | lineBB 534 | >>>>>>> fileB 535 | ...some stuff... 536 | lineC 537 | \end{verbatim} 538 | \end{itemize} 539 | \end{itemize} 540 | \end{frame} 541 | 542 | \begin{frame}[fragile]{How to resolve conflict} 543 | \begin{itemize} 544 | \item Remove all the helper line 545 | \item Leave the actual content\begin{verbatim} 546 | lineBBD 547 | ...some stuff... 548 | lineC 549 | \end{verbatim} 550 | \item Or if you are aware of what you are doing\begin{itemize} 551 | \item \T{git merge-file --ours --stdout fileD fileA fileB} 552 | \item Keep our change, discard theirs 553 | \item \T{git merge-file --theirs --stdout fileD fileA fileB} 554 | \item Keep their change, discard ours 555 | \item \T{git merge-file --union --stdout fileD fileA fileB} 556 | \item Keep both changes, concat them 557 | \end{itemize} 558 | \end{itemize} 559 | \end{frame} 560 | 561 | \end{document} 562 | 563 | % vim: nospell 564 | -------------------------------------------------------------------------------- /img/lifecycle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZenithalHourlyRate/learn-git-the-not-so-super-hard-way/8319a239e51eb2d55bec721bbb4ce06d0fd5e5e8/img/lifecycle.png --------------------------------------------------------------------------------