Talk to git
Upcoming SlideShare
Loading in...5

Like this? Share it with your network


Talk to git



A summarize and re-categorize of the git tutorial.

A summarize and re-categorize of the git tutorial.



Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds


Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment
  • How to collaboration?

Talk to git Presentation Transcript

  • 1. Talk to Git Jim Chen
  • 2. VCS and Git
  • 3. Why Version Control? •History is important. •Time travel is possible! o Roll back to old version •Collaboration o Contributors can work at the same time.
  • 4. Local Version Control System •Only on your PC
  • 5. Centralized Version Control System •Server owns all versions. •Clients only have one version.
  • 6. Distributed Version Control System •Every one has a full copy •Recovery friendly
  • 7. History In 2005, relationship between Linux Kernel community and commercial company of BitKeeper broken down for reasons.
  • 8. Goals of Git •Speed •Simple design •Strong support for non-linear development (branches over the world) •Fully distributed •Able to handle large projects efficiently (Linux kernel is really huge)
  • 9. Git Basics
  • 10. Snapshots, Not Differences
  • 11. Nearly Operations are local •Full copy in local computer •Make changes but can keep update with remote •Network independent
  • 12. Integrity •Check-sum based tracking •SHA-1 Hash function •40-characters
  • 13. Generally Only Adds Data •Everything committed will be a snapshot in Git history •Even another commit remove the file.
  • 14. Three States •Committed •Modified •Staged
  • 15. Welcome Aboard
  • 16. Get Repository •Initialize in existing directory $ git init $ git add *.sh $ git commit -m "Initial project version" •Clone from existing repository $ git clone <url>
  • 17. File Status untracked unmodified modified staged add the file remove the file git add <file> git rm <file> commit stage the file edit the file git add <file> git commit git reset HEAD <file> git checkout <file>
  • 18. Checking Status $ git status
  • 19. Tracking New File $ touch README $ git status
  • 20. Tracking New File $ git add README $ git status
  • 21. Staging modfied Make some change in $ git status
  • 22. Staging modfied $ git add $ git status
  • 23. Viewing Unstaged Changes $ vim $ git diff
  • 24. Viewing Staged Changes $ git diff --cached
  • 25. Discard modified $ git status $ git checkout $ git status
  • 26. Unstage staged $ git reset HEAD
  • 27. Commit It $ git commit
  • 28. Guidelines to Commit No whitespaces $ git diff --check • Try to make each commit a logically separate change set. • Getting in the habit of creating quality commit messages. o This would help others to review.
  • 29. More commands •Removing files $ git rm <file> •Moving files $ git mv <file>
  • 30. Viewing History in CLI $ git log
  • 31. Viewing History in GUI $ gitk
  • 32. Oops! Something missed. But committed already...
  • 33. Change Last Commit $ git commit --amend
  • 34. Working with Remote
  • 35. Clone Repository $ git clone <url> <folder>
  • 36. Showing Remotes $ git remote -v
  • 37. Adding and Removing Remotes $ git remote add <remote-name> <url> $ git remote rm <remote-name>
  • 38. Fetching and Pulling from Remotes $ git fetch <remote-name> $ git pull <remote-name> = git fetch + git merge
  • 39. Pushing changes to Remote $ git push <remote-name> <branch-name>
  • 40. Branching
  • 41. Why branches? •Stabilize stables •Make topics no bother
  • 42. Data Structure •Blob o Storing file data •Tree o Structure of project, just like directory •Commit o A pointer to a single tree, with some meta-data •Tag o Mark a commit as special
  • 43. Commit
  • 44. Versions
  • 45. A lightweight movable pointer to one of the commits. Branch in Git is HEAD is a special pointer to the current working branch you are.
  • 46. I want to resolve a topic
  • 47. $ git branch topic1 $ git checkout topic1 C0 C1 C2 master HEAD topic1 HEAD
  • 48. $ git checkout -b topic1 C0 C1 C2 master HEAD topic1 HEAD
  • 49. Commit new change on topic1 C0 C1 C2 master topic1 C3 topic1
  • 50. Urgent!! Bug fix for master
  • 51. Create hotfix branch from master for fix bug (C4) $ git checkout master $ git checkout -b hotfix Fix bug and commit change C0 C1 C2 master topic1 C3 C4 hotfix Quiz: Where is the HEAD? HEAD
  • 52. Merge branches hotfix is good for release
  • 53. Merge Mechanism •Fast-forward Branches are in the same history flow so Git can only change the pointer to the new one. •Three-way merge – Locate the common ancestor – Git automatically calculate how to merge – Create a merge commit recording new snapshot
  • 54. Fast-forward $ git checkout master $ git merge hotfix Updating ... Fast forward C0 C1 C2 master topic1 C3 C4 hotfix master
  • 55. Three-way merge $ git checkout master $ git merge topic1 Merge made by recursive C0 C1 C2 topic1 C3 C4 master C5 Snapshot to merge into Snapshot to merge into Common Ancestor C6 master
  • 56. Gosh... Conflict happens
  • 57. What will you see when merge conflict
  • 58. Resolve and commit the change
  • 59. Rebasing Merge is good but I want a clearer history
  • 60. Merge $ git checkout master $ git merge topic1 Merge made by recursive C0 C1 C2 topic1 C3 C4 C5 C6 master
  • 61. Basic Rebase $ git checkout topic1 $ git rebase master C0 C1 C2 C4 topic1 C3 C5 master topic1 C3' C5'
  • 62. Rebasing pushed commits confuses reviewers. Do not rebase commits have pushed to a public repository!
  • 63. Example of rebasing a pushed commit
  • 64. What's more?
  • 65. Where is the commit lost? Look into commit updated history
  • 66. $ git reflog SHA-1 id you can use Cherry-pick commit d6297c2 $ git cherry-pick d6297c2
  • 67. Stashing New request comes but I am working on something else.
  • 68. $ git stash $ git stash list/pop/apply
  • 69. Interactive Rebase Change multiple commits Reordering
  • 70. Interactive rebase C0 C1 C2 master C3 C4 $ git rebase -i HEAD~2 Successfully rebased and updated refs/heads/master. master C4 C3
  • 71. git official sites: commands: zh book: Git and Linux Kernel: Git Immersion: (Practices) Revision Control: Distributed VCS: References