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

Git

 Git

Presented at GR Dev Day 2013. View corresponding shell sessions at http://brondsema.net/presentations/grdevday-git/

Dave Brondsema

March 02, 2013
Tweet

More Decks by Dave Brondsema

Other Decks in Programming

Transcript

  1. Git Commands add am archive bisect branch bundle checkout cherry-pick

    citool clean clone commit describe diff fetch format-patch gc grep gui init log merge mv notes pull push rebase reset revert rm shortlog show stash status submodule tag gitk config fast-export fast-import filter-branch lost-found mergetool pack-refs prune reflog relink remote repack replace repo-config annotate blame cherry count-objects difftool fsck get-tar-commit-id help instaweb merge-tree rerere rev-parse show-branch verify-tag whatchanged archimport cvsexportcommit cvsimport cvsserver imap-send quiltimport request-pull send-email svn apply checkout-index commit-tree hash-object index-pack merge-file merge-index mktag mktree pack-objects prune-packed read-tree symbolic-ref unpack-objects update-index update-ref write-tree cat-file diff-files diff-index diff-tree for-each-ref ls-files ls-remote ls-tree merge-base name-rev pack-redundant rev-list show-index show-ref tar-tree unpack-file var verify-pack daemon fetch-pack http-backend send-pack update-server-info http-fetch http-push parse-remote receive-pack shell upload-archive upload-pack check-attr check-ref-format fmt-merge-msg mailinfo mailsplit merge-one-file patch-id peek-remote sh-setup stripspace ...also extremely powerful "porcelain", "plumbing" i don't know them all learning curve
  2. Git Commands add bisect blame checkout cherry-pick clone commit config

    diff fetch help init log merge mv pull push rebase remote reset revert rm show stash status tag focus on just a few example usage, many possibilities
  3. Start git init OR git clone ... clone is really

    a clone - you get it all, locally then you work locally. In contrast with SVN, you only push & pull when you specifically say so
  4. Looking around git log --decorate --stat --graph git show git

    diff git blame git bisect see how a repository looks terminology
  5. HEAD -> where you're currently at branches. "master" is the

    main one, by convention tags are just names for commits gitk, other guis
  6. lots of ways to display it short hash diff is

    very flexible, commitish, symbolic, etc
  7. Looking around git log --decorate --stat --graph git show git

    diff git blame git bisect blame you've seen before, straightforward bisect - interactive session of good/bad commits to narrow in on one
  8. Example workflow git checkout -b fix-abc ...code it up... git

    status # review our work git diff git commit -m "abc works now" -a git push ...code up a new test... git add tests/test_abc.py git commit -m "add a test too" git fetch # get any master changes from origin git rebase -i origin/master # rebase against those changes git push --force # warning -- force pushing is dangerous git checkout master git pull # merge origin changes into local master git merge fix-abc git push how I typically use git. See shell session recording
  9. Rebase vs Merge Some people like to keep merge commits

    when branches come in to master Show shell recording warning - reverting a merge, then re-merging it is tricky
  10. Bonus git cherry-pick [commit-ish] git stash [...] git revert [commit-ish]

    git commit --patch move individual commits around quickly move changes aside - but why not commit? revert - you can't go back in time (not without destroying stuff) - instead, new commit which is reverse of prior commit commit chunks at a time, make separate cohesive commits
  11. Bonus: searching history git log [-p] --grep word-in-commit-message git log

    [-p] -G word-in-diff git log [-p] -S word-added-or-removed
  12. Bonus: reviewing code git diff master... # three dots to

    combine all commits git diff -U10 # 10 lines context (unified diff) git diff --color-words # see tiny changes in big lines git diff -w # ignore whitespace changes git log -- tests/foo/ # limit to a path
  13. Bonus: fixing mistakes git checkout path/file.ext # reset file to

    last commit git reset [...] # various types, soft, hard git rebase --abort # quit a rebase git merge --abort # quit a pull with conflicts "checkout" is overloaded :( a pull is a fetch+merge, conflicts mean somebody force-pushed, need to use reset