git
DESCRIPTION
NCCU 103 Data Structure TA CourseTRANSCRIPT
V E R S I O N C O N T R O L :
G I T
2 0 1 4 . 1 1 . 1 9 W I L L I A M W A N G
1
W H A T I S V E R S I O N C O N T R O L
2
A simple database that kept
all the changes to files under
revision control
L O C A L V E R S I O N C O N T R O L
S Y S T E M S
3
L V C S P R O B L E M :
People need to collaborate with
developers on other systems.
C V C S S O L U T I O N :
A single server that contains all the
versioned files, and a number of
clients that check out files from that
central place.
C E N T R A L I Z E D V E R S I O N
C O N T R O L S Y S T E M S
4
D I S T R I B U T E D V E R S I O N
C O N T R O L S Y S T E M S
L V C S , C V C S P R O B L E M :
Whenever you have the entire
history of the project in a single
place, you risk losing everything.
D V C S S O L U T I O N :
In a DVCS (such as Git, Mercurial,
Bazaar or Darcs), clients don’t just check
out the latest .snapshot of the files: they
fully mirror the repository.
5
I N T R O D U C E G I T
• The origin of all things - Linux Kernel (1991–
2002)
• From BitKeeper to Git(2005)-Linus Torvalds
(Linux Creator) and the community develop their
own tool based on some of the lessons they
learned while using BitKeeper.
• Fast Speed(write in C)、Simple Design、Strong
support for non-linear development(Thousands
of parallel branches) 、Fully Distributed、Able
to handle large projects
• Who use git for developing?
• Eclipse,RoR,Android,jQuery,PHP……
O T H E R V C S
7
M O S T O T H E R S Y S T E M S S T O R E I N F O R M A T I O N A S A L I S T O F
F I L E - B A S E D C H A N G E S
G I T
8
1 . E V E R Y T I M E Y O U C O M M I T , O R S A V E T H E S T A T E . I T B A S I C A L L Y T A K E S
A P I C T U R E O F W H A T A L L Y O U R F I L E S L O O K L I K E A T T H A T M O M E N T
A N D S T O R E S A R E F E R E N C E T O T H A T S N A P S H O T .
2 . I F F I L E S H A V E N O T C H A N G E D , G I T D O E S N ’ T S T O R E T H E F I L E A G A I N ,
J U S T A L I N K T O T H E P R E V I O U S I D E N T I C A L F I L E I T H A S A L R E A D Y
S T O R E D .
3 . G I T T H I N K S A B O U T I T S D A T A M O R E L I K E A S T R E A M O F S N A P S H O T S .
G I T B A S I C S
• Nearly Every Operation Is Local
• You have the entire history of the project right there on your local disk.
• Git Has Integrity
• Everything in Git is check-summed before it is stored and is then
referred to by that checksum.
• Git uses SHA-1 hash for checksumming and it calculated based on the
contents of a file or directory structure in Git.Looks like: 24b9da6552252987aa493b52f8696cd6d3b00373
• Git Generally Only Adds Data
• The Three States
G I T B A S I C S - T H E T H R E E S T A T E S
• Three main sections of a Git project: Git directory, Working directory, Staging area.
• Three main states that your files can reside in: Committed, Modified, Staged.
• Committed means that the data is safely stored in your local database.
• Modified means that you have changed the file but have not committed it to your database yet.
• Staged means that you have marked a modified file in its current version to go into your next
commit snapshot
I N S T A L L G I T ( M A C , L I N U X … )
• Mac OS X
• OS X has default git, so if you want to get the latest
version, you can use some pkm(mac ports,homebrew…)
• Linux
• Debian-based:#apt-get install git
• Redhat-based:#yum install git
• …
11
I N S T A L L G I T ( W I N D O W S )
12
I N S T A L L G I T ( W I N D O W S )
13
I N S T A L L G I T ( W I N D O W S )
14
I N S T A L L G I T ( W I N D O W S )
15
I N S T A L L G I T ( W I N D O W S )
16
I N S T A L L G I T ( W I N D O W S )
17
I N S T A L L G I T ( W I N D O W S )
18
19
I N S T A L L G I T ( W I N D O W S )
20
I N S T A L L G I T ( W I N D O W S )
21
I N S T A L L G I T ( W I N D O W S )
G I T C O M M A N D
mkdir helloGit
cd helloGit
git init
G I T C O M M A N D
23
echo ‘Hi,git’> README.md
git status
git add READE.md
git status
git commit -m ‘First commit with README’
git status
G I T C O M M A N Dgit remote add origin URL
git push -u origin --all
GitHub大冒險 by Muan@JSDC2014:https://www.youtube.com/watch?v=5YX33tyJfOI&index=21&list=PL8dIIwCMF-SN8ZOY1NgSrj-WkYb112glF
Teaching Git and GitHub with Node.js by
Jessica@JSDC2014:https://www.youtube.com/watch?v=vH8koy9DtLY&index=14&list=PL8dIIwCMF-SN8ZOY1NgSrj-WkYb112glF
G I T C O M M A N D
25
git branch
git branch newBranch
git branch
git checkout newBranch
echo ‘This is a newBranch edit’ >> README.md
git status
git add .
git commit -m ‘commite on newBranch and edit README.md’
git checkout master
echo ‘Try to make some confilts’ >> README.md
git add . && git commit ‘master edit before merge’
git merge newBranch
//Solve the conflict
git add .
git commit -m ‘We merge these two branches’
git push -u origin --all
T R Y M O R E
26
git clone [URL]
git checkout [commit hash value]
git rebase [branch name]
…
…
…
For you to reference:
http://blog.gogojimmy.net/2012/02/29/git-scenario/
http://www.draconianoverlord.com/git-workshop.html
http://isis.apache.org/contributors/git-cookbook.html
https://github.com/ulrich/useful-git-command
P R A C T I C E : G I T I T
27
• git it:https://github.com/jlord/git-it
R E F E R E N C E
Git:
http://git-scm.com/
CodeSchool Try Git:
https://www.codeschool.com/courses/try-git
ihower’s blog:
http://ihower.tw/git/
gugod’s blog:
http://gugod.org/2009/12/git-graphing/
唐維佋’s slides:
http://www.slideshare.net/pa4373/git-git-hub-34165878
Hsiao-Ting Yu’s slides:
http://www.slideshare.net/littlebtc/git-5528339
28
T H A N K S ,
A N D
H A P P Y W I T H G I T