2012/08/15

That Conference: Git More Done

The final session I attended was presented by Keith Dahlby.

  • Config
    • git help config
    • git config –l
    • You have the system level configs, user configs, and repository level configs
    • git config –e –global (will open up the global config in default text editor)
    • configs are pretty similar to INI files
    • core.editor = <path>
    • diff.renames = false|true|copies
    • difftool.prompt = true|false
    • mergetool.prompt = true|false
    • mergetool.keepBackup = true|false
    • help.autocorrect = 0|N|-1
    • log.date=default|relative|local|iso|rfc short
    • aliasing
  • Named Commits
    • SHA1
      • or the unique initial substring (6 often sufficient)
    • Symbolic references:
      • branch (moves with commits)
      • Tag (remains static)
    • remote references
    • Head = what’s checked out
      • reference to a branch
      • Arbitrary commit (detatched HEAD)
        • on commit, no branch to update
    • ORIG_HEAD = “undo” for big HEAD changes
      • Saved before reset, merge, pull, etc.
    • FETCH_HEAD = last fetched from remote
      • git fetch <url> <branch>
    • MERGE_HEAD = incoming merge heads
    • Relatively naming commits
      • suffixes
        • ~ = parent; ~n = nth-generation grandparent
        • ^=first parent; ^n = nth merge parent
        • 3 commits ago = HEAD~3 = HEAD^^^
        • @{n} = nth prior value for that ref
        • Undo last commit = git reset HEAD@{1}
      • git help revisions
  • Local workflow
    • Ridiculously cheap – use liberally
      • Write SHA to file in refs/heads
    • Branches to clean up
      • git branch – merged
    • Keep Master clean!
    • New topic branch from master
      • git checkout master –b topic
    • Commit more than feels natural
    • git stash
      • Stash away work in progress
      • Typical workflow
        • git stash save “comment…”
        • switch to fix and then switch back
        • git stash pop
      • git stash save –include-untracked
      • git stash list
      • git stash show –p stash@{1}
      • git stash drop stash@{1}
      • git stash branch
    • Temporary Commits
      • Advantage: WIP lives in branch
      • commit, then git reset HEAD~ to go back
    • Reset path in index to match commit:
      • git reset commit  -- <paths>…
    • Unstage:
      • git reset HEAD – stateged-file.txt
    • Reset HEAD reference to commit:
      • git reset [—<mode>] commit
    • Discard previous commit:
      • git reset HEAD~
    • soft reset = move HEAD; don’t reset index/work tree. Essentially an uncommit
    • mixed mode = reset index but not work tree (default). Unstage
    • hard mode = reset index and work tree (discard changes (ignores untracked files); VERY DESTRUCTIVE!!!
    • git add –patch allows for overlapping changes that should be in different commits
      • reformatting
      • refactoring
      • changing functionality
      • Allow for “hunks” (sections of diff) to stage
      • Key operations: y/n, a (all)/d (delete), s (split), e (edit)
      • Also can be done on reset, checkout, and stash save
    • Rewriting History
      • Permanent when pushed
        • Until then, pretend you were perfect
      • git commit –amend (easiest way to change the last commit)
      • alias.cia = commit –amend –C HEAD
        • git cia –a –reset-author
      • git cherry-pick
        • apply changeset(s) elsewhere
          • like to the wrong branch
      • merge vs rebase
        • think of it like shuffling a deck of cards (merging) vs cutting a deck (rebasing)
        • rebasing are a replay of commits
        • rebase –interactive allows for replay with modifications
        • rebase –autosquash … use “fixup! <message>” and git will automatically combine a commit with one awhile ago
        • config rebase.autosquash
  • Fixing “oops”
    • git reflog
      • ls –r .git/logs
        • HEAD, heads, remotes
      • git reflog –all
  • Finding bugs
    • git bisect
      • binary search through a commit space
      • git bisect visualize = view = overview in gitk/log
      • git bisect skip (current version can’t be tested)
      • run my_script = automated bisect
  • http://github.com/dahlbyk/Presentations
  • http://github.com/dahlbyk/posh-git

No comments: