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.

philpalmieri

January 01, 2017
Tweet

More Decks by philpalmieri

Other Decks in Programming

Transcript

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

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

    commit has a unique hash - Every hash has a - diff / files - date - author - message
  3. 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)
  4. 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
  5. 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
  6. 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
  7. Create a ‘Simple’ Patch File %> git show [hash1] >

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

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

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

    Will show you who changed each line of the file