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

Git, The Good Stuff

Git, The Good Stuff

By now, everyone has branched and merged - but there is so much more to git. We will go through rebasing, cherry-picking, patch files, wrangling the git log, and power using git diff. I’ll show you how to do partial cherry picks, revert commits, and squash all your work into a manageable single commit or patch.

3de614918b5182f2562bc3659de0b296?s=128

philpalmieri

January 01, 2017
Tweet

Transcript

  1. Git, The Good Stuff Phil Palmieri

  2. What We Are Covering - Git Log - Rebasing -

    Squashing - Cherry-Picking - Patch Files - Reverting and Oh S!#t now what do I do?
  3. Anatomy of the log - %> git log - Every

    commit has a unique hash - Every hash has a - diff / files - date - author - message
  4. Git Log Options - Git log any branch by appending

    “git log [branch name]” - %> git log --stat (shows files) - --since/after=[date] - --until/before=[date] - --grep=[regex] - --graph (pretty graph)
  5. Git Log Format - %> git log --format=[oneline|short|medium|full] - %>

    git log --format=”custom %h formatting” - %h [short hash] - %an [author name] - %ar [date relative] - %C [color] full list at https://git-scm.com/docs/git-log
  6. Viewing a commit / hash %> git show [hash]

  7. Rebasing %> git rebase [branch] re-stacking the deck 3 1

    - 2 1 2 1 2 2 2 2 3 1 1 1
  8. Combining (squashing) commits %> git rebase -i HEAD~2 - will

    rebase interactive the last 2 commits - change hash to ‘s’ to squash multiple commits - update messages 3.2 3.1 3 2 1 3 2 1
  9. Cherry-Picking %> git cherry-pick [hash] creates a copy of a

    commit on one branch to another. - very good for copying code to a Q/A server
  10. Create a ‘Simple’ Patch File %> git show [hash1] >

    ~/mypatch.patch %> git show [hash2] >> ~/mypatch.patch (append) %> git apply ~/mypatch.patch
  11. Undo / Oh S#%t button %> git reset --hard HEAD

    ----------------------------------------------- %> git reset --hard HEAD^^^^^^^ (rollback a few commits) %> git pull
  12. Undo Your Commit %> git revert [hash] Did your code/commit

    break something - undo it. note: You can revert a revert to put it back
  13. Git Blame (who wrote that code?) %> git blame [file]

    Will show you who changed each line of the file