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

Advanced Git

Mike McQuaid
February 29, 2012

Advanced Git

A walkthrough of some lesser-known advanced features in Git.
Presented at the KDAB company meeting in 2011.

Mike McQuaid

February 29, 2012
Tweet

More Decks by Mike McQuaid

Other Decks in Programming

Transcript

  1. Advanced Git
    Mike McQuaid

    View Slide

  2. /usr/local/bin/git-foo
    == git foo

    View Slide

  3. git cherry master

    View Slide

  4. git reflog

    View Slide

  5. a369495 HEAD@{39}: commit (amend): Make tray icon strings more
    consistent.
    5e7f0b0 HEAD@{40}: commit: Make tray icon strings more consistent.
    8b84f7f HEAD@{41}: commit: Fix not being able to run previous task from
    menu.
    436df83 HEAD@{42}: commit: Fix start task menu separator usage.
    8e61a3f HEAD@{43}: rebase -i (continue): More consistent alternate row
    colors.
    7c56620 HEAD@{44}: rebase -i (continue): Improve tasks eliding.
    0def733 HEAD@{45}: checkout: moving from master to
    0def733217f57276901da9ff578366f56d2d0f02
    74fae75 HEAD@{46}: rebase -i (fixup): Improve tasks eliding.
    515aa9b HEAD@{47}: rebase -i (fixup): updating HEAD

    View Slide

  6. [alias]

    x = !gitx

    View Slide

  7. [github]

    token = verysecurepassword123

    View Slide

  8. [github]

    token = !security 2>&1 >/dev/null find-
    generic-password -gs github.token | grep
    password | cut -f2 -d\\\" #"

    View Slide

  9. [alias]

    serve = !git daemon --reuseaddr --export-
    all --base-path=. --verbose ./.git

    View Slide

  10. [core]
    excludesfile = ~/.gitignore

    View Slide

  11. moc_*.cpp
    qrc_*.cpp
    ui_*.h
    *.pro.user
    *.o
    *.rej
    *.swp
    *~
    .DS_Store
    CMakeLists.txt.user
    b/

    View Slide

  12. [sendemail]

    identity = kdab

    thread = false

    chainreplyto = false

    suppresscc = all
    [sendemail "kdab"]

    smtpserver = mail.kdab.com

    smtpencryption = tls

    smtpserverport = 25

    smtpuser = mike

    from = [email protected]

    View Slide

  13. Merge vs Rebase

    View Slide

  14. 1 branch per feature
    git merge / git pull
    many branches with many merge commits
    1 branch used for release

    View Slide

  15. CMake

    View Slide

  16. 1 branch or commit per feature
    git rebase / git pull --rebase
    1 branch with no merge commits
    1 branch used for release

    View Slide

  17. Homebrew

    View Slide

  18. This is the short commit message
    Longer commit message that spans multiple
    lines.
    - List items
    - Like this

    View Slide

  19. From 2ca294d83d8f64b8ff1611efa4aa4d1baa4f291a Mon Sep 17 00:00:00 2001
    From: Mike McQuaid
    Date: Wed, 20 Apr 2011 12:17:37 +0100
    Subject: [PATCH] Add DeployQt4 module.
    Add a module that gives better support to BundleUtilities to handle
    Qt plugins and deploy Qt applications.
    ---
    Modules/DeployQt4.cmake | 104 +++++++++++++++++++++++++++++++++++++++++++++++
    1 files changed, 104 insertions(+), 0 deletions(-)
    create mode 100644 Modules/DeployQt4.cmake
    diff --git a/Modules/DeployQt4.cmake b/Modules/DeployQt4.cmake
    ...

    View Slide

  20. git rebase 93b0c51

    View Slide

  21. git merge 93b0c51

    View Slide

  22. git clone ~/git1 ~/git2

    View Slide

  23. git cherry-pick 93b0c51

    View Slide

  24. Secure backup:
    2ca294d83d8f64b8ff161
    1efa4aa4d1baa4f291a

    View Slide

  25. git filter-branch --tree-filter 'rm secretfile'
    HEAD

    View Slide

  26. git diff 1b6d > my.patch
    git apply < my.patch

    View Slide

  27. git format-patch 1b6d
    git am < 0001-ab.patch

    View Slide

  28. git send-email 1b6d

    View Slide

  29. git remote add other
    git://a/b.git
    git pull other a-branch

    View Slide

  30. git diff origin/a other/b

    View Slide

  31. git fetch
    git fetch other
    git fetch --all

    View Slide

  32. export GIT_DIR=./a.git

    View Slide

  33. GIT_WORK_TREE
    GIT_INDEX_FILE

    View Slide

  34. git submodule add
    git://b/b.git b

    View Slide

  35. git clone git://a/a.git
    cd a/b
    git submodule init
    git submodule update

    View Slide

  36. superprojects

    View Slide

  37. .gitattributes
    .git/info/attributes

    View Slide

  38. *.pbxproj binary

    View Slide

  39. *.doc diff=word

    View Slide

  40. git config
    diff.word.textconv
    strings

    View Slide

  41. *.png diff=exif

    View Slide

  42. git config
    diff.exif.textconv
    exiftool

    View Slide

  43. --- a/image.png
    +++ b/image.png
    @@ -1,12 +1,12 @@
    -File Size : 70 kB
    -File Modification Date/Time : 2009:04:21 07:02:45-07:00
    +File Size : 94 kB
    +File Modification Date/Time : 2009:04:21 07:02:43-07:00
    -Image Width : 1058
    -Image Height : 889
    +Image Width : 1056
    +Image Height : 827

    View Slide

  44. *.txt ident
    echo '$Id$' > test.txt

    View Slide

  45. applypatch-msg
    commit-msg
    post-commit
    post-receive
    post-update
    pre-applypatch
    pre-commit
    pre-rebase
    prepare-commit-msg
    update

    View Slide

  46. http://zrusin.blogspot.com/2007/09/
    git-cheat-sheet.html

    View Slide

  47. Any questions?

    View Slide