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