Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Debug Code and Rewrite History with Git

Debug Code and Rewrite History with Git

A short talk about how to use git bisect, interactive rebase, and git reflog for the first Dev O'Clock HVTech meetup.

Eileen M. Uchitelle

September 10, 2015
Tweet

More Decks by Eileen M. Uchitelle

Other Decks in Technology

Transcript

  1. Debug Code and
    Rewrite History
    with Git

    View Slide

  2. EILEEN M. UCHITELLE
    Programmer at Basecamp
    ! eileencodes.com
    " @eileencodes
    # @eileencodes

    View Slide

  3. Rails Committers Team &
    Rails Security Team

    View Slide

  4. PRACTICE REPO
    $ git clone [email protected]:eileencodes/
    railsconf_scripts.git
    $ git checkout practicing-git

    View Slide

  5. GIT
    $ git bisect
    $ git rebase -i
    $ git reflog

    View Slide

  6. Debugging with
    Git Bisect
    C1 C2 C3 C4 C5 C6 M3 M4
    M0

    View Slide

  7. GIT BISECT
    $ git bisect start

    View Slide

  8. GIT BISECT
    $ git bisect bad
    $ git bisect good tag-name

    View Slide

  9. GIT BISECT
    $ git bisect

    View Slide

  10. Rewriting History
    with Git
    C1 C2 C3 C4 C5 C6 M3 M4
    M0

    View Slide

  11. Short (50 chars or less) summary of changes
    More detailed explanatory text, if necessary. Wrap it to
    about 72 characters or so. In some contexts, the first
    line is treated as the subject of an email and the rest
    of the text as the body. The blank line separating the
    summary from the body is critical (unless you omit
    the body entirely); tools like rebase can get confused
    if you run the two together.
    Further paragraphs come after blank lines.
    - Bullet points are okay, too
    - Typically a hyphen or asterisk is used for the
    bullet, preceded by a single space, with blank lines in
    between, but conventions vary here

    View Slide

  12. Using
    M1 M2 M3 M4
    F1 F2 F1 F2
    M0
    Interactive Rebase

    View Slide

  13. GIT

    View Slide

  14. GIT REBASE -I
    $ git rebase -i master

    View Slide

  15. 1 pick e92e34f Refactor existing code
    2 pick 80601e8 Oops add in missing code
    3 pick 8d91f76 Remove extra piece I left behind
    4 pick 933bd58 Fix bug reported in #9895
    5 pick 99302ef Clean up changes
    6 pick 5cc3c5a Fix spelling mistake in documentation
    7
    8 # Rebase 0131d99..5cc3c5a onto 0131d99
    9 #
    10 # Commands:
    11 # p, pick = use commit
    12 # r, reword = use commit, but edit the commit message
    13 # e, edit = use commit, but stop for amending
    14 # s, squash = use commit, but meld into previous commit
    15 # f, fixup = like "squash", but discard this commit's log
    16 # x, exec = run command (the rest of the line) using shell

    View Slide

  16. 1 pick e92e34f Refactor existing code
    2 pick 80601e8 Oops add in missing code
    3 pick 8d91f76 Remove extra piece I left behind
    4 pick 933bd58 Fix bug reported in #9895
    5 pick 99302ef Clean up changes
    6 pick 5cc3c5a Fix spelling mistake in documentation
    7
    8 # Rebase 0131d99..5cc3c5a onto 0131d99
    9 #
    10 # Commands:
    11 # p, pick = use commit
    12 # r, reword = use commit, but edit the commit message
    13 # e, edit = use commit, but stop for amending
    14 # s, squash = use commit, but meld into previous commit
    15 # f, fixup = like "squash", but discard this commit's log
    16 # x, exec = run command (the rest of the line) using shell

    View Slide

  17. 1 reword e92e34f Refactor existing code
    2 pick 80601e8 Oops add in missing code
    3 pick 8d91f76 Remove extra piece I left behind
    4 pick 933bd58 Fix bug reported in #9895
    5 pick 99302ef Clean up changes
    6 pick 5cc3c5a Fix spelling mistake in documentation
    7
    8 # Rebase 0131d99..5cc3c5a onto 0131d99
    9 #
    10 # Commands:
    11 # p, pick = use commit
    12 # r, reword = use commit, but edit the commit message
    13 # e, edit = use commit, but stop for amending
    14 # s, squash = use commit, but meld into previous commit
    15 # f, fixup = like "squash", but discard this commit's log
    16 # x, exec = run command (the rest of the line) using shell

    View Slide

  18. 1 reword e92e34f Refactor existing code
    2 pick 80601e8 Oops add in missing code
    3 edit 8d91f76 Remove extra piece I left behind
    4 pick 933bd58 Fix bug reported in #9895
    5 pick 99302ef Clean up changes
    6 pick 5cc3c5a Fix spelling mistake in documentation
    7
    8 # Rebase 0131d99..5cc3c5a onto 0131d99
    9 #
    10 # Commands:
    11 # p, pick = use commit
    12 # r, reword = use commit, but edit the commit message
    13 # e, edit = use commit, but stop for amending
    14 # s, squash = use commit, but meld into previous commit
    15 # f, fixup = like "squash", but discard this commit's log
    16 # x, exec = run command (the rest of the line) using shell

    View Slide

  19. 1 reword e92e34f Refactor existing code
    2 pick 80601e8 Oops add in missing code
    3 edit 8d91f76 Remove extra piece I left behind
    4 pick 933bd58 Fix bug reported in #9895
    5 squash 99302ef Clean up changes
    6 pick 5cc3c5a Fix spelling mistake in documentation
    7
    8 # Rebase 0131d99..5cc3c5a onto 0131d99
    9 #
    10 # Commands:
    11 # p, pick = use commit
    12 # r, reword = use commit, but edit the commit message
    13 # e, edit = use commit, but stop for amending
    14 # s, squash = use commit, but meld into previous commit
    15 # f, fixup = like "squash", but discard this commit's log
    16 # x, exec = run command (the rest of the line) using shell

    View Slide

  20. 1 reword e92e34f Refactor existing code
    2 fixup 80601e8 Oops add in missing code
    3 edit 8d91f76 Remove extra piece I left behind
    4 pick 933bd58 Fix bug reported in #9895
    5 squash 99302ef Clean up changes
    6 pick 5cc3c5a Fix spelling mistake in documentation
    7
    8 # Rebase 0131d99..5cc3c5a onto 0131d99
    9 #
    10 # Commands:
    11 # p, pick = use commit
    12 # r, reword = use commit, but edit the commit message
    13 # e, edit = use commit, but stop for amending
    14 # s, squash = use commit, but meld into previous commit
    15 # f, fixup = like "squash", but discard this commit's log
    16 # x, exec = run command (the rest of the line) using shell

    View Slide

  21. 1 reword e92e34f Refactor existing code
    2 fixup 80601e8 Oops add in missing code
    3 edit 8d91f76 Remove extra piece I left behind
    4 pick 933bd58 Fix bug reported in #9895
    5 squash 99302ef Clean up changes
    6 pick 5cc3c5a Fix spelling mistake in documentation
    7
    8 # Rebase 0131d99..5cc3c5a onto 0131d99
    9 #
    10 # Commands:
    11 # p, pick = use commit
    12 # r, reword = use commit, but edit the commit message
    13 # e, edit = use commit, but stop for amending
    14 # s, squash = use commit, but meld into previous commit
    15 # f, fixup = like "squash", but discard this commit's log
    16 # x, exec = run command (the rest of the line) using shell

    View Slide

  22. GIT REBASE -I
    $ git rebase -i master

    View Slide

  23. 628168
    628168
    50718b
    bc503a1
    C1 C2 C3 C4
    C0
    Git Reflog
    Using

    View Slide

  24. View Slide

  25. GIT REFLOG
    $ git reflog

    View Slide

  26. 628c168 [email protected]{0}: rebase -i (finish): returning to refs/heads/your-branch
    628c168 [email protected]{1}: rebase -i (start): checkout master
    628c168 [email protected]{2}: reset: moving to 628c168
    bc503a1 [email protected]{3}: rebase -i (finish): returning to refs/heads/your-branch
    bc503a1 [email protected]{4}: rebase -i (pick): Add Person model and migration
    1ad2ff2 [email protected]{5}: rebase -i (pick): Improve README section on git reflog
    026457d [email protected]{6}: rebase -i (start): checkout master
    633f620 [email protected]{7}: rebase -i (finish): returning to refs/heads/your-branch
    633f620 [email protected]{8}: rebase -i (pick): Improve README section on git reflog
    19f41a7 [email protected]{9}: commit (amend): Add Person model and migration
    50718b1 [email protected]{10}: rebase -i (edit): Add Person model and migration
    026457d [email protected]{11}: rebase -i (reword): Update README with sections on rebase and
    c8c6000 [email protected]{12}: rebase -i (reword): Update README with sections on rebase and
    628fbd2 [email protected]{13}: rebase -i (squash): Update README description section
    455dab0 [email protected]{14}: rebase -i (fixup): # This is a combination of 2 commits.
    4392779 [email protected]{15}: rebase -i (start): checkout master
    628c168 [email protected]{16}: rebase -i (finish): returning to refs/heads/your-branch
    628c168 [email protected]{17}: rebase -i (start): checkout master
    628c168 [email protected]{18}: rebase -i (finish): returning to refs/heads/your-branch
    628c168 [email protected]{19}: rebase -i (start): checkout master
    628c168 [email protected]{20}: rebase: aborting
    1f935f7 [email protected]{21}: rebase -i (edit): Add Person model and migration

    View Slide

  27. GIT REFLOG
    $ git reflog
    $ git reset -—hard 628c168

    View Slide

  28. EILEEN M. UCHITELLE
    Programmer at Basecamp
    ! eileencodes.com
    " @eileencodes
    # @eileencodes
    Slides:
    speakerdeck.com/eileencodes

    View Slide