/usr/share/doc/gitmagic/html/ch05.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 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | <!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 5. Lessons of History</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="ch04.html" title=
"Chapter 4. Branch Wizardry">
<link rel="next" href="ch06.html" title=
"Chapter 6. Multiplayer Git">
</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="lessons_of_history" name=
"lessons_of_history"></a>Chapter 5. Lessons of
History</h1>
</div>
</div>
</div>
<p>A consequence of Git’s distributed nature is that history
can be edited easily. But if you tamper with the past, take
care: only rewrite that part of history which you alone
possess. Just as nations forever argue over who committed what
atrocity, if someone else has a clone whose version of history
differs to yours, you will have trouble reconciling when your
trees interact.</p>
<p>Some developers strongly feel history should be immutable,
warts and all. Others feel trees should be made presentable
before they are unleashed in public. Git accommodates both
viewpoints. Like cloning, branching, and merging, rewriting
history is simply another power Git gives you. It is up to you
to use it wisely.</p>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="i_stand_corrected" name=
"i_stand_corrected"></a>I Stand Corrected</h2>
</div>
</div>
</div>
<p>Did you just commit, but wish you had typed a different
message? Then run:</p>
<pre class="literallayout">
$ git commit --amend
</pre>
<p>to change the last message. Realized you forgot to add a
file? Run <span class="strong"><strong>git
add</strong></span> to add it, and then run the above
command.</p>
<p>Want to include a few more edits in that last commit? Then
make those edits and run:</p>
<pre class="literallayout">
$ git commit --amend -a
</pre>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="and_then_some" name=
"and_then_some"></a>… And Then Some</h2>
</div>
</div>
</div>
<p>Suppose the previous problem is ten times worse. After a
lengthy session you’ve made a bunch of commits. But you’re
not quite happy with the way they’re organized, and some of
those commit messages could use rewording. Then type:</p>
<pre class="literallayout">
$ git rebase -i HEAD~10
</pre>
<p>and the last 10 commits will appear in your favourite
$EDITOR. A sample excerpt:</p>
<pre class="literallayout">
pick 5c6eb73 Added repo.or.cz link
pick a311a64 Reordered analogies in "Work How You Want"
pick 100834f Added push target to Makefile
</pre>
<p>Older commits precede newer commits in this list, unlike
the <code class="literal">log</code> command. Here, 5c6eb73
is the oldest commit, and 100834f is the newest. Then:</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">Remove commits by deleting lines.
Like the revert command, but off the record: it will be
as if the commit never existed.</li>
<li class="listitem">Reorder commits by reordering
lines.</li>
<li class="listitem">
<p class="simpara">Replace <code class=
"literal">pick</code> with:</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="circle">
<li class="listitem"><code class=
"literal">edit</code> to mark a commit for
amending.</li>
<li class="listitem"><code class=
"literal">reword</code> to change the log
message.</li>
<li class="listitem"><code class=
"literal">squash</code> to merge a commit with the
previous one.</li>
<li class="listitem"><code class=
"literal">fixup</code> to merge a commit with the
previous one and discard the log message.</li>
</ul>
</div>
</li>
</ul>
</div>
<p>For example, we might replace the second <code class=
"literal">pick</code> with <code class=
"literal">squash</code>:</p>
<pre class="literallayout">
pick 5c6eb73 Added repo.or.cz link
squash a311a64 Reordered analogies in "Work How You Want"
pick 100834f Added push target to Makefile
</pre>
<p>After we save and quit, Git merges a311a64 into 5c6eb73.
Thus <span class="strong"><strong>squash</strong></span>
merges into the next commit up: think “squash up”.</p>
<p>Git then combines their log messages and presents them for
editing. The command <span class=
"strong"><strong>fixup</strong></span> skips this step; the
squashed log message is simply discarded.</p>
<p>If you marked a commit with <span class=
"strong"><strong>edit</strong></span>, Git returns you to the
past, to the oldest such commit. You can amend the old commit
as described in the previous section, and even create new
commits that belong here. Once you’re pleased with the
“retcon”, go forward in time by running:</p>
<pre class="literallayout">
$ git rebase --continue
</pre>
<p>Git replays commits until the next <span class=
"strong"><strong>edit</strong></span>, or to the present if
none remain.</p>
<p>You can also abandon the rebase with:</p>
<pre class="literallayout">
$ git rebase --abort
</pre>
<p>So commit early and commit often: you can tidy up later
with rebase.</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="local_changes_last" name=
"local_changes_last"></a>Local Changes Last</h2>
</div>
</div>
</div>
<p>You’re working on an active project. You make some local
commits over time, and then you sync with the official tree
with a merge. This cycle repeats itself a few times before
you’re ready to push to the central tree.</p>
<p>But now the history in your local Git clone is a messy
jumble of your changes and the official changes. You’d prefer
to see all your changes in one contiguous section, and after
all the official changes.</p>
<p>This is a job for <span class="strong"><strong>git
rebase</strong></span> as described above. In many cases you
can use the <span class=
"strong"><strong>--onto</strong></span> flag and avoid
interaction.</p>
<p>Also see <span class="strong"><strong>git help
rebase</strong></span> for detailed examples of this amazing
command. You can split commits. You can even rearrange
branches of a tree.</p>
<p>Take care: rebase is a powerful command. For complicated
rebases, first make a backup with <span class=
"strong"><strong>git clone</strong></span>.</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="rewriting_history" name=
"rewriting_history"></a>Rewriting History</h2>
</div>
</div>
</div>
<p>Occasionally, you need the source control equivalent of
airbrushing people out of official photos, erasing them from
history in a Stalinesque fashion. For example, suppose we
intend to release a project, but it involves a file that
should be kept private for some reason. Perhaps I left my
credit card number in a text file and accidentally added it
to the project. Deleting the file is insufficient, for the
file can be accessed from older commits. We must remove the
file from all commits:</p>
<pre class="literallayout">
$ git filter-branch --tree-filter 'rm top/secret/file' HEAD
</pre>
<p>See <span class="strong"><strong>git help
filter-branch</strong></span>, which discusses this example
and gives a faster method. In general, <span class=
"strong"><strong>filter-branch</strong></span> lets you alter
large sections of history with a single command.</p>
<p>Afterwards, the <code class=
"literal">.git/refs/original</code> directory describes the
state of affairs before the operation. Check the
filter-branch command did what you wanted, then delete this
directory if you wish to run more filter-branch commands.</p>
<p>Lastly, replace clones of your project with your revised
version if you want to interact with them later.</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="making_history" name=
"making_history"></a>Making History</h2>
</div>
</div>
</div>
<p><a name="makinghistory" id="makinghistory"></a>Want to
migrate a project to Git? If it’s managed with one of the
more well-known systems, then chances are someone has already
written a script to export the whole history to Git.</p>
<p>Otherwise, look up <span class="strong"><strong>git
fast-import</strong></span>, which reads text input in a
specific format to create Git history from scratch. Typically
a script using this command is hastily cobbled together and
run once, migrating the project in a single shot.</p>
<p>As an example, paste the following listing into temporary
file, such as <code class="literal">/tmp/history</code>:</p>
<pre class="screen">
commit refs/heads/master
committer Alice <alice@example.com> Thu, 01 Jan 1970 00:00:00 +0000
data <<EOT
Initial commit.
EOT
M 100644 inline hello.c
data <<EOT
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
EOT
commit refs/heads/master
committer Bob <bob@example.com> Tue, 14 Mar 2000 01:59:26 -0800
data <<EOT
Replace printf() with write().
EOT
M 100644 inline hello.c
data <<EOT
#include <unistd.h>
int main() {
write(1, "Hello, world!\n", 14);
return 0;
}
EOT
</pre>
<p>Then create a Git repository from this temporary file by
typing:</p>
<pre class="literallayout">
$ mkdir project; cd project; git init
$ git fast-import --date-format=rfc2822 < /tmp/history
</pre>
<p>You can checkout the latest version of the project
with:</p>
<pre class="literallayout">
$ git checkout master .
</pre>
<p>The <span class="strong"><strong>git
fast-export</strong></span> command converts any repository
to the <span class="strong"><strong>git
fast-import</strong></span> format, whose output you can
study for writing exporters, and also to transport
repositories in a human-readable format. Indeed, these
commands can send repositories of text files over text-only
channels.</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="where_did_it_all_go_wrong"
name="where_did_it_all_go_wrong"></a>Where Did It All
Go Wrong?</h2>
</div>
</div>
</div>
<p>You’ve just discovered a broken feature in your program
which you know for sure was working a few months ago. Argh!
Where did this bug come from? If only you had been testing
the feature as you developed.</p>
<p>It’s too late for that now. However, provided you’ve been
committing often, Git can pinpoint the problem:</p>
<pre class="literallayout">
$ git bisect start
$ git bisect bad HEAD
$ git bisect good 1b6d
</pre>
<p>Git checks out a state halfway in between. Test the
feature, and if it’s still broken:</p>
<pre class="literallayout">
$ git bisect bad
</pre>
<p>If not, replace "bad" with "good". Git again transports
you to a state halfway between the known good and bad
versions, narrowing down the possibilities. After a few
iterations, this binary search will lead you to the commit
that caused the trouble. Once you’ve finished your
investigation, return to your original state by typing:</p>
<pre class="literallayout">
$ git bisect reset
</pre>
<p>Instead of testing every change by hand, automate the
search by running:</p>
<pre class="literallayout">
$ git bisect run my_script
</pre>
<p>Git uses the return value of the given command, typically
a one-off script, to decide whether a change is good or bad:
the command should exit with code 0 when good, 125 when the
change should be skipped, and anything else between 1 and 127
if it is bad. A negative return value aborts the bisect.</p>
<p>You can do much more: the help page explains how to
visualize bisects, examine or replay the bisect log, and
eliminate known innocent changes for a speedier search.</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="who_made_it_all_go_wrong"
name="who_made_it_all_go_wrong"></a>Who Made It All Go
Wrong?</h2>
</div>
</div>
</div>
<p>Like many other version control systems, Git has a blame
command:</p>
<pre class="literallayout">
$ git blame bug.c
</pre>
<p>which annotates every line in the given file showing who
last changed it, and when. Unlike many other version control
systems, this operation works offline, reading only from
local disk.</p>
</div>
<div class="section">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a id="personal_experience" name=
"personal_experience"></a>Personal Experience</h2>
</div>
</div>
</div>
<p>In a centralized version control system, history
modification is a difficult operation, and only available to
administrators. Cloning, branching, and merging are
impossible without network communication. So are basic
operations such as browsing history, or committing a change.
In some systems, users require network connectivity just to
view their own changes or open a file for editing.</p>
<p>Centralized systems preclude working offline, and need
more expensive network infrastructure, especially as the
number of developers grows. Most importantly, all operations
are slower to some degree, usually to the point where users
shun advanced commands unless absolutely necessary. In
extreme cases this is true of even the most basic commands.
When users must run slow commands, productivity suffers
because of an interrupted work flow.</p>
<p>I experienced these phenomena first-hand. Git was the
first version control system I used. I quickly grew
accustomed to it, taking many features for granted. I simply
assumed other systems were similar: choosing a version
control system ought to be no different from choosing a text
editor or web browser.</p>
<p>I was shocked when later forced to use a centralized
system. A flaky internet connection matters little with Git,
but makes development unbearable when it needs to be as
reliable as local disk. Additionally, I found myself
conditioned to avoid certain commands because of the
latencies involved, which ultimately prevented me from
following my desired work flow.</p>
<p>When I had to run a slow command, the interruption to my
train of thought dealt a disproportionate amount of damage.
While waiting for server communication to complete, I’d do
something else to pass the time, such as check email or write
documentation. By the time I returned to the original task,
the command had finished long ago, and I would waste more
time trying to remember what I was doing. Humans are bad at
context switching.</p>
<p>There was also an interesting tragedy-of-the-commons
effect: anticipating network congestion, individuals would
consume more bandwidth than necessary on various operations
in an attempt to reduce future delays. The combined efforts
intensified congestion, encouraging individuals to consume
even more bandwidth next time to avoid even longer
delays.</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>
|