Professional Documents
Culture Documents
Chapter 1 : Introduction
1.1 (Version Control System : VCS)
Local Version Control System : LVCS
Centralized Version Control System : CVCS
Distributed Version Control System : DVCS
1.2 Git
1.3 Git
Chapter 2 : Git basic
2.1
2.2 Git
Chapter 3 : Installation
3.1 Windows
3.2 Mac OS X
3.3 Others operating system
Chapter 4 : Git scenario
1 : !@#%!@
2 : Remote repo
3 : ,,
4 : Conflict
5 : Alias
6 : Fast Forward 3way Merge
7 : Branch
8 : Commit History
9 : Difference
10 : Reflog
11 : Optimize
12 : Stash
1
1
2
3
4
6
16
18
29
36
38
39
44
50
53
55
55
56
58
60
62
63
63
13 : Tag Commit
14 : ignore
Workflow
Fork Pull Request
Chapter 5 : Git GUI
Chapter 6 :
65
65
66
69
72
76
77
Chapter 1 : Introduction
Git (Version control)
Version control ?
1.1 (Version Control System : VCS)
Version control ( Revision control, Source control)
( & Something like that) Version control
Backup ( )
Version control 3 Local, Centralized Distributed
Local Version Control System : LVCS
Backup
Revision Control System : RCS
Walter F. Tichy
RCS Developer
Tools Mac OS X
Patch
2
Centralized Version Control System : CVCS
Local Version Control
USB Drive
Server Server
Server Server (
)
Project manager
Server Server
Server Harddisk
(Server Client ) Server Log
( Server Server )
Version control Centralized CVS, SourceSafe,
Subversion, Team Foundation Server
3
Distributed Version Control System : DVCS
Centralized Version Control System Server
Distributed
Server
Server Server
Server
Server (
T___T)
Team A Team
B
Server
Centralized Server
Git (), BitKeeper( ), Mercurial, Bazaar Darcs
4
1.2 Git
Linux kernel
. . 19912002 Linus Benedict Torvalds Linux
kernel Patch Source code
( Tarball)
Linus Linux kernel
Linus
Patch
Linus Patch Source code
Patch
2002
DVCS BitKeeper
BitMover BitKeeper Commercial software
Larry McVoy CEO BitMover Open
source
2005 Andrew Tridgell ( "Tridge")
Samba BitKeeper
Open source SourcePuller BitKeeper
client ( Larry McVoy )
Tridge Reverseengineered
BitKeeper Larry Tridge
Metadata
? Tridge
Metadata BitKeeper SourcePuller
Metadata Telnet
BitKeeper server HELP BitKeeper client
Linus Tridge
Tridge Tridge Tridge
Larry 3
5
BitKeeper server Tridge Linus
Community Open source License
Community ( Tools BitKeeper )
Linus Project Linux Git
, ,
Git
Global information
tracker "Goddamn idiotic
truckload of sh*t" ( )
Linus Version control
Linux kernel
Version control BitKeeper Version control
( branch )
Distributed Version Control System
Linux kernel ( )
Git 3 2005 C,Shell script Perl, 6
Git Open source GNU GPL version 2
Selfhosting ( Git Source code Git ) 7 , Branch
18 29 ( Patch Linux kernel
Tree 6.7 ) 26 2005 Linus Junio Hamano Git
6
1.3 Git
Version control (
) Version control (
) Git
Version control CVS, Subversion, Perforce, Bazaar
Delta Storage ( Differences )
3 Commit ( Version )
Commit 1 A, B C
Commit 2 ( )
A B C C ( C )
Pointer C Commit 1
Commit 3 A Pointer Commit
Commit 2 B C Commit 2
Commit 3 C Pointer Commit ( Commit 2
) Commit 2 Pointer C
C Commit 1 C Pointer
7
Commit Commit
Commit Commit
Reverse File
Forward File Delta
3 A , B C
Commit 1 Commit Snapshot
Snapshot A1,B1
C1
Commit 2 A B Snapshot A2 B2
C Reference Snapshot C1
Commit 3 A Reference Snapshot A2 Snapshot
A1 B C Snapshot B3 C2
2 Delta storage
Snapshot storage Git Storage Snapshot ( Git git pack
Delta )
9
Git Snapshot Hash SHA1 ( ) 160 Bits
SHA1 40 (09 af)
Checksum Checksum
Checksum
SHA1
10
Git Snapshot 40
Checksum Snapshot 3 c3d, f13, 6d4 84f
3 40 ( 3
) Git Commit Commit KeyValue
Key Snapshot Value
Git
Commit Snapshot
Snapshot
11
Git Add Commit
Git
Snapshot
4
Untrack Git Git
Stack trace, Error Track
Committed Commit Git
Committed
Modified Git Staged Commit
Git
Staged Commit Untrack Modified
Git Staged
Commit ( Config
Commit )
12
13
Git object model
Git Hash SHA1 40
Object
6ff87c4664981e4397625791c8ea3bbb5f2279a3
Object 3 Type Object , Size
Object Content Type Object 4
Blob,Tree,Commit Tag Pointer Object
Git
Blob Binary Large Object
Object Metadata
14
Commit Tree Commit
+ Tree Tree
+ Parent Commit
+ Author
+ Committer Commit
Object Model
15
Flow Commit Git (cc: schacon.github.io) Git commit
Tree Tree Tree Blob
Snapshot Commit
16
17
Add
Add Snapshot Add
Staging area Commit Snapshot
Git Repository Commit
Commit
Commit
Commit Commit
? Commit Snapshot Staging area Git
Repository
Commit
Branch
Commit Branch Git Branch
Switch
Remote
Remote Repository Git
Repo Official version Git
Server DVCS Repo
Code Repo Repo
Repo ( Merge
)
Push
Update Remote repository
Pull
Remote repository
Merge
Branch Master
Branch Dev_send_email
Merge Master
18
Master Master
2.2 Git
$ git config
Log Git
$ git config global user.name AorJoa
19
$ git clone
Remote Repo
Git init Git clone
Remote Repo
.git Clone Repo
https://github.com/chanwit/spockreporthtml.git
$ git clone https://github.com/chanwit/spockreporthtml.git Clone Remote Repo
$ git status
$ git status
$ git add
Staging area Commit Git Repo
$ git add .
20
$ git mv
$ git mv Space
$ git mv sub_folder/test.txt sub_folder/bio.txt
21
$ git commit
Staging area Git Repository $ git
commit m
Commit
$ git commit m "Initial Git basic" Commit
22
$ git rm
$ git rm $ git remove
r
$ git rm r sub_folder
Git
2 Commit
Git Repo
Commit Commit
$ git branch
Branch
Branch Branch
$ git branch
Branch
$ git branch dev
Branch dev
$ git branch d dev Branch dev
$ git checkout
Branch Commit Branch
$ git checkout dev
Branch dev Branch dev
$ git checkout b dev
Branch dev Checkout
$git branch dev $git checkout dev
23
$ git merge
Branch Branch
about.html Branch background_red master
Checkout master Merge background_red
master master about.html
$ git checkout b background_red background_red
24
$ git remote
Remote repository
Repository Remote repository
origin Server Github.com Repository
Path https://github.com/Aorjoa/basic_git.git
$ git remote add origin https://github.com/Aorjoa/basic_git.git
25
$ git fetch
Remote Repo
( Remote Repo Update Local Repo
Remote Repo
Working directory )
Merge Merge
Working directory
$ git fetch origin master Remote Repo origin ( Branch master)
$ git pull
git pull git fetch git merge
git fetch git merge Merge
git pull
$ git pull origin master Remote Repo origin Local repo
Remote repo Merge Branch )
26
$ git rebase
Branch Merge Rebase
Rebase commit Push Remote repo Rebase
Branch master Feature
Bug Branch master Bug Branch
Feature master Rebase
Branch Feature Bug
27
$ git log
Log
Commit Hash SHA1
Commit
$ git log
Repository
Commit Commit
Branch
$ git reset
2 soft reset
soft Commit hard reset hard
Commit ( Snapshot Reset )
git reset hard
$ git reset hard ed51e23
28
$ git revert
$
git reset
Commit
$ git revert noedit ed51e23..HEAD
Commit ed51e23
HEAD
( Conflict
) Commit 2 ca764a3 4e8849b noedit
Comment Commit Revert Comment
Commit Revert Commit
(Add line two Add line one)
Flow Git
29
Chapter 3 : Installation
Version control, Git Git
Git
========================================================================
3.1 Windows
========================================================================
1) http://gitscm.com/downloads
Download Windows
2) Git
30
Installer Next
31
Next
32
Component Next
Shortcut Next
33
: Git Git Bash
: Windows Command Prompt Git
: Windows Command Prompt Git UNIX
( Command CMD )
Next
34
Windows UNIX
Platform Next
35
View ReleaseNotes.rtf Finish
Version Git
36
========================================================================
3.2 Mac OS X
========================================================================
1) http://gitscm.com/downloads Download Mac OS X
2) Git
37
Continue
38
========================================================================
3.3 Others operating system
========================================================================
Donwload http://gitscm.com/downloads
39
Git Git
Mac OS X Source
code Software
Windows Git bash
UNIX Git bash ( Command Prompt)
1 : !@#%!@
$ git config global user.name AorJoa
( )
$ git config global user.email aorjoa@iaor.com
Email
$ git config global color.ui true
$ git config global user.ui true
2
Git flow
$ git init Repository Git
40
readme.txt $ nano readme.txt nano Text editor Unix
Notepad
Ctrl + X ( X )
Save Y
Enter nano
Command ls
41
$ git rm r recursive
$ git rm r Git
Working directory
$ git mv
42
readme.txt Untracked files
git add $ git add readme.txt $ git status
Change to be committed
Staging area ( Snapshot) $ git commit m "Initial Git repository"
Snapshot Staging area Git
43
$ git log Commit
Remote repo
44
2 : Remote repo
.zip .tar Tarball
Email
Email Version control Git
Remote repositoy
Git remote
repository Github.com, Gitlab.org Bitbucket.org
Remote repo Github.com
Tutorial try.github.io
Portfolio (
Octocat Github >__<)
StepbyStep
(1) https://www.github.com
45
(3) Finish sign up Email Github
link Confirm
Repo
46
Enter file in which to save the key (/Users/dekcom/.ssh/id_rsa): Enter
/Users/dekcom/.ssh/id_rsa already exists.
Overwrite (y/n)? y ()
Enter passphrase (empty for no passphrase): Passphrase (
) Enter
Enter same passphrase again: Passphrase
Private key (identification) Public key
Your identification has been saved in /Users/dekcom/.ssh/id_rsa.
Your public key has been saved in /Users/dekcom/.ssh/id_rsa.pub.
Public key
$ cat ~/.ssh/id_rsa.pub
Github
47
github.com Public key github Setting
> SSH Keys > Title ( ) > Key > Add key
(5) Repository
> New repository
> Repo
48
> Repo
Create repository
49
Passphrase OK ( OS Command line )
readme.txt
readme.txt
50
3 : ,,
3 Checkout, Revert Reset
$ git status Commit
Working directory
Clean Conflict
> Checkout
Checkout
Branch
Commit
Checkout Branch master
51
(4) $ git branch Detached branch branch checkout
branch
> Revert
Revert Commit
Commit
Revert Commit B Commit D
Commit C Commit
Revert
Revert Commit A Revert Commit A HEAD Conflict (
Conflict Conflict)
(1) Log $ git log
52
(3) $ git log Revert commit 2e7885
(4) readme.txt
> Reset
Reset
Spec Software
2 Commit
2 Commit
Commit
soft hard
53
4 : Conflict
Version control Conflict
Conflit Conflict
git
Branch master (Remote repo) Push Github Branch master
(Local repo) Git
(1) Github Push
Commit ( 3) Branch
Branch master
Conflict
54
(3) Editor
Commit
(4) Log
55
5 : Alias
Alias
$ git log graph decorate pretty=oneline abbrevcommit all alias lol $ git
config global add alias.lol "log graph decorate pretty=oneline abbrevcommit all"
56
7 : Branch
Branch
Branch Brach
Branch Branch Branch
> Local branch
Branch Local $ git checkout b 'bugfix' $ git branch
57
Github Remote repo ( origin) Branch issue
Branch Branch issue ( Branch bugfix Local repo )
master Branch master
Checkout master
58
8 : Commit History
Commit
readme.txt Commit !
Commit Commit (
Commit Comment Done
Commit Done#2 )
> Commit
Commit ( Commit ) $ git commit amend
m 'Edit comment' Comment Commit
59
(2) $ git rebase i 8ba8bb9
Commit base 8ba8bb9 ( Commit 8456e87
base)
:wq
Git Rebase Conflict
60
readme.txt both modified
readme.txt Conflict
Commit
9 : Difference
Version control Option
Git $ git diff
Commit $ git diff
61
Branch $ git diff master dev
62
$ git whatchanged since="2 day ago" oneline $ git whatchanged since="2
weeks ago" oneline
10 : Reflog
Git 23
!! $ git reset
Commit Holy Sh**t !
Git Git
Commit, Checkout Reflog $ git reflog
63
$ git cherrypick af13edd Commit af13edd ( Commit Reflog)
11 : Optimize
Git Local repo Repo
Reflog
$ git gc
Delta compression
12 : Stash
Pull, Merge, Rebase Working
directory Commit
$ git stash Pull, Merge, Rebase Working directory
$ git stash pop
64
$ git status
$ git stash
65
13 : Tag Commit
Object Git Tag object
git tag a v1.0 d256a7f m 'Tag release V.1.0' ( Tag
tags Push $ git push origin tags
14 : ignore
Git
.war Deploy Git .gitignore
.gitignore $ git add .gitignore
Git readyou.me
66
Workflow
Branch
Flow Clone > Branch dev
> Branch dev > Merge Checkout master > Pull
Branch master > Checkout branch dev > Rebase branch dev >
Checkout master > Merge branch dev > Push Remote repo
Flow ()
Dev ( ) hotfix ( )
Merge Master master Tag 0.2 Dev
Merge hotfix Dev
67
68
(cc : http://nvie.com/posts/asuccessfulgitbranchingmodel)
69
(2) Fork
Fork
(3) Repo Fork
Pull Request
Fork repo Repo Guthub Repo
Pull Request Fork Library
graph
Library graph Pull Request Repo
Pull Request
(1) Repo Fork
70
Repo Fork
71
Pull Request
Repo
(1) inbox message
Update readme.txt
(4) Request
72
(2) (
)
(3) Settings
73
(6) Remote repo Add
(10)
74
(13)
(16) Commit
75
(19) Push Origin (Github) Branch master
(21) Gitghub
76
Chapter 6 :
77
Blog Blog
( Tag ) Git
Git Clone (>.<)
Community
Git :
https://www.facebook.com/groups/440497309296387
Creative Common 4.0
Email : bhuridech@gmail.com
Website : www.iaor.com
WebBlog : aorjoa.blogspot.com
GitHub : https://github.com/Aorjoa
Source code