/usr/share/doc/gitmagic/html/ch02.html is in gitmagic 20140125-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 25 March 2009), see www.w3.org">
<meta http-equiv="Content-Type" content=
"text/html; charset=utf-8">
<title>Git Magic - Chapter 2. Basic Tricks</title>
<link rel="stylesheet" type="text/css" href="default.css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="Git Magic">
<link rel="up" href="index.html" title="Git Magic">
<link rel="prev" href="ch01.html" title=
"Chapter 1. Introduction">
<link rel="next" href="ch03.html" title=
"Chapter 3. Cloning Around">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084"
alink="#0000FF">
<div class="toc">
<ul class="toc">
<li><b>Git Magic</b></li>
<li>
<span class="preface"><a href=
"index.html">Preface</a></span>
<ul>
<li><span class="section"><a href=
"index.html#thanks">Thanks!</a></span></li>
<li><span class="section"><a href=
"index.html#license">License</a></span></li>
</ul>
</li>
<li>
<span class="chapter"><a href="ch01.html">1.
Introduction</a></span>
<ul>
<li><span class="section"><a href=
"ch01.html#work_is_play">Work is Play</a></span></li>
<li><span class="section"><a href=
"ch01.html#version_control">Version
Control</a></span></li>
<li><span class="section"><a href=
"ch01.html#distributed_control">Distributed
Control</a></span></li>
<li><span class="section"><a href=
"ch01.html#a_silly_superstition">A Silly
Superstition</a></span></li>
<li><span class="section"><a href=
"ch01.html#merge_conflicts">Merge
Conflicts</a></span></li>
</ul>
</li>
<li>
<span class="chapter"><a href="ch02.html">2. Basic
Tricks</a></span>
<ul>
<li><span class="section"><a href=
"ch02.html#saving_state">Saving State</a></span></li>
<li><span class="section"><a href=
"ch02.html#add_delete_rename">Add, Delete,
Rename</a></span></li>
<li><span class="section"><a href=
"ch02.html#advanced_undo_redo">Advanced
Undo/Redo</a></span></li>
<li><span class="section"><a href=
"ch02.html#reverting">Reverting</a></span></li>
<li><span class="section"><a href=
"ch02.html#changelog_generation">Changelog
Generation</a></span></li>
<li><span class="section"><a href=
"ch02.html#downloading_files">Downloading
Files</a></span></li>
<li><span class="section"><a href=
"ch02.html#the_bleeding_edge">The Bleeding
Edge</a></span></li>
<li><span class="section"><a href=
"ch02.html#instant_publishing">Instant
Publishing</a></span></li>
<li><span class="section"><a href=
"ch02.html#what_have_i_done">What Have I
Done?</a></span></li>
<li><span class="section"><a href=
"ch02.html#exercise">Exercise</a></span></li>
</ul>
</li>
<li>
<span class="chapter"><a href="ch03.html">3. Cloning
Around</a></span>
<ul>
<li><span class="section"><a href=
"ch03.html#sync_computers">Sync
Computers</a></span></li>
<li><span class="section"><a href=
"ch03.html#classic_source_control">Classic Source
Control</a></span></li>
<li><span class="section"><a href=
"ch03.html#secret_source">Secret Source</a></span></li>
<li><span class="section"><a href=
"ch03.html#bare_repositories">Bare
repositories</a></span></li>
<li><span class="section"><a href=
"ch03.html#push_versus_pull">Push versus
pull</a></span></li>
<li><span class="section"><a href=
"ch03.html#forking_a_project">Forking a
Project</a></span></li>
<li><span class="section"><a href=
"ch03.html#ultimate_backups">Ultimate
Backups</a></span></li>
<li><span class="section"><a href=
"ch03.html#light_speed_multitask">Light-Speed
Multitask</a></span></li>
<li><span class="section"><a href=
"ch03.html#guerilla_version_control">Guerilla Version
Control</a></span></li>
<li><span class="section"><a href=
"ch03.html#mercurial">Mercurial</a></span></li>
<li><span class="section"><a href=
"ch03.html#bazaar">Bazaar</a></span></li>
<li><span class="section"><a href=
"ch03.html#why_i_use_git">Why I use Git</a></span></li>
</ul>
</li>
<li>
<span class="chapter"><a href="ch04.html">4. Branch
Wizardry</a></span>
<ul>
<li><span class="section"><a href=
"ch04.html#the_boss_key">The Boss Key</a></span></li>
<li><span class="section"><a href=
"ch04.html#dirty_work">Dirty Work</a></span></li>
<li><span class="section"><a href=
"ch04.html#quick_fixes">Quick Fixes</a></span></li>
<li><span class="section"><a href=
"ch04.html#merging">Merging</a></span></li>
<li><span class="section"><a href=
"ch04.html#uninterrupted_workflow">Uninterrupted
Workflow</a></span></li>
<li><span class="section"><a href=
"ch04.html#reorganizing_a_medley">Reorganizing a
Medley</a></span></li>
<li><span class="section"><a href=
"ch04.html#managing_branches">Managing
Branches</a></span></li>
<li><span class="section"><a href=
"ch04.html#temporary_branches">Temporary
Branches</a></span></li>
<li><span class="section"><a href=
"ch04.html#work_how_you_want">Work How You
Want</a></span></li>
</ul>
</li>
<li>
<span class="chapter"><a href="ch05.html">5. Lessons of
History</a></span>
<ul>
<li><span class="section"><a href=
"ch05.html#i_stand_corrected">I Stand
Corrected</a></span></li>
<li><span class="section"><a href=
"ch05.html#and_then_some">… And Then
Some</a></span></li>
<li><span class="section"><a href=
"ch05.html#local_changes_last">Local Changes
Last</a></span></li>
<li><span class="section"><a href=
"ch05.html#rewriting_history">Rewriting
History</a></span></li>
<li><span class="section"><a href=
"ch05.html#making_history">Making
History</a></span></li>
<li><span class="section"><a href=
"ch05.html#where_did_it_all_go_wrong">Where Did It All
Go Wrong?</a></span></li>
<li><span class="section"><a href=
"ch05.html#who_made_it_all_go_wrong">Who Made It All Go
Wrong?</a></span></li>
<li><span class="section"><a href=
"ch05.html#personal_experience">Personal
Experience</a></span></li>
</ul>
</li>
<li>
<span class="chapter"><a href="ch06.html">6. Multiplayer
Git</a></span>
<ul>
<li><span class="section"><a href=
"ch06.html#who_am_i">Who Am I?</a></span></li>
<li><span class="section"><a href=
"ch06.html#git_over_ssh_http">Git Over SSH,
HTTP</a></span></li>
<li><span class="section"><a href=
"ch06.html#git_over_anything">Git Over
Anything</a></span></li>
<li><span class="section"><a href=
"ch06.html#patches_the_global_currency">Patches: The
Global Currency</a></span></li>
<li><span class="section"><a href=
"ch06.html#sorry_we_8217_ve_moved">Sorry, We’ve
Moved</a></span></li>
<li><span class="section"><a href=
"ch06.html#remote_branches">Remote
Branches</a></span></li>
<li><span class="section"><a href=
"ch06.html#multiple_remotes">Multiple
Remotes</a></span></li>
<li><span class="section"><a href=
"ch06.html#my_preferences">My
Preferences</a></span></li>
</ul>
</li>
<li>
<span class="chapter"><a href="ch07.html">7. Git
Grandmastery</a></span>
<ul>
<li><span class="section"><a href=
"ch07.html#source_releases">Source
Releases</a></span></li>
<li><span class="section"><a href=
"ch07.html#commit_what_changed">Commit What
Changed</a></span></li>
<li><span class="section"><a href=
"ch07.html#my_commit_is_too_big">My Commit Is Too
Big!</a></span></li>
<li><span class="section"><a href=
"ch07.html#the_index_git_8217_s_staging_area">The
Index: Git’s Staging Area</a></span></li>
<li><span class="section"><a href=
"ch07.html#don_8217_t_lose_your_head">Don’t Lose Your
HEAD</a></span></li>
<li><span class="section"><a href=
"ch07.html#head_hunting">HEAD-hunting</a></span></li>
<li><span class="section"><a href=
"ch07.html#building_on_git">Building On
Git</a></span></li>
<li><span class="section"><a href=
"ch07.html#daring_stunts">Daring Stunts</a></span></li>
<li><span class="section"><a href=
"ch07.html#preventing_bad_commits">Preventing Bad
Commits</a></span></li>
</ul>
</li>
<li>
<span class="chapter"><a href="ch08.html">8. Secrets
Revealed</a></span>
<ul>
<li><span class="section"><a href=
"ch08.html#invisibility">Invisibility</a></span></li>
<li><span class="section"><a href=
"ch08.html#integrity">Integrity</a></span></li>
<li><span class="section"><a href=
"ch08.html#intelligence">Intelligence</a></span></li>
<li><span class="section"><a href=
"ch08.html#indexing">Indexing</a></span></li>
<li><span class="section"><a href=
"ch08.html#git_8217_s_origins">Git’s
Origins</a></span></li>
<li><span class="section"><a href=
"ch08.html#the_object_database">The Object
Database</a></span></li>
<li><span class="section"><a href=
"ch08.html#blobs">Blobs</a></span></li>
<li><span class="section"><a href=
"ch08.html#trees">Trees</a></span></li>
<li><span class="section"><a href=
"ch08.html#commits">Commits</a></span></li>
<li><span class="section"><a href=
"ch08.html#indistinguishable_from_magic">Indistinguishable
From Magic</a></span></li>
</ul>
</li>
<li>
<span class="appendix"><a href="apa.html">A. Git
Shortcomings</a></span>
<ul>
<li><span class="section"><a href=
"apa.html#sha1_weaknesses">SHA1
Weaknesses</a></span></li>
<li><span class="section"><a href=
"apa.html#microsoft_windows">Microsoft
Windows</a></span></li>
<li><span class="section"><a href=
"apa.html#unrelated_files">Unrelated
Files</a></span></li>
<li><span class="section"><a href=
"apa.html#who_8217_s_editing_what">Who’s Editing
What?</a></span></li>
<li><span class="section"><a href=
"apa.html#file_history">File History</a></span></li>
<li><span class="section"><a href=
"apa.html#initial_clone">Initial Clone</a></span></li>
<li><span class="section"><a href=
"apa.html#volatile_projects">Volatile
Projects</a></span></li>
<li><span class="section"><a href=
"apa.html#global_counter">Global
Counter</a></span></li>
<li><span class="section"><a href=
"apa.html#empty_subdirectories">Empty
Subdirectories</a></span></li>
<li><span class="section"><a href=
"apa.html#initial_commit">Initial
Commit</a></span></li>
<li><span class="section"><a href=
"apa.html#interface_quirks">Interface
Quirks</a></span></li>
</ul>
</li>
<li><span class="appendix"><a href="apb.html">B.
Translating This Guide</a></span></li>
</ul>
</div>
<div class="content">
<div class="chapter">
<div class="titlepage">
<div>
<div>
<h1 class="title"><a id="basic_tricks" name=
"basic_tricks"></a>Chapter 2. Basic Tricks</h1>
</div>
</div>
</div>
<p>Rather than diving into a sea of Git commands, use these
elementary examples to get your feet wet. Despite their
simplicity, each of them are useful. Indeed, in my first months
with Git I never ventured beyond the material in this
chapter.</p>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="saving_state" name=
"saving_state"></a>Saving State</h2>
</div>
</div>
</div>
<p>About to attempt something drastic? Before you do, take a
snapshot of all files in the current directory with:</p>
<pre class="literallayout">
$ git init
$ git add .
$ git commit -m "My first backup"
</pre>
<p>Now if your new edits go awry, restore the pristine
version:</p>
<pre class="literallayout">
$ git reset --hard
</pre>
<p>To save the state again:</p>
<pre class="literallayout">
$ git commit -a -m "Another backup"
</pre>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="add_delete_rename" name=
"add_delete_rename"></a>Add, Delete, Rename</h2>
</div>
</div>
</div>
<p>The above only keeps track of the files that were present
when you first ran <span class="strong"><strong>git
add</strong></span>. If you add new files or subdirectories,
you’ll have to tell Git:</p>
<pre class="literallayout">
$ git add readme.txt Documentation
</pre>
<p>Similarly, if you want Git to forget about certain
files:</p>
<pre class="literallayout">
$ git rm kludge.h obsolete.c
$ git rm -r incriminating/evidence/
</pre>
<p>Git deletes these files for you if you haven’t
already.</p>
<p>Renaming a file is the same as removing the old name and
adding the new name. There’s also the shortcut <span class=
"strong"><strong>git mv</strong></span> which has the same
syntax as the <span class="strong"><strong>mv</strong></span>
command. For example:</p>
<pre class="literallayout">
$ git mv bug.c feature.c
</pre>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="advanced_undo_redo" name=
"advanced_undo_redo"></a>Advanced Undo/Redo</h2>
</div>
</div>
</div>
<p>Sometimes you just want to go back and forget about every
change past a certain point because they’re all wrong.
Then:</p>
<pre class="literallayout">
$ git log
</pre>
<p>shows you a list of recent commits, and their SHA1
hashes:</p>
<pre class="screen">
commit 766f9881690d240ba334153047649b8b8f11c664
Author: Bob <bob@example.com>
Date: Tue Mar 14 01:59:26 2000 -0800
Replace printf() with write().
commit 82f5ea346a2e651544956a8653c0f58dc151275c
Author: Alice <alice@example.com>
Date: Thu Jan 1 00:00:00 1970 +0000
Initial commit.
</pre>
<p>The first few characters of the hash are enough to specify
the commit; alternatively, copy and paste the entire hash.
Type:</p>
<pre class="literallayout">
$ git reset --hard 766f
</pre>
<p>to restore the state to a given commit and erase all newer
commits from the record permanently.</p>
<p>Other times you want to hop to an old state briefly. In
this case, type:</p>
<pre class="literallayout">
$ git checkout 82f5
</pre>
<p>This takes you back in time, while preserving newer
commits. However, like time travel in a science-fiction
movie, if you now edit and commit, you will be in an
alternate reality, because your actions are different to what
they were the first time around.</p>
<p>This alternate reality is called a <span class=
"emphasis"><em>branch</em></span>, and <a class="link" href=
"ch04.html#branch">we’ll have more to say about this
later</a>. For now, just remember that</p>
<pre class="literallayout">
$ git checkout master
</pre>
<p>will take you back to the present. Also, to stop Git
complaining, always commit or reset your changes before
running checkout.</p>
<p>To take the computer game analogy again:</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem"><span class=
"strong"><strong><code class="literal">git reset
--hard</code></strong></span>: load an old save and
delete all saved games newer than the one just
loaded.</li>
<li class="listitem"><span class=
"strong"><strong><code class="literal">git
checkout</code></strong></span>: load an old game, but if
you play on, the game state will deviate from the newer
saves you made the first time around. Any saved games you
make now will end up in a separate branch representing
the alternate reality you have entered. <a class="link"
href="ch04.html#branch">We deal with this later</a>.</li>
</ul>
</div>
<p>You can choose only to restore particular files and
subdirectories by appending them after the command:</p>
<pre class="literallayout">
$ git checkout 82f5 some.file another.file
</pre>
<p>Take care, as this form of <span class=
"strong"><strong>checkout</strong></span> can silently
overwrite files. To prevent accidents, commit before running
any checkout command, especially when first learning Git. In
general, whenever you feel unsure about any operation, Git
command or not, first run <span class="strong"><strong>git
commit -a</strong></span>.</p>
<p>Don’t like cutting and pasting hashes? Then use:</p>
<pre class="literallayout">
$ git checkout :/"My first b"
</pre>
<p>to jump to the commit that starts with a given message.
You can also ask for the 5th-last saved state:</p>
<pre class="literallayout">
$ git checkout master~5
</pre>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="reverting" name=
"reverting"></a>Reverting</h2>
</div>
</div>
</div>
<p>In a court of law, events can be stricken from the record.
Likewise, you can pick specific commits to undo.</p>
<pre class="literallayout">
$ git commit -a
$ git revert 1b6d
</pre>
<p>will undo just the commit with the given hash. The revert
is recorded as a new commit, which you can confirm by running
<span class="strong"><strong>git log</strong></span>.</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="changelog_generation" name=
"changelog_generation"></a>Changelog Generation</h2>
</div>
</div>
</div>
<p>Some projects require a <a class="ulink" href=
"http://en.wikipedia.org/wiki/Changelog" target=
"_top">changelog</a>. Generate one by typing:</p>
<pre class="literallayout">
$ git log > ChangeLog
</pre>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="downloading_files" name=
"downloading_files"></a>Downloading Files</h2>
</div>
</div>
</div>
<p>Get a copy of a project managed with Git by typing:</p>
<pre class="literallayout">
$ git clone git://server/path/to/files
</pre>
<p>For example, to get all the files I used to create this
site:</p>
<pre class="literallayout">
$ git clone git://git.or.cz/gitmagic.git
</pre>
<p>We’ll have much to say about the <span class=
"strong"><strong>clone</strong></span> command soon.</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="the_bleeding_edge" name=
"the_bleeding_edge"></a>The Bleeding Edge</h2>
</div>
</div>
</div>
<p>If you’ve already downloaded a copy of a project using
<span class="strong"><strong>git clone</strong></span>, you
can upgrade to the latest version with:</p>
<pre class="literallayout">
$ git pull
</pre>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="instant_publishing" name=
"instant_publishing"></a>Instant Publishing</h2>
</div>
</div>
</div>
<p>Suppose you’ve written a script you’d like to share with
others. You could just tell them to download from your
computer, but if they do so while you’re improving the script
or making experimental changes, they could wind up in
trouble. Of course, this is why release cycles exist.
Developers may work on a project frequently, but they only
make the code available when they feel it is presentable.</p>
<p>To do this with Git, in the directory where your script
resides:</p>
<pre class="literallayout">
$ git init
$ git add .
$ git commit -m "First release"
</pre>
<p>Then tell your users to run:</p>
<pre class="literallayout">
$ git clone your.computer:/path/to/script
</pre>
<p>to download your script. This assumes they have ssh
access. If not, run <span class="strong"><strong>git
daemon</strong></span> and tell your users to instead
run:</p>
<pre class="literallayout">
$ git clone git://your.computer/path/to/script
</pre>
<p>From now on, every time your script is ready for release,
execute:</p>
<pre class="literallayout">
$ git commit -a -m "Next release"
</pre>
<p>and your users can upgrade their version by changing to
the directory containing your script and typing:</p>
<pre class="literallayout">
$ git pull
</pre>
<p>Your users will never end up with a version of your script
you don’t want them to see.</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="what_have_i_done" name=
"what_have_i_done"></a>What Have I Done?</h2>
</div>
</div>
</div>
<p>Find out what changes you’ve made since the last commit
with:</p>
<pre class="literallayout">
$ git diff
</pre>
<p>Or since yesterday:</p>
<pre class="literallayout">
$ git diff "@{yesterday}"
</pre>
<p>Or between a particular version and 2 versions ago:</p>
<pre class="literallayout">
$ git diff 1b6d "master~2"
</pre>
<p>In each case the output is a patch that can be applied
with <span class="strong"><strong>git apply</strong></span>.
Try also:</p>
<pre class="literallayout">
$ git whatchanged --since="2 weeks ago"
</pre>
<p>Often I’ll browse history with <a class="ulink" href=
"http://sourceforge.net/projects/qgit" target="_top">qgit</a>
instead, due to its slick photogenic interface, or <a class=
"ulink" href="http://jonas.nitro.dk/tig/" target=
"_top">tig</a>, a text-mode interface that works well over
slow connections. Alternatively, install a web server, run
<span class="strong"><strong>git instaweb</strong></span> and
fire up any web browser.</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="exercise" name=
"exercise"></a>Exercise</h2>
</div>
</div>
</div>
<p>Let A, B, C, D be four successive commits where B is the
same as A except some files have been removed. We want to add
the files back at D. How can we do this?</p>
<p>There are at least three solutions. Assuming we are at
D:</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p class="simpara">The difference between A and B are
the removed files. We can create a patch representing
this difference and apply it:</p>
<pre class="literallayout">
$ git diff B A | git apply
</pre>
</li>
<li class="listitem">
<p class="simpara">Since we saved the files back at A,
we can retrieve them:</p>
<pre class="literallayout">
$ git checkout A foo.c bar.h
</pre>
</li>
<li class="listitem">
<p class="simpara">We can view going from A to B as a
change we want to undo:</p>
<pre class="literallayout">
$ git revert B
</pre>
</li>
</ol>
</div>
<p>Which choice is best? Whichever you prefer most. It is
easy to get what you want with Git, and often there are many
ways to get it.</p>
</div>
</div><script type="text/javascript" src="find_selflink.js">
</script>
</div>
</div><div class="footer"><a href="/~blynn/">Ben Lynn</a></div>
</body>
</html>
|