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

Digging into Git

Digging into Git

Daily Kos Skillshare by Meagan Waller

Meagan Waller

March 10, 2017
Tweet

More Decks by Meagan Waller

Other Decks in Technology

Transcript

  1. A graph is a structure consisting of a collection of

    nodes and a collection of edges that connect pairs of nodes. 4
  2. A graph is a structure consisting of a collection of

    nodes and a collection of edges that connect pairs of nodes. 4 Node Node Node Edge Edge Edge
  3. 6 Seven Bridges of Königsberg Can you walk through the

    city and cross every bridge exactly once?
  4. 17 The Blob The contents of the file are stored

    as blobs. !"❱❱❱ git cat-file -p 2edbc8 # This is the Skillshare README
  5. 18 The Tree Directories are stored as trees. Trees are

    pointers to blobs and other trees. !"❱❱❱ git cat-file -p d31e9 100644 blob 2edbc8 README.md 040000 tree 260449 app A tree stores a text file with the mode, type, sha, and, name of each entry.
  6. 19 The Commit The history of these blobs and trees

    is stored in the commit object. !"❱❱❱ git cat-file -p 237e8d7 tree d31e9e author Meagan Waller committer Meagan Waller Initial commit A commit points to a tree and keeps an author, committer, message, and any parent commits
  7. 20 The Commit The history of these blobs and trees

    is stored in the commit object. !"❱❱❱ git cat-file -p e825ee8 tree b8ba0 parent 045883 author Meagan Waller committer Meagan Waller A commit points to a tree and keeps an author, committer, message, and any parent commits
  8. 21 The Commit The history of these blobs and trees

    is stored in the commit object. !"❱❱❱ git cat-file -p 1e4fb7a tree 5d7bf9 parent 4d9d44 parent 1ecf93 author Meagan Waller A commit points to a tree and keeps an author, committer, message, and any parent commits
  9. 22 The Tag Tags are objects that provide a permanent

    shorthand name for a particular commit. !"❱❱❱ git cat-file -p v1.0 object 237e8d type commit tag v1.0 tagger Meagan Waller version 1.0 They contain an object, type, tagger, and a message. The type is usually a commit and the object is the SHA-1 of the commit you’re tagging.
  10. Visualizing the Git Repo 23 !"❱❱❱ git log 4786ce0 (HEAD

    -> master) Merge branch ‘new-feature' 240106a (hotfix) Does the even cooler thing 78d44a3 (new-feature) Adds the amazing feature 830b929 Adds to the README 237e8d7 (tag: v1.0) Initial commit
  11. Visualizing the Git Repo 25 Commits are nodes in the

    graph Parent commits are edges in the graph
  12. Visualizing the Git Repo 26 Commits are nodes in the

    graph Parent commits are edges in the graph
  13. Visualizing the Git Repo 27 Commits are nodes in the

    graph Parent commits are edges in the graph
  14. Branch & Branch Often 28 Git stores a series of

    snapshots. A commit is a pointer to the snapshot of the content we staged and some metadata. A branch is a moveable, lightweight pointer to a commit. master is no different than any other branch
  15. Creating a branch 29 A new pointer is created. !"❱❱❱

    git branch new-feature Creating a branch is writing 40 bytes to disk.
  16. When history diverges 32 Commits point to their parents, Git

    leverages this to automatically merge.
  17. When history diverges 33 1. Work on our application 2.

    Create a branch for a new story 3. Do work in that branch
  18. When history diverges 33 1. Work on our application 2.

    Create a branch for a new story 3. Do work in that branch Critical issue requires a hot fix ASAP
  19. When history diverges 33 1. Work on our application 2.

    Create a branch for a new story 3. Do work in that branch Critical issue requires a hot fix ASAP 1. Switch to production branch 2. Create a hot fix branch 3. After testing, merge branch and push to production 4. Switch back to original story and continue working
  20. When history diverges 34 The hot fix merge is fast-forwarded

    No merge commit will be made Commit pointed to by hotfix branch directly ahead of commit pointed to by master
  21. When history diverges 34 The hot fix merge is fast-forwarded

    No merge commit will be made Commit pointed to by hotfix branch directly ahead of commit pointed to by master Git only had to move the pointer forward.
  22. When history diverges 35 Ready to merge new-feature into master.

    The merge is made by the recursive strategy.
  23. When history diverges 35 Ready to merge new-feature into master.

    The merge is made by the recursive strategy. Our histories have diverged, master had hotfix merged into it.
  24. When history diverges 35 Ready to merge new-feature into master.

    The merge is made by the recursive strategy. Git performs a three-way merge Our histories have diverged, master had hotfix merged into it.
  25. When history diverges 35 Ready to merge new-feature into master.

    The merge is made by the recursive strategy. Git performs a three-way merge 1. Finds a common ancestor of master and the feature branch Our histories have diverged, master had hotfix merged into it.
  26. When history diverges 35 Ready to merge new-feature into master.

    The merge is made by the recursive strategy. Git performs a three-way merge 1. Finds a common ancestor of master and the feature branch 2. Creates a new snapshot, the result of the three-way merge Our histories have diverged, master had hotfix merged into it.
  27. When history diverges 35 Ready to merge new-feature into master.

    The merge is made by the recursive strategy. Git performs a three-way merge 1. Finds a common ancestor of master and the feature branch 2. Creates a new snapshot, the result of the three-way merge 3. Creates a merge commit pointing to the snapshot. This commit will have 2 parents. Our histories have diverged, master had hotfix merged into it.
  28. Rebasing 41 Another way to integrate changes from one branch

    to another. Takes changes committed on one branch and replays them on another one.
  29. Rebasing 42 $ git checkout new-feature $ git rebase master

    First, rewinding head to replay your work on top of it... Applying: Adds to the README Applying: Adds TODO for specs
  30. Golden Rule of Rebasing 43 Never rebase commits that exist

    outside your repository. C1 master C1 dk/master C2 C3 master DK team remote repository My local repo — I’ve cloned the repo and based work on it.
  31. Golden Rule of Rebasing 44 Never rebase commits that exist

    outside your repository. C1 master DK team remote repository, someone else does work that includes a merge and pushes it up C4 C6 C5
  32. Golden Rule of Rebasing 45 Never rebase commits that exist

    outside your repository. C1 dk/master C2 C3 master My local repo, I’ve fetched and merged into my work. C4 C6 C5 C7
  33. Golden Rule of Rebasing 46 Never rebase commits that exist

    outside your repository. DK Remote Repo, after `git push —force` C1 master C4’ C6 C5 C4
  34. Golden Rule of Rebasing 47 Never rebase commits that exist

    outside your repository. My local repo, after fetching from the server. C1 dk/master C4’ C6 C5 C4 C2 C3 master C7
  35. Golden Rule of Rebasing 48 Never rebase commits that exist

    outside your repository. My local repo, after fetching from the server and merging into my work. C1 dk/master C4’ C6 C5 C4 C2 C3 master C7 C8
  36. Golden Rule of Rebasing 49 If this happens, your challenge

    is to figure out what is yours and what they’re rewritten.
  37. Golden Rule of Rebasing 49 If this happens, your challenge

    is to figure out what is yours and what they’re rewritten. Git calculates another checksum based on the patch introduced with the commit called the patch-id.
  38. Golden Rule of Rebasing 50 Never rebase commits that exist

    outside your repository. My local repo, after merging into my work. C1 dk/master C4’ C6 C5 C4 C2 C3 master C7 C8
  39. Golden Rule of Rebasing 51 Run git rebase dk/master 1.

    What is unique to our branch 2. Which aren’t merge commits 3. Which have not been rewritten into the target branch 4. Apply those commits to the top of dk/master C1 dk/master C4’ C6 C5 C4 C2 C3 master C7
  40. Golden Rule of Rebasing 52 Run git rebase dk/master 1.

    What is unique to our branch 2. Which aren’t merge commits 3. Which have not been rewritten into the target branch 4. Apply those commits to the top of dk/master C1 dk/master C4’ C6 C5 C4 C2 C3 master C7
  41. Golden Rule of Rebasing 53 Run git rebase dk/master 1.

    What is unique to our branch 2. Which aren’t merge commits 3. Which have not been rewritten into the target branch 4. Apply those commits to the top of dk/master C1 dk/master C4’ C6 C5 C4 C2 C3 master C7
  42. Golden Rule of Rebasing 54 Run git rebase dk/master 1.

    What is unique to our branch 2. Which aren’t merge commits 3. Which have not been rewritten into the target branch 4. Apply those commits to the top of dk/master C1 dk/master C4’ C6 C5 C4 C2 C3 master C7
  43. Golden Rule of Rebasing 55 Run git rebase dk/master 1.

    What is unique to our branch 2. Which aren’t merge commits 3. Which have not been rewritten into the target branch 4. Apply those commits to the top of dk/master C1 dk/master C4’ C5 C2’ C3’ master
  44. Golden Rule of Rebasing 56 Always use git pull --rebase

    Set it with: git config --global pull.rebase true Treat rebase as a way to clean-up and work with commits before you push them.
  45. Rebase or Merge? 57 Commit history is the story of

    how your project was made. Rebase Repository’s commit history is a record of what actually happened. Merge
  46. Interactive Staging 58 Craft your commits to include only certain

    combinations and parts of files. !"❱❱❱ git add -i staged unstaged path 1: unchanged +1/-1 README.md 2: unchanged +4/-0 lib/app.rb *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now>
  47. Interactive Staging 59 Craft your commits to include only certain

    combinations and parts of files. What now> 2 staged unstaged path 1: unchanged +1/-1 README.md 2: unchanged +4/-0 lib/app.rb Update>>
  48. Interactive Staging 60 Craft your commits to include only certain

    combinations and parts of files. Update>> 1 staged unstaged path * 1: unchanged +1/-1 README.md 2: unchanged +4/-0 lib/app.rb Update>> updated one path *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now>
  49. Interactive Staging 61 Craft your commits to include only certain

    combinations and parts of files. *** Commands *** 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now> 5 staged unstaged path 1: unchanged +1/-1 README.md Patch update>> 1 staged unstaged path * 1: unchanged +1/-1 README.md
  50. Interactive Staging 62 Craft your commits to include only certain

    combinations and parts of files. Patch update>> diff --git a/README.md b/README.md index f8b7956..2a41661 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,4 @@ This is the skillshare README! -Learning Git is fun! +Learning Git is fun. Stage this hunk [y,n,q,a,d,/,e,?]?
  51. Interactive Staging 63 Craft your commits to include only certain

    combinations and parts of files. Stage this hunk [y,n,q,a,d,/,e,?]? ? y - stage this hunk n - do not stage this hunk q - quit; do not stage this hunk or any of the remaining ones a - stage this hunk and all later hunks in the file d - do not stage this hunk or any of the later hunks in the file g - select a hunk to go to / - search for a hunk matching the given regex j - leave this hunk undecided, see next undecided hunk J - leave this hunk undecided, see next hunk k - leave this hunk undecided, see previous undecided hunk K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks e - manually edit the current hunk ? - print help
  52. Handy Git Knowledge 67 https://git-scm.com/ Blog posts http://reinh.com/blog/2009/03/02/a-git-workflow-for-agile-teams.html https://randyfay.com/content/rebase-workflow-git http://unethicalblogger.com/2010/04/02/a-rebase-based-workflow.html

    http://2ndscale.com/rtomayko/2008/the-thing-about-git https://git-scm.com/ Guides & Tools https://www.atlassian.com/git https://www.git-tower.com/ http://gitready.com/ https://www.khanacademy.org/ computing/computer-science/ algorithms#graph-representation http://rogerdudler.github.io/git-guide/ https://onlywei.github.io/explain-git-with-d3/ https://blog.thoughtram.io/git/2014/11/18/the-anatomy-of- a-git-commit.html
  53. 68

  54. 68