SlideShare uma empresa Scribd logo
1 de 71
Talk to Git
Jim Chen
VCS and Git
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.
Local Version Control System
•Only on your PC
Centralized Version Control
System
•Server owns all
versions.
•Clients only
have one
version.
Distributed Version Control
System
•Every one has a
full copy
•Recovery friendly
History
In 2005, relationship between Linux Kernel
community and commercial company of
BitKeeper broken down for reasons.
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)
Git Basics
Snapshots, Not Differences
Nearly Operations are local
•Full copy in local
computer
•Make changes but can
keep update with
remote
•Network independent
Integrity
•Check-sum based
tracking
•SHA-1 Hash
function
•40-characters
Generally Only Adds Data
•Everything committed will be a snapshot in
Git history
•Even another commit remove the file.
Three States
•Committed
•Modified
•Staged
Welcome Aboard
Get Repository
•Initialize in existing directory
$ git init
$ git add *.sh
$ git commit -m "Initial project version"
•Clone from existing repository
$ git clone <url>
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>
Checking Status
$ git status
Tracking New File
$ touch README
$ git status
Tracking New File
$ git add README
$ git status
Staging modfied
Make some change in hello.sh
$ git status
Staging modfied
$ git add hello.sh
$ git status
Viewing Unstaged Changes
$ vim hello.sh
$ git diff
Viewing Staged Changes
$ git diff --cached
Discard modified
$ git status
$ git checkout hello.sh
$ git status
Unstage staged
$ git reset HEAD hello.sh
Commit It
$ git commit
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.
More commands
•Removing files
$ git rm <file>
•Moving files
$ git mv <file>
Viewing History in CLI
$ git log
Viewing History in GUI
$ gitk
Oops!
Something missed.
But committed already...
Change Last Commit
$ git commit --amend
Working with Remote
Clone Repository
$ git clone <url> <folder>
Showing Remotes
$ git remote -v
Adding and Removing Remotes
$ git remote add <remote-name> <url>
$ git remote rm <remote-name>
Fetching and Pulling from
Remotes
$ git fetch <remote-name>
$ git pull <remote-name>
= git fetch + git merge
Pushing changes to Remote
$ git push <remote-name> <branch-name>
Branching
Why branches?
•Stabilize stables
•Make topics no bother
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
Commit
Versions
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.
I want to resolve a
topic
$ git branch topic1
$ git checkout topic1
C0 C1 C2
master
HEAD
topic1
HEAD
$ git checkout -b topic1
C0 C1 C2
master
HEAD
topic1
HEAD
Commit new change on topic1
C0 C1 C2
master
topic1
C3
topic1
Urgent!!
Bug fix for master
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
Merge branches
hotfix is good for
release
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
Fast-forward
$ git checkout master
$ git merge hotfix
Updating ...
Fast forward
C0 C1 C2
master
topic1
C3
C4
hotfix
master
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
Gosh...
Conflict happens
What will you see when merge conflict
Resolve and commit the change
Rebasing
Merge is good but
I want a clearer history
Merge
$ git checkout master
$ git merge topic1
Merge made by recursive
C0 C1 C2
topic1
C3
C4
C5
C6
master
Basic Rebase
$ git checkout topic1
$ git rebase master
C0 C1 C2
C4
topic1
C3 C5
master
topic1
C3' C5'
Rebasing pushed commits confuses
reviewers.
Do not rebase commits
have pushed to a public
repository!
Example of rebasing a pushed commit
What's more?
Where is the commit
lost?
Look into commit updated history
$ git reflog
SHA-1 id you can use
Cherry-pick commit d6297c2
$ git cherry-pick d6297c2
Stashing
New request comes but I am
working on something else.
$ git stash
$ git stash list/pop/apply
Interactive Rebase
Change multiple commits
Reordering
Interactive rebase
C0 C1 C2
master
C3 C4
$ git rebase -i HEAD~2
Successfully rebased and updated refs/heads/master.
master
C4 C3
git official sites: http://git-scm.com
commands: http://git-scm.com/book/commands
zh book: http://git-scm.com/book/zh
Git and Linux Kernel: http://en.wikipedia.org/wiki/Linux_kernel#Revision_control
Git Immersion: http://gitimmersion.com (Practices)
Revision Control: http://en.wikipedia.org/wiki/Revision_control
Distributed VCS: http://en.wikipedia.org/wiki/Distributed_revision_control
References

Mais conteúdo relacionado

Mais procurados (20)

Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
 
Git Basics at Rails Underground
Git Basics at Rails UndergroundGit Basics at Rails Underground
Git Basics at Rails Underground
 
Git basic
Git basicGit basic
Git basic
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Git commands
Git commandsGit commands
Git commands
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
 
Git learning
Git learningGit learning
Git learning
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to git
 
Basic principles of Git
Basic principles of GitBasic principles of Git
Basic principles of Git
 
Git Rebase vs Merge
Git Rebase vs MergeGit Rebase vs Merge
Git Rebase vs Merge
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Git Terminologies
Git TerminologiesGit Terminologies
Git Terminologies
 
Git & GitHub WorkShop
Git & GitHub WorkShopGit & GitHub WorkShop
Git & GitHub WorkShop
 
Git - The Incomplete Introduction
Git - The Incomplete IntroductionGit - The Incomplete Introduction
Git - The Incomplete Introduction
 

Semelhante a Talk to git

The Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubThe Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubBigBlueHat
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthroughBimal Jain
 
Introduction to git, an efficient distributed version control system
Introduction to git, an efficient distributed version control systemIntroduction to git, an efficient distributed version control system
Introduction to git, an efficient distributed version control systemAlbanLevy
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configurationKishor Kumar
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitRobert Lee-Cann
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshopthemystic_ca
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github Max Claus Nunes
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developersAidan Casey
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdfTilton2
 

Semelhante a Talk to git (20)

3 Git
3 Git3 Git
3 Git
 
The Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubThe Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHub
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
Working with Git
Working with GitWorking with Git
Working with Git
 
Git-r-Done
Git-r-DoneGit-r-Done
Git-r-Done
 
Git tips
Git tipsGit tips
Git tips
 
Introduction into Git
Introduction into GitIntroduction into Git
Introduction into Git
 
Introduction to git, an efficient distributed version control system
Introduction to git, an efficient distributed version control systemIntroduction to git, an efficient distributed version control system
Introduction to git, an efficient distributed version control system
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developers
 
Git
GitGit
Git
 
Wokshop de Git
Wokshop de Git Wokshop de Git
Wokshop de Git
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
 

Último

Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan
 
E J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxE J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxJackieSparrow3
 
Inspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxInspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxShubham Rawat
 
(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)oannq
 
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...JeylaisaManabat1
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证kbdhl05e
 

Último (6)

Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
Authentic No 1 Amil Baba In Pakistan Amil Baba In Faisalabad Amil Baba In Kar...
 
E J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptxE J Waggoner against Kellogg's Pantheism 8.pptx
E J Waggoner against Kellogg's Pantheism 8.pptx
 
Inspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptxInspiring Through Words Power of Inspiration.pptx
Inspiring Through Words Power of Inspiration.pptx
 
(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)(南达科他州立大学毕业证学位证成绩单-永久存档)
(南达科他州立大学毕业证学位证成绩单-永久存档)
 
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
Module-2-Lesson-2-COMMUNICATION-AIDS-AND-STRATEGIES-USING-TOOLS-OF-TECHNOLOGY...
 
南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证南新罕布什尔大学毕业证学位证成绩单-学历认证
南新罕布什尔大学毕业证学位证成绩单-学历认证
 

Talk to git

Notas do Editor

  1. How to collaboration?