Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" |
| 2 | "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
| 4 | <head> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 6 | <meta name="generator" content="AsciiDoc 8.2.5" /> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 7 | <style type="text/css"> |
| 8 | /* Debug borders */ |
| 9 | p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 { |
| 10 | /* |
| 11 | border: 1px solid red; |
| 12 | */ |
| 13 | } |
| 14 | |
| 15 | body { |
| 16 | margin: 1em 5% 1em 5%; |
| 17 | } |
| 18 | |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 19 | a { |
| 20 | color: blue; |
| 21 | text-decoration: underline; |
| 22 | } |
| 23 | a:visited { |
| 24 | color: fuchsia; |
| 25 | } |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 26 | |
| 27 | em { |
| 28 | font-style: italic; |
| 29 | } |
| 30 | |
| 31 | strong { |
| 32 | font-weight: bold; |
| 33 | } |
| 34 | |
| 35 | tt { |
| 36 | color: navy; |
| 37 | } |
| 38 | |
| 39 | h1, h2, h3, h4, h5, h6 { |
| 40 | color: #527bbd; |
| 41 | font-family: sans-serif; |
| 42 | margin-top: 1.2em; |
| 43 | margin-bottom: 0.5em; |
| 44 | line-height: 1.3; |
| 45 | } |
| 46 | |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 47 | h1, h2, h3 { |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 48 | border-bottom: 2px solid silver; |
| 49 | } |
| 50 | h2 { |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 51 | padding-top: 0.5em; |
| 52 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 53 | h3 { |
| 54 | float: left; |
| 55 | } |
| 56 | h3 + * { |
| 57 | clear: left; |
| 58 | } |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 59 | |
| 60 | div.sectionbody { |
| 61 | font-family: serif; |
| 62 | margin-left: 0; |
| 63 | } |
| 64 | |
| 65 | hr { |
| 66 | border: 1px solid silver; |
| 67 | } |
| 68 | |
| 69 | p { |
| 70 | margin-top: 0.5em; |
| 71 | margin-bottom: 0.5em; |
| 72 | } |
| 73 | |
| 74 | pre { |
| 75 | padding: 0; |
| 76 | margin: 0; |
| 77 | } |
| 78 | |
| 79 | span#author { |
| 80 | color: #527bbd; |
| 81 | font-family: sans-serif; |
| 82 | font-weight: bold; |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 83 | font-size: 1.1em; |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 84 | } |
| 85 | span#email { |
| 86 | } |
| 87 | span#revision { |
| 88 | font-family: sans-serif; |
| 89 | } |
| 90 | |
| 91 | div#footer { |
| 92 | font-family: sans-serif; |
| 93 | font-size: small; |
| 94 | border-top: 2px solid silver; |
| 95 | padding-top: 0.5em; |
| 96 | margin-top: 4.0em; |
| 97 | } |
| 98 | div#footer-text { |
| 99 | float: left; |
| 100 | padding-bottom: 0.5em; |
| 101 | } |
| 102 | div#footer-badges { |
| 103 | float: right; |
| 104 | padding-bottom: 0.5em; |
| 105 | } |
| 106 | |
| 107 | div#preamble, |
| 108 | div.tableblock, div.imageblock, div.exampleblock, div.verseblock, |
| 109 | div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock, |
| 110 | div.admonitionblock { |
| 111 | margin-right: 10%; |
| 112 | margin-top: 1.5em; |
| 113 | margin-bottom: 1.5em; |
| 114 | } |
| 115 | div.admonitionblock { |
| 116 | margin-top: 2.5em; |
| 117 | margin-bottom: 2.5em; |
| 118 | } |
| 119 | |
| 120 | div.content { /* Block element content. */ |
| 121 | padding: 0; |
| 122 | } |
| 123 | |
| 124 | /* Block element titles. */ |
| 125 | div.title, caption.title { |
| 126 | font-family: sans-serif; |
| 127 | font-weight: bold; |
| 128 | text-align: left; |
| 129 | margin-top: 1.0em; |
| 130 | margin-bottom: 0.5em; |
| 131 | } |
| 132 | div.title + * { |
| 133 | margin-top: 0; |
| 134 | } |
| 135 | |
| 136 | td div.title:first-child { |
| 137 | margin-top: 0.0em; |
| 138 | } |
| 139 | div.content div.title:first-child { |
| 140 | margin-top: 0.0em; |
| 141 | } |
| 142 | div.content + div.title { |
| 143 | margin-top: 0.0em; |
| 144 | } |
| 145 | |
| 146 | div.sidebarblock > div.content { |
| 147 | background: #ffffee; |
| 148 | border: 1px solid silver; |
| 149 | padding: 0.5em; |
| 150 | } |
| 151 | |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 152 | div.listingblock { |
| 153 | margin-right: 0%; |
| 154 | } |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 155 | div.listingblock > div.content { |
| 156 | border: 1px solid silver; |
| 157 | background: #f4f4f4; |
| 158 | padding: 0.5em; |
| 159 | } |
| 160 | |
| 161 | div.quoteblock > div.content { |
| 162 | padding-left: 2.0em; |
| 163 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 164 | |
| 165 | div.attribution { |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 166 | text-align: right; |
| 167 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 168 | div.verseblock + div.attribution { |
| 169 | text-align: left; |
| 170 | } |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 171 | |
| 172 | div.admonitionblock .icon { |
| 173 | vertical-align: top; |
| 174 | font-size: 1.1em; |
| 175 | font-weight: bold; |
| 176 | text-decoration: underline; |
| 177 | color: #527bbd; |
| 178 | padding-right: 0.5em; |
| 179 | } |
| 180 | div.admonitionblock td.content { |
| 181 | padding-left: 0.5em; |
| 182 | border-left: 2px solid silver; |
| 183 | } |
| 184 | |
| 185 | div.exampleblock > div.content { |
| 186 | border-left: 2px solid silver; |
| 187 | padding: 0.5em; |
| 188 | } |
| 189 | |
| 190 | div.verseblock div.content { |
| 191 | white-space: pre; |
| 192 | } |
| 193 | |
| 194 | div.imageblock div.content { padding-left: 0; } |
| 195 | div.imageblock img { border: 1px solid silver; } |
| 196 | span.image img { border-style: none; } |
| 197 | |
| 198 | dl { |
| 199 | margin-top: 0.8em; |
| 200 | margin-bottom: 0.8em; |
| 201 | } |
| 202 | dt { |
| 203 | margin-top: 0.5em; |
| 204 | margin-bottom: 0; |
| 205 | font-style: italic; |
| 206 | } |
| 207 | dd > *:first-child { |
| 208 | margin-top: 0; |
| 209 | } |
| 210 | |
| 211 | ul, ol { |
| 212 | list-style-position: outside; |
| 213 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 214 | div.olist2 ol { |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 215 | list-style-type: lower-alpha; |
| 216 | } |
| 217 | |
| 218 | div.tableblock > table { |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 219 | border: 3px solid #527bbd; |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 220 | } |
| 221 | thead { |
| 222 | font-family: sans-serif; |
| 223 | font-weight: bold; |
| 224 | } |
| 225 | tfoot { |
| 226 | font-weight: bold; |
| 227 | } |
| 228 | |
| 229 | div.hlist { |
| 230 | margin-top: 0.8em; |
| 231 | margin-bottom: 0.8em; |
| 232 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 233 | div.hlist td { |
| 234 | padding-bottom: 5px; |
| 235 | } |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 236 | td.hlist1 { |
| 237 | vertical-align: top; |
| 238 | font-style: italic; |
| 239 | padding-right: 0.8em; |
| 240 | } |
| 241 | td.hlist2 { |
| 242 | vertical-align: top; |
| 243 | } |
| 244 | |
| 245 | @media print { |
| 246 | div#footer-badges { display: none; } |
| 247 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 248 | |
| 249 | div#toctitle { |
| 250 | color: #527bbd; |
| 251 | font-family: sans-serif; |
| 252 | font-size: 1.1em; |
| 253 | font-weight: bold; |
| 254 | margin-top: 1.0em; |
| 255 | margin-bottom: 0.1em; |
| 256 | } |
| 257 | |
| 258 | div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 { |
| 259 | margin-top: 0; |
| 260 | margin-bottom: 0; |
| 261 | } |
| 262 | div.toclevel2 { |
| 263 | margin-left: 2em; |
| 264 | font-size: 0.9em; |
| 265 | } |
| 266 | div.toclevel3 { |
| 267 | margin-left: 4em; |
| 268 | font-size: 0.9em; |
| 269 | } |
| 270 | div.toclevel4 { |
| 271 | margin-left: 6em; |
| 272 | font-size: 0.9em; |
| 273 | } |
| 274 | include1::./stylesheets/xhtml11-manpage.css[] |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 275 | /* Workarounds for IE6's broken and incomplete CSS2. */ |
| 276 | |
| 277 | div.sidebar-content { |
| 278 | background: #ffffee; |
| 279 | border: 1px solid silver; |
| 280 | padding: 0.5em; |
| 281 | } |
| 282 | div.sidebar-title, div.image-title { |
| 283 | font-family: sans-serif; |
| 284 | font-weight: bold; |
| 285 | margin-top: 0.0em; |
| 286 | margin-bottom: 0.5em; |
| 287 | } |
| 288 | |
| 289 | div.listingblock div.content { |
| 290 | border: 1px solid silver; |
| 291 | background: #f4f4f4; |
| 292 | padding: 0.5em; |
| 293 | } |
| 294 | |
| 295 | div.quoteblock-content { |
| 296 | padding-left: 2.0em; |
| 297 | } |
| 298 | |
| 299 | div.exampleblock-content { |
| 300 | border-left: 2px solid silver; |
| 301 | padding-left: 0.5em; |
| 302 | } |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 303 | |
| 304 | /* IE6 sets dynamically generated links as visited. */ |
| 305 | div#toc a:visited { color: blue; } |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 306 | </style> |
| 307 | <title>gittutorial(7)</title> |
| 308 | </head> |
| 309 | <body> |
| 310 | <div id="header"> |
| 311 | <h1> |
| 312 | gittutorial(7) Manual Page |
| 313 | </h1> |
| 314 | <h2>NAME</h2> |
| 315 | <div class="sectionbody"> |
| 316 | <p>gittutorial - |
| 317 | A tutorial introduction to git (for version 1.5.1 or newer) |
| 318 | </p> |
| 319 | </div> |
| 320 | </div> |
| 321 | <h2>SYNOPSIS</h2> |
| 322 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 323 | <div class="para"><p>git *</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 324 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 325 | <h2 id="_description">DESCRIPTION</h2> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 326 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 327 | <div class="para"><p>This tutorial explains how to import a new project into git, make |
| 328 | changes to it, and share changes with other developers.</p></div> |
| 329 | <div class="para"><p>If you are instead primarily interested in using git to fetch a project, |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 330 | for example, to test the latest version, you may prefer to start with |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 331 | the first two chapters of <a href="user-manual.html">The Git User's Manual</a>.</p></div> |
| 332 | <div class="para"><p>First, note that you can get documentation for a command such as |
| 333 | <tt>git log --graph</tt> with:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 334 | <div class="listingblock"> |
| 335 | <div class="content"> |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 336 | <pre><tt>$ man git-log</tt></pre> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 337 | </div></div> |
Junio C Hamano | f66ecee | 2008-11-17 18:25:43 | [diff] [blame] | 338 | <div class="para"><p>or:</p></div> |
| 339 | <div class="listingblock"> |
| 340 | <div class="content"> |
| 341 | <pre><tt>$ git help log</tt></pre> |
| 342 | </div></div> |
| 343 | <div class="para"><p>With the latter, you can use the manual viewer of your choice; see |
| 344 | <a href="git-help.html">git-help(1)</a> for more information.</p></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 345 | <div class="para"><p>It is a good idea to introduce yourself to git with your name and |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 346 | public email address before doing any operation. The easiest |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 347 | way to do so is:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 348 | <div class="listingblock"> |
| 349 | <div class="content"> |
| 350 | <pre><tt>$ git config --global user.name "Your Name Comes Here" |
| 351 | $ git config --global user.email you@yourdomain.example.com</tt></pre> |
| 352 | </div></div> |
| 353 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 354 | <h2 id="_importing_a_new_project">Importing a new project</h2> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 355 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 356 | <div class="para"><p>Assume you have a tarball project.tar.gz with your initial work. You |
| 357 | can place it under git revision control as follows.</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 358 | <div class="listingblock"> |
| 359 | <div class="content"> |
| 360 | <pre><tt>$ tar xzf project.tar.gz |
| 361 | $ cd project |
| 362 | $ git init</tt></pre> |
| 363 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 364 | <div class="para"><p>Git will reply</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 365 | <div class="listingblock"> |
| 366 | <div class="content"> |
| 367 | <pre><tt>Initialized empty Git repository in .git/</tt></pre> |
| 368 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 369 | <div class="para"><p>You've now initialized the working directory--you may notice a new |
| 370 | directory created, named ".git".</p></div> |
| 371 | <div class="para"><p>Next, tell git to take a snapshot of the contents of all files under the |
| 372 | current directory (note the <em>.</em>), with <em>git-add</em>:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 373 | <div class="listingblock"> |
| 374 | <div class="content"> |
| 375 | <pre><tt>$ git add .</tt></pre> |
| 376 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 377 | <div class="para"><p>This snapshot is now stored in a temporary staging area which git calls |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 378 | the "index". You can permanently store the contents of the index in the |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 379 | repository with <em>git-commit</em>:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 380 | <div class="listingblock"> |
| 381 | <div class="content"> |
| 382 | <pre><tt>$ git commit</tt></pre> |
| 383 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 384 | <div class="para"><p>This will prompt you for a commit message. You've now stored the first |
| 385 | version of your project in git.</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 386 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 387 | <h2 id="_making_changes">Making changes</h2> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 388 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 389 | <div class="para"><p>Modify some files, then add their updated contents to the index:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 390 | <div class="listingblock"> |
| 391 | <div class="content"> |
| 392 | <pre><tt>$ git add file1 file2 file3</tt></pre> |
| 393 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 394 | <div class="para"><p>You are now ready to commit. You can see what is about to be committed |
| 395 | using <em>git-diff</em> with the --cached option:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 396 | <div class="listingblock"> |
| 397 | <div class="content"> |
| 398 | <pre><tt>$ git diff --cached</tt></pre> |
| 399 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 400 | <div class="para"><p>(Without --cached, <em>git-diff</em> will show you any changes that |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 401 | you've made but not yet added to the index.) You can also get a brief |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 402 | summary of the situation with <em>git-status</em>:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 403 | <div class="listingblock"> |
| 404 | <div class="content"> |
| 405 | <pre><tt>$ git status |
| 406 | # On branch master |
| 407 | # Changes to be committed: |
| 408 | # (use "git reset HEAD <file>..." to unstage) |
| 409 | # |
| 410 | # modified: file1 |
| 411 | # modified: file2 |
| 412 | # modified: file3 |
| 413 | #</tt></pre> |
| 414 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 415 | <div class="para"><p>If you need to make any further adjustments, do so now, and then add any |
| 416 | newly modified content to the index. Finally, commit your changes with:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 417 | <div class="listingblock"> |
| 418 | <div class="content"> |
| 419 | <pre><tt>$ git commit</tt></pre> |
| 420 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 421 | <div class="para"><p>This will again prompt you for a message describing the change, and then |
| 422 | record a new version of the project.</p></div> |
| 423 | <div class="para"><p>Alternatively, instead of running <em>git-add</em> beforehand, you can use</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 424 | <div class="listingblock"> |
| 425 | <div class="content"> |
| 426 | <pre><tt>$ git commit -a</tt></pre> |
| 427 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 428 | <div class="para"><p>which will automatically notice any modified (but not new) files, add |
| 429 | them to the index, and commit, all in one step.</p></div> |
| 430 | <div class="para"><p>A note on commit messages: Though not required, it's a good idea to |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 431 | begin the commit message with a single short (less than 50 character) |
| 432 | line summarizing the change, followed by a blank line and then a more |
| 433 | thorough description. Tools that turn commits into email, for |
| 434 | example, use the first line on the Subject: line and the rest of the |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 435 | commit in the body.</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 436 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 437 | <h2 id="_git_tracks_content_not_files">Git tracks content not files</h2> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 438 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 439 | <div class="para"><p>Many revision control systems provide an <tt>add</tt> command that tells the |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 440 | system to start tracking changes to a new file. Git's <tt>add</tt> command |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 441 | does something simpler and more powerful: <em>git-add</em> is used both for new |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 442 | and newly modified files, and in both cases it takes a snapshot of the |
| 443 | given files and stages that content in the index, ready for inclusion in |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 444 | the next commit.</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 445 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 446 | <h2 id="_viewing_project_history">Viewing project history</h2> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 447 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 448 | <div class="para"><p>At any point you can view the history of your changes using</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 449 | <div class="listingblock"> |
| 450 | <div class="content"> |
| 451 | <pre><tt>$ git log</tt></pre> |
| 452 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 453 | <div class="para"><p>If you also want to see complete diffs at each step, use</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 454 | <div class="listingblock"> |
| 455 | <div class="content"> |
| 456 | <pre><tt>$ git log -p</tt></pre> |
| 457 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 458 | <div class="para"><p>Often the overview of the change is useful to get a feel of |
| 459 | each step</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 460 | <div class="listingblock"> |
| 461 | <div class="content"> |
| 462 | <pre><tt>$ git log --stat --summary</tt></pre> |
| 463 | </div></div> |
| 464 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 465 | <h2 id="_managing_branches">Managing branches</h2> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 466 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 467 | <div class="para"><p>A single git repository can maintain multiple branches of |
| 468 | development. To create a new branch named "experimental", use</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 469 | <div class="listingblock"> |
| 470 | <div class="content"> |
| 471 | <pre><tt>$ git branch experimental</tt></pre> |
| 472 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 473 | <div class="para"><p>If you now run</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 474 | <div class="listingblock"> |
| 475 | <div class="content"> |
| 476 | <pre><tt>$ git branch</tt></pre> |
| 477 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 478 | <div class="para"><p>you'll get a list of all existing branches:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 479 | <div class="listingblock"> |
| 480 | <div class="content"> |
| 481 | <pre><tt> experimental |
| 482 | * master</tt></pre> |
| 483 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 484 | <div class="para"><p>The "experimental" branch is the one you just created, and the |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 485 | "master" branch is a default branch that was created for you |
| 486 | automatically. The asterisk marks the branch you are currently on; |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 487 | type</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 488 | <div class="listingblock"> |
| 489 | <div class="content"> |
| 490 | <pre><tt>$ git checkout experimental</tt></pre> |
| 491 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 492 | <div class="para"><p>to switch to the experimental branch. Now edit a file, commit the |
| 493 | change, and switch back to the master branch:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 494 | <div class="listingblock"> |
| 495 | <div class="content"> |
| 496 | <pre><tt>(edit file) |
| 497 | $ git commit -a |
| 498 | $ git checkout master</tt></pre> |
| 499 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 500 | <div class="para"><p>Check that the change you made is no longer visible, since it was |
| 501 | made on the experimental branch and you're back on the master branch.</p></div> |
| 502 | <div class="para"><p>You can make a different change on the master branch:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 503 | <div class="listingblock"> |
| 504 | <div class="content"> |
| 505 | <pre><tt>(edit file) |
| 506 | $ git commit -a</tt></pre> |
| 507 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 508 | <div class="para"><p>at this point the two branches have diverged, with different changes |
| 509 | made in each. To merge the changes made in experimental into master, run</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 510 | <div class="listingblock"> |
| 511 | <div class="content"> |
| 512 | <pre><tt>$ git merge experimental</tt></pre> |
| 513 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 514 | <div class="para"><p>If the changes don't conflict, you're done. If there are conflicts, |
| 515 | markers will be left in the problematic files showing the conflict;</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 516 | <div class="listingblock"> |
| 517 | <div class="content"> |
| 518 | <pre><tt>$ git diff</tt></pre> |
| 519 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 520 | <div class="para"><p>will show this. Once you've edited the files to resolve the |
| 521 | conflicts,</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 522 | <div class="listingblock"> |
| 523 | <div class="content"> |
| 524 | <pre><tt>$ git commit -a</tt></pre> |
| 525 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 526 | <div class="para"><p>will commit the result of the merge. Finally,</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 527 | <div class="listingblock"> |
| 528 | <div class="content"> |
| 529 | <pre><tt>$ gitk</tt></pre> |
| 530 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 531 | <div class="para"><p>will show a nice graphical representation of the resulting history.</p></div> |
| 532 | <div class="para"><p>At this point you could delete the experimental branch with</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 533 | <div class="listingblock"> |
| 534 | <div class="content"> |
| 535 | <pre><tt>$ git branch -d experimental</tt></pre> |
| 536 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 537 | <div class="para"><p>This command ensures that the changes in the experimental branch are |
| 538 | already in the current branch.</p></div> |
| 539 | <div class="para"><p>If you develop on a branch crazy-idea, then regret it, you can always |
| 540 | delete the branch with</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 541 | <div class="listingblock"> |
| 542 | <div class="content"> |
| 543 | <pre><tt>$ git branch -D crazy-idea</tt></pre> |
| 544 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 545 | <div class="para"><p>Branches are cheap and easy, so this is a good way to try something |
| 546 | out.</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 547 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 548 | <h2 id="_using_git_for_collaboration">Using git for collaboration</h2> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 549 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 550 | <div class="para"><p>Suppose that Alice has started a new project with a git repository in |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 551 | /home/alice/project, and that Bob, who has a home directory on the |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 552 | same machine, wants to contribute.</p></div> |
| 553 | <div class="para"><p>Bob begins with:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 554 | <div class="listingblock"> |
| 555 | <div class="content"> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 556 | <pre><tt>bob$ git clone /home/alice/project myrepo</tt></pre> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 557 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 558 | <div class="para"><p>This creates a new directory "myrepo" containing a clone of Alice's |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 559 | repository. The clone is on an equal footing with the original |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 560 | project, possessing its own copy of the original project's history.</p></div> |
| 561 | <div class="para"><p>Bob then makes some changes and commits them:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 562 | <div class="listingblock"> |
| 563 | <div class="content"> |
| 564 | <pre><tt>(edit files) |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 565 | bob$ git commit -a |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 566 | (repeat as necessary)</tt></pre> |
| 567 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 568 | <div class="para"><p>When he's ready, he tells Alice to pull changes from the repository |
| 569 | at /home/bob/myrepo. She does this with:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 570 | <div class="listingblock"> |
| 571 | <div class="content"> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 572 | <pre><tt>alice$ cd /home/alice/project |
| 573 | alice$ git pull /home/bob/myrepo master</tt></pre> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 574 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 575 | <div class="para"><p>This merges the changes from Bob's "master" branch into Alice's |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 576 | current branch. If Alice has made her own changes in the meantime, |
| 577 | then she may need to manually fix any conflicts. (Note that the |
| 578 | "master" argument in the above command is actually unnecessary, as it |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 579 | is the default.)</p></div> |
| 580 | <div class="para"><p>The "pull" command thus performs two operations: it fetches changes |
| 581 | from a remote branch, then merges them into the current branch.</p></div> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 582 | <div class="para"><p>Note that in general, Alice would want her local changes committed before |
| 583 | initiating this "pull". If Bob's work conflicts with what Alice did since |
| 584 | their histories forked, Alice will use her working tree and the index to |
| 585 | resolve conflicts, and existing local changes will interfere with the |
| 586 | conflict resolution process (git will still perform the fetch but will |
| 587 | refuse to merge --- Alice will have to get rid of her local changes in |
| 588 | some way and pull again when this happens).</p></div> |
| 589 | <div class="para"><p>Alice can peek at what Bob did without merging first, using the "fetch" |
| 590 | command; this allows Alice to inspect what Bob did, using a special |
| 591 | symbol "FETCH_HEAD", in order to determine if he has anything worth |
| 592 | pulling, like this:</p></div> |
| 593 | <div class="listingblock"> |
| 594 | <div class="content"> |
| 595 | <pre><tt>alice$ git fetch /home/bob/myrepo master |
Junio C Hamano | a387df3 | 2008-08-29 08:56:58 | [diff] [blame] | 596 | alice$ git log -p HEAD..FETCH_HEAD</tt></pre> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 597 | </div></div> |
Junio C Hamano | a387df3 | 2008-08-29 08:56:58 | [diff] [blame] | 598 | <div class="para"><p>This operation is safe even if Alice has uncommitted local changes. |
| 599 | The range notation HEAD..FETCH_HEAD" means "show everything that is reachable |
| 600 | from the FETCH_HEAD but exclude anything that is reachable from HEAD. |
| 601 | Alice already knows everything that leads to her current state (HEAD), |
| 602 | and reviewing what Bob has in his state (FETCH_HEAD) that she has not |
| 603 | seen with this command</p></div> |
| 604 | <div class="para"><p>If Alice wants to visualize what Bob did since their histories forked |
| 605 | she can issue the following command:</p></div> |
| 606 | <div class="listingblock"> |
| 607 | <div class="content"> |
| 608 | <pre><tt>$ gitk HEAD..FETCH_HEAD</tt></pre> |
| 609 | </div></div> |
| 610 | <div class="para"><p>This uses the same two-dot range notation we saw earlier with <em>git log</em>.</p></div> |
| 611 | <div class="para"><p>Alice may want to view what both of them did since they forked. |
| 612 | She can use three-dot form instead of the two-dot form:</p></div> |
| 613 | <div class="listingblock"> |
| 614 | <div class="content"> |
| 615 | <pre><tt>$ gitk HEAD...FETCH_HEAD</tt></pre> |
| 616 | </div></div> |
| 617 | <div class="para"><p>This means "show everything that is reachable from either one, but |
| 618 | exclude anything that is reachable from both of them".</p></div> |
| 619 | <div class="para"><p>Please note that these range notation can be used with both gitk |
| 620 | and "git log".</p></div> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 621 | <div class="para"><p>After inspecting what Bob did, if there is nothing urgent, Alice may |
| 622 | decide to continue working without pulling from Bob. If Bob's history |
| 623 | does have something Alice would immediately need, Alice may choose to |
| 624 | stash her work-in-progress first, do a "pull", and then finally unstash |
| 625 | her work-in-progress on top of the resulting history.</p></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 626 | <div class="para"><p>When you are working in a small closely knit group, it is not |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 627 | unusual to interact with the same repository over and over |
| 628 | again. By defining <em>remote</em> repository shorthand, you can make |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 629 | it easier:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 630 | <div class="listingblock"> |
| 631 | <div class="content"> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 632 | <pre><tt>alice$ git remote add bob /home/bob/myrepo</tt></pre> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 633 | </div></div> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 634 | <div class="para"><p>With this, Alice can perform the first part of the "pull" operation alone using the |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 635 | <em>git-fetch</em> command without merging them with her own branch, |
| 636 | using:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 637 | <div class="listingblock"> |
| 638 | <div class="content"> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 639 | <pre><tt>alice$ git fetch bob</tt></pre> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 640 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 641 | <div class="para"><p>Unlike the longhand form, when Alice fetches from Bob using a |
| 642 | remote repository shorthand set up with <em>git-remote</em>, what was |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 643 | fetched is stored in a remote tracking branch, in this case |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 644 | <tt>bob/master</tt>. So after this:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 645 | <div class="listingblock"> |
| 646 | <div class="content"> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 647 | <pre><tt>alice$ git log -p master..bob/master</tt></pre> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 648 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 649 | <div class="para"><p>shows a list of all the changes that Bob made since he branched from |
| 650 | Alice's master branch.</p></div> |
| 651 | <div class="para"><p>After examining those changes, Alice |
| 652 | could merge the changes into her master branch:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 653 | <div class="listingblock"> |
| 654 | <div class="content"> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 655 | <pre><tt>alice$ git merge bob/master</tt></pre> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 656 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 657 | <div class="para"><p>This <tt>merge</tt> can also be done by <em>pulling from her own remote |
| 658 | tracking branch</em>, like this:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 659 | <div class="listingblock"> |
| 660 | <div class="content"> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 661 | <pre><tt>alice$ git pull . remotes/bob/master</tt></pre> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 662 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 663 | <div class="para"><p>Note that git pull always merges into the current branch, |
| 664 | regardless of what else is given on the command line.</p></div> |
| 665 | <div class="para"><p>Later, Bob can update his repo with Alice's latest changes using</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 666 | <div class="listingblock"> |
| 667 | <div class="content"> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 668 | <pre><tt>bob$ git pull</tt></pre> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 669 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 670 | <div class="para"><p>Note that he doesn't need to give the path to Alice's repository; |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 671 | when Bob cloned Alice's repository, git stored the location of her |
| 672 | repository in the repository configuration, and that location is |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 673 | used for pulls:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 674 | <div class="listingblock"> |
| 675 | <div class="content"> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 676 | <pre><tt>bob$ git config --get remote.origin.url |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 677 | /home/alice/project</tt></pre> |
| 678 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 679 | <div class="para"><p>(The complete configuration created by <em>git-clone</em> is visible using |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 680 | <tt>git config -l</tt>, and the <a href="git-config.html">git-config(1)</a> man page |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 681 | explains the meaning of each option.)</p></div> |
| 682 | <div class="para"><p>Git also keeps a pristine copy of Alice's master branch under the |
| 683 | name "origin/master":</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 684 | <div class="listingblock"> |
| 685 | <div class="content"> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 686 | <pre><tt>bob$ git branch -r |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 687 | origin/master</tt></pre> |
| 688 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 689 | <div class="para"><p>If Bob later decides to work from a different host, he can still |
| 690 | perform clones and pulls using the ssh protocol:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 691 | <div class="listingblock"> |
| 692 | <div class="content"> |
Junio C Hamano | 38ddcce | 2008-07-15 15:49:03 | [diff] [blame] | 693 | <pre><tt>bob$ git clone alice.org:/home/alice/project myrepo</tt></pre> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 694 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 695 | <div class="para"><p>Alternatively, git has a native protocol, or can use rsync or http; |
| 696 | see <a href="git-pull.html">git-pull(1)</a> for details.</p></div> |
| 697 | <div class="para"><p>Git can also be used in a CVS-like mode, with a central repository |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 698 | that various users push changes to; see <a href="git-push.html">git-push(1)</a> and |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 699 | <a href="gitcvs-migration.html">gitcvs-migration(7)</a>.</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 700 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 701 | <h2 id="_exploring_history">Exploring history</h2> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 702 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 703 | <div class="para"><p>Git history is represented as a series of interrelated commits. We |
| 704 | have already seen that the <em>git-log</em> command can list those commits. |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 705 | Note that first line of each git log entry also gives a name for the |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 706 | commit:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 707 | <div class="listingblock"> |
| 708 | <div class="content"> |
| 709 | <pre><tt>$ git log |
| 710 | commit c82a22c39cbc32576f64f5c6b3f24b99ea8149c7 |
| 711 | Author: Junio C Hamano <junkio@cox.net> |
| 712 | Date: Tue May 16 17:18:22 2006 -0700 |
| 713 | |
| 714 | merge-base: Clarify the comments on post processing.</tt></pre> |
| 715 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 716 | <div class="para"><p>We can give this name to <em>git-show</em> to see the details about this |
| 717 | commit.</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 718 | <div class="listingblock"> |
| 719 | <div class="content"> |
| 720 | <pre><tt>$ git show c82a22c39cbc32576f64f5c6b3f24b99ea8149c7</tt></pre> |
| 721 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 722 | <div class="para"><p>But there are other ways to refer to commits. You can use any initial |
| 723 | part of the name that is long enough to uniquely identify the commit:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 724 | <div class="listingblock"> |
| 725 | <div class="content"> |
| 726 | <pre><tt>$ git show c82a22c39c # the first few characters of the name are |
| 727 | # usually enough |
| 728 | $ git show HEAD # the tip of the current branch |
| 729 | $ git show experimental # the tip of the "experimental" branch</tt></pre> |
| 730 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 731 | <div class="para"><p>Every commit usually has one "parent" commit |
| 732 | which points to the previous state of the project:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 733 | <div class="listingblock"> |
| 734 | <div class="content"> |
| 735 | <pre><tt>$ git show HEAD^ # to see the parent of HEAD |
| 736 | $ git show HEAD^^ # to see the grandparent of HEAD |
| 737 | $ git show HEAD~4 # to see the great-great grandparent of HEAD</tt></pre> |
| 738 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 739 | <div class="para"><p>Note that merge commits may have more than one parent:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 740 | <div class="listingblock"> |
| 741 | <div class="content"> |
| 742 | <pre><tt>$ git show HEAD^1 # show the first parent of HEAD (same as HEAD^) |
| 743 | $ git show HEAD^2 # show the second parent of HEAD</tt></pre> |
| 744 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 745 | <div class="para"><p>You can also give commits names of your own; after running</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 746 | <div class="listingblock"> |
| 747 | <div class="content"> |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 748 | <pre><tt>$ git tag v2.5 1b2e1d63ff</tt></pre> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 749 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 750 | <div class="para"><p>you can refer to 1b2e1d63ff by the name "v2.5". If you intend to |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 751 | share this name with other people (for example, to identify a release |
| 752 | version), you should create a "tag" object, and perhaps sign it; see |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 753 | <a href="git-tag.html">git-tag(1)</a> for details.</p></div> |
| 754 | <div class="para"><p>Any git command that needs to know a commit can take any of these |
| 755 | names. For example:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 756 | <div class="listingblock"> |
| 757 | <div class="content"> |
| 758 | <pre><tt>$ git diff v2.5 HEAD # compare the current HEAD to v2.5 |
| 759 | $ git branch stable v2.5 # start a new branch named "stable" based |
| 760 | # at v2.5 |
| 761 | $ git reset --hard HEAD^ # reset your current branch and working |
| 762 | # directory to its state at HEAD^</tt></pre> |
| 763 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 764 | <div class="para"><p>Be careful with that last command: in addition to losing any changes |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 765 | in the working directory, it will also remove all later commits from |
| 766 | this branch. If this branch is the only branch containing those |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 767 | commits, they will be lost. Also, don't use <em>git-reset</em> on a |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 768 | publicly-visible branch that other developers pull from, as it will |
| 769 | force needless merges on other developers to clean up the history. |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 770 | If you need to undo changes that you have pushed, use <em>git-revert</em> |
| 771 | instead.</p></div> |
| 772 | <div class="para"><p>The <em>git-grep</em> command can search for strings in any version of your |
| 773 | project, so</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 774 | <div class="listingblock"> |
| 775 | <div class="content"> |
| 776 | <pre><tt>$ git grep "hello" v2.5</tt></pre> |
| 777 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 778 | <div class="para"><p>searches for all occurrences of "hello" in v2.5.</p></div> |
| 779 | <div class="para"><p>If you leave out the commit name, <em>git-grep</em> will search any of the |
| 780 | files it manages in your current directory. So</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 781 | <div class="listingblock"> |
| 782 | <div class="content"> |
| 783 | <pre><tt>$ git grep "hello"</tt></pre> |
| 784 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 785 | <div class="para"><p>is a quick way to search just the files that are tracked by git.</p></div> |
| 786 | <div class="para"><p>Many git commands also take sets of commits, which can be specified |
| 787 | in a number of ways. Here are some examples with <em>git-log</em>:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 788 | <div class="listingblock"> |
| 789 | <div class="content"> |
| 790 | <pre><tt>$ git log v2.5..v2.6 # commits between v2.5 and v2.6 |
| 791 | $ git log v2.5.. # commits since v2.5 |
| 792 | $ git log --since="2 weeks ago" # commits from the last 2 weeks |
| 793 | $ git log v2.5.. Makefile # commits since v2.5 which modify |
| 794 | # Makefile</tt></pre> |
| 795 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 796 | <div class="para"><p>You can also give <em>git-log</em> a "range" of commits where the first is not |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 797 | necessarily an ancestor of the second; for example, if the tips of |
| 798 | the branches "stable-release" and "master" diverged from a common |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 799 | commit some time ago, then</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 800 | <div class="listingblock"> |
| 801 | <div class="content"> |
| 802 | <pre><tt>$ git log stable..experimental</tt></pre> |
| 803 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 804 | <div class="para"><p>will list commits made in the experimental branch but not in the |
| 805 | stable branch, while</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 806 | <div class="listingblock"> |
| 807 | <div class="content"> |
| 808 | <pre><tt>$ git log experimental..stable</tt></pre> |
| 809 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 810 | <div class="para"><p>will show the list of commits made on the stable branch but not |
| 811 | the experimental branch.</p></div> |
| 812 | <div class="para"><p>The <em>git-log</em> command has a weakness: it must present commits in a |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 813 | list. When the history has lines of development that diverged and |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 814 | then merged back together, the order in which <em>git-log</em> presents |
| 815 | those commits is meaningless.</p></div> |
| 816 | <div class="para"><p>Most projects with multiple contributors (such as the linux kernel, |
| 817 | or git itself) have frequent merges, and <em>gitk</em> does a better job of |
| 818 | visualizing their history. For example,</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 819 | <div class="listingblock"> |
| 820 | <div class="content"> |
| 821 | <pre><tt>$ gitk --since="2 weeks ago" drivers/</tt></pre> |
| 822 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 823 | <div class="para"><p>allows you to browse any commits from the last 2 weeks of commits |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 824 | that modified files under the "drivers" directory. (Note: you can |
| 825 | adjust gitk's fonts by holding down the control key while pressing |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 826 | "-" or "+".)</p></div> |
| 827 | <div class="para"><p>Finally, most commands that take filenames will optionally allow you |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 828 | to precede any filename by a commit, to specify a particular version |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 829 | of the file:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 830 | <div class="listingblock"> |
| 831 | <div class="content"> |
| 832 | <pre><tt>$ git diff v2.5:Makefile HEAD:Makefile.in</tt></pre> |
| 833 | </div></div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 834 | <div class="para"><p>You can also use <em>git-show</em> to see any such file:</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 835 | <div class="listingblock"> |
| 836 | <div class="content"> |
| 837 | <pre><tt>$ git show v2.5:Makefile</tt></pre> |
| 838 | </div></div> |
| 839 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 840 | <h2 id="_next_steps">Next Steps</h2> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 841 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 842 | <div class="para"><p>This tutorial should be enough to perform basic distributed revision |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 843 | control for your projects. However, to fully understand the depth |
| 844 | and power of git you need to understand two simple ideas on which it |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 845 | is based:</p></div> |
| 846 | <div class="ilist"><ul> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 847 | <li> |
| 848 | <p> |
| 849 | The object database is the rather elegant system used to |
| 850 | store the history of your project--files, directories, and |
| 851 | commits. |
| 852 | </p> |
| 853 | </li> |
| 854 | <li> |
| 855 | <p> |
| 856 | The index file is a cache of the state of a directory tree, |
| 857 | used to create commits, check out working directories, and |
| 858 | hold the various trees involved in a merge. |
| 859 | </p> |
| 860 | </li> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 861 | </ul></div> |
| 862 | <div class="para"><p>Part two of this tutorial explains the object |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 863 | database, the index file, and a few other odds and ends that you'll |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 864 | need to make the most of git. You can find it at <a href="gittutorial-2.html">gittutorial-2(7)</a>.</p></div> |
| 865 | <div class="para"><p>If you don't want to continue with that right away, a few other |
| 866 | digressions that may be interesting at this point are:</p></div> |
| 867 | <div class="ilist"><ul> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 868 | <li> |
| 869 | <p> |
| 870 | <a href="git-format-patch.html">git-format-patch(1)</a>, <a href="git-am.html">git-am(1)</a>: These convert |
| 871 | series of git commits into emailed patches, and vice versa, |
| 872 | useful for projects such as the linux kernel which rely heavily |
| 873 | on emailed patches. |
| 874 | </p> |
| 875 | </li> |
| 876 | <li> |
| 877 | <p> |
| 878 | <a href="git-bisect.html">git-bisect(1)</a>: When there is a regression in your |
| 879 | project, one way to track down the bug is by searching through |
| 880 | the history to find the exact commit that's to blame. Git bisect |
| 881 | can help you perform a binary search for that commit. It is |
| 882 | smart enough to perform a close-to-optimal search even in the |
| 883 | case of complex non-linear history with lots of merged branches. |
| 884 | </p> |
| 885 | </li> |
| 886 | <li> |
| 887 | <p> |
| 888 | <a href="everyday.html">Everyday GIT with 20 Commands Or So</a> |
| 889 | </p> |
| 890 | </li> |
| 891 | <li> |
| 892 | <p> |
Junio C Hamano | fce7c7e | 2008-07-02 03:06:38 | [diff] [blame] | 893 | <a href="gitcvs-migration.html">gitcvs-migration(7)</a>: Git for CVS users. |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 894 | </p> |
| 895 | </li> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 896 | </ul></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 897 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 898 | <h2 id="_see_also">SEE ALSO</h2> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 899 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 900 | <div class="para"><p><a href="gittutorial-2.html">gittutorial-2(7)</a>, |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 901 | <a href="gitcvs-migration.html">gitcvs-migration(7)</a>, |
Junio C Hamano | 9e1793f | 2008-06-02 07:31:16 | [diff] [blame] | 902 | <a href="gitcore-tutorial.html">gitcore-tutorial(7)</a>, |
| 903 | <a href="gitglossary.html">gitglossary(7)</a>, |
Junio C Hamano | f66ecee | 2008-11-17 18:25:43 | [diff] [blame] | 904 | <a href="git-help.html">git-help(1)</a>, |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 905 | <a href="everyday.html">Everyday git</a>, |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 906 | <a href="user-manual.html">The Git User's Manual</a></p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 907 | </div> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 908 | <h2 id="_git">GIT</h2> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 909 | <div class="sectionbody"> |
Junio C Hamano | ba4b928 | 2008-07-06 05:20:31 | [diff] [blame] | 910 | <div class="para"><p>Part of the <a href="git.html">git(1)</a> suite.</p></div> |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 911 | </div> |
| 912 | <div id="footer"> |
| 913 | <div id="footer-text"> |
Junio C Hamano | ec87f52 | 2008-12-10 08:35:25 | [diff] [blame] | 914 | Last updated 2008-12-10 08:33:33 UTC |
Junio C Hamano | dfccbb0 | 2008-05-26 01:16:14 | [diff] [blame] | 915 | </div> |
| 916 | </div> |
| 917 | </body> |
| 918 | </html> |