SlideShare a Scribd company logo
自由軟體鑄造場作業暨智財權說明會 
版本控制系統與科技部專案(以Git為例) 
中研院資訊創新科技研究中心 
自由軟體鑄造場蘇展 
Oct. 6
Code Hosting Sites 
1
Johnson J. Su 
Linkedin:https://www.linkedin.com/in/jansu 
E-mail:johnsonsu@iis.sinica.edu.tw 
TEL:(02) 2788-3799 ext. 1478 
2
Git版本控制教學 
科技部專案操作與資源表列 
Topics 
3
SAME ISSUES! 
4
SAME ISSUES! Collaboration Issues! 
5
YOU NEED VCS 
6
GitBasic 
Topics 
GitWorkflow 
GitHub Flow 
7
GitBasic 
Topic 
8
What is Git? 
GitBasic 
9
Git is an open source, distributed version control system designed for speed and efficiency 
GitBasic 
10
Gitis an open source, distributed version control system designed for speed and efficiency 
GitBasic 
11
Gitis an open source, distributedversion control system designed for speed and efficiency 
GitBasic 
12
GitBasic 
13
GitBasic 
14
GitBasic 
15
Fully Distributed 
GitBasic 
16
(almost) everything is local 
GitBasic 
17
which means 
GitBasic 
18
which means 
everything is fast 
GitBasic 
19
which means 
everything is fast 
every clone is a backup 
GitBasic 
20
which means 
everything is fast 
every clone is a backup 
work offline 
GitBasic 
21
No Network Needed 
GitBasic 
22
No Network Needed 
Performing a diff 
GitBasic 
23
No Network Needed 
Performing a diff 
Viewing file history 
GitBasic 
24
No Network Needed 
Performing a diff 
Viewing file history 
Committing changes 
GitBasic 
25
No Network Needed 
Performing a diff 
Viewing file history 
Committing changes 
Merging branches 
Obtaining other revisions of a file 
GitBasic 
26
No Network Needed 
Performing a diff 
Viewing file history 
Committing changes 
Merging branches 
Obtaining other revisions of a file 
Switching branches 
GitBasic 
27
(almost) never removes data 
GitBasic 
29
Compare with svn… 
GitBasic 
30
Snapshots, not Patches 
GitBasic 
31
File Based 
Delta Storage 
GitBasic 
32
First… 
Let’s make an example of svn 
GitBasic 
33
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
34
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
README.txt 
hello.c 
Commit 
A 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
. 
35
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
README.txt 
hello.c 
Commit 
A 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
. 
36
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
README.txt 
hello.c 
Commit 
A 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
. 
37
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
Commit 
B 
-printf("Hellon"); 
+ printf(“Jellon"); 
README.txt 
hello.c 
Commit 
A 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
. 
38
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
Commit 
B 
-printf("Hellon"); 
+ printf(“Jellon"); 
README.txt 
hello.c 
Commit 
A 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
. 
39
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
Commit 
B 
-printf("Hellon"); 
+ printf(“Jellon"); 
README.txt 
hello.c 
Commit 
A 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
. 
40
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
Commit 
B 
-printf("Hellon"); 
+ printf(“Jellon"); 
README.txt 
hello.c 
Commit 
A 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
. 
jello.c 
(rename) 
Commit 
C 
41
This is Johnson Su’s jelloproject. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
Commit 
B 
-printf("Hellon"); 
+ printf(“Jellon"); 
README.txt 
hello.c 
Commit 
A 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
. 
jello.c 
(rename) 
Commit 
C 
42
This is Johnson Su’s jelloproject. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
Commit 
B 
-printf("Hellon"); 
+ printf(“Jellon"); 
README.txt 
hello.c 
Commit 
A 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
. 
jello.c 
(rename) 
Commit 
C 
43
This is Johnson Su’s jelloproject. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
Commit 
B 
-printf("Hellon"); 
+ printf(“Jellon"); 
README.txt 
hello.c 
Commit 
A 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
. 
jello.c 
(rename) 
Commit 
C 
Commit 
D 
-excellent 
+ Jello 
(rename) 
44
This is Johnson Su’s jelloproject. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
Commit 
B 
-printf("Hellon"); 
+ printf(“Jellon"); 
README.txt 
hello.c 
Commit 
A 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
. 
jello.c 
(rename) 
Commit 
C 
Commit 
D 
-excellent 
+ Jello 
(rename) 
45
GitSnapshots 
GitBasic 
46
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
47
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
CHECKSUM 
48
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
CHECKSUM 
49
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
50
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
51
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
Commit 
A 
c3dREADME.txt 
f13hello.c 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
52
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
Commit 
A 
c3dREADME.txt 
f13hello.c 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
53
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
54
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
Commit 
B 
c3dREADME.txt 
6d4hello.c 
#include<stdio.h> 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
6d4 
55
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
Commit 
B 
c3dREADME.txt 
6d4hello.c 
#include<stdio.h> 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
6d4 
56
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
Commit 
B 
c3dREADME.txt 
6d4hello.c 
#include<stdio.h> 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
6d4 
57
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
Commit 
B 
c3dREADME.txt 
6d4hello.c 
#include<stdio.h> 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
6d4 
58
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
Commit 
B 
c3dREADME.txt 
6d4hello.c 
#include<stdio.h> 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
6d4 
Commit 
C 
c3dREADME.txt 
6d4jello.c 
59
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
Commit 
B 
c3dREADME.txt 
6d4hello.c 
#include<stdio.h> 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
6d4 
Commit 
C 
c3dREADME.txt 
6d4jello.c 
60
This is Johnson Su’s excellent project. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
Commit 
B 
c3dREADME.txt 
6d4hello.c 
#include<stdio.h> 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
6d4 
Commit 
C 
c3dREADME.txt 
6d4jello.c 
61
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
Commit 
B 
c3dREADME.txt 
6d4hello.c 
#include<stdio.h> 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
6d4 
Commit 
C 
c3dREADME.txt 
6d4jello.c 
This is Johnson Su’s Jelloproject. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
62
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
Commit 
B 
c3dREADME.txt 
6d4hello.c 
#include<stdio.h> 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
6d4 
Commit 
C 
c3dREADME.txt 
6d4jello.c 
This is Johnson Su’s Jelloproject. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
63
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
Commit 
B 
c3dREADME.txt 
6d4hello.c 
#include<stdio.h> 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
6d4 
Commit 
C 
c3dREADME.txt 
6d4jello.c 
This is Johnson Su’s Jelloproject. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
This is Johnson Su’s Jelloproject. 
Licensed under GPL. 
84f 
64
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
Commit 
B 
c3dREADME.txt 
6d4hello.c 
#include<stdio.h> 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
6d4 
Commit 
C 
c3dREADME.txt 
6d4jello.c 
This is Johnson Su’s Jelloproject. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
This is Johnson Su’s Jelloproject. 
Licensed under GPL. 
84f 
Commit 
D 
84fREADME.txt 
6d4jello.c 
6d4hello.c 
65
This is Johnson Su’s excellent project. 
Licensed under GPL. 
#include<stdio.h> 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
c3d 
f13 
Commit 
A 
c3dREADME.txt 
f13hello.c 
Commit 
B 
c3dREADME.txt 
6d4hello.c 
#include<stdio.h> 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
6d4 
Commit 
C 
c3dREADME.txt 
6d4jello.c 
This is Johnson Su’s Jelloproject. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
jello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Jellon”); 
return 0; 
} 
This is Johnson Su’s Jelloproject. 
Licensed under GPL. 
84f 
Commit 
D 
84fREADME.txt 
6d4jello.c 
6d4hello.c 
66
67 
GitBasic
68 
GitBasic 
Gitcommands 
(Live demo)
Beforewe start 
to use Gitrepository…… 
69 
GitBasic
http://git-scm.com/ 
GitInstallation 
70 
GitBasic
$ gitconfig--global user.name “Johnson J. Su” 
$ gitconfig--global user.email“johnsonsu@iis.sinica.edu.tw” 
Setting Up Git 
$ gitconfig--global color.uiture 
71 
GitBasic
Let’s start using Git 
first… 
Create or Clone a Gitrepository 
72 
GitBasic
Two way to get Gitrepository… 
$ gitclone https://example.com/example.git 
$ mkdirproject 
$ cd project 
$ gitinit 
gitclone repository from remote server 
gitinitial a repository in local system 
73 
GitBasic
74 
GitBasic 
Johnson creates README.txt file 
Add file to staging area 
Commit changes 
Johnson modifies README.txt file & adds hello.c 
Add both file to staging area 
Commit changes
Untracked 
Unmodified 
Modified 
Staged 
initial 
gitinit 
File Status Lifecycle 
75 
GitBasic
$ mkdirproject 
$ cd project 
$ touch README.txt 
$ gitinit 
$ tree -a 
Use the following commands: 
76 
GitBasic
Untracked 
Unmodified 
Modified 
Staged 
initial 
gitinit 
add the file 
1.gitadd filename 
2.gitcommit 
File Status Lifecycle 
77 
GitBasic
$ gitadd . 
$ gitstatus 
$ gitcommit –m “Initial commit” 
Use the following commands: 
78 
GitBasic
Untracked 
Unmodified 
Modified 
Staged 
initial 
gitinit 
add the file 
add/edit the file 
gitadd filename 
File Status Lifecycle 
79 
GitBasic
README.txt 
Use the following commands: 
80 
GitBasic
$ vim README.txt 
Use the following commands: 
This is Johnson Su’s excellentproject. 
Licensed under GPL. 
README.txt 
81 
GitBasic
$ vim README.txt 
$ touch hello.c 
Use the following commands: 
This is Johnson Su’s excellentproject. 
Licensed under GPL. 
README.txt 
hello.c 
82 
GitBasic
$ vim README.txt 
$ touch hello.c 
$ vim hello.c 
Use the following commands: 
This is Johnson Su’s excellentproject. 
Licensed under GPL. 
README.txt 
hello.c 
83 
GitBasic
$ vim README.txt 
$ touch hello.c 
$ vim hello.c 
Use the following commands: 
This is Johnson Su’s excellentproject. 
Licensed under GPL. 
README.txt 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
84 
GitBasic
Untracked 
Unmodified 
Modified 
Staged 
initial 
gitinit 
add the file 
add/edit the file 
stage the file 
gitadd filename 
gitadd filename 
File Status Lifecycle 
85 
GitBasic
$ gitadd . 
$ gitstatus 
$ gitcommit –m “modify README.txt and add hello.cfile” 
Use the following commands: 
The commit message must be very clear!! 
(Recommend) 86 
GitBasic
Untracked 
Unmodified 
Modified 
Staged 
initial 
gitinit 
add the file 
add/edit the file 
stage the file 
gitadd filename 
Commit a version 
gitadd filename 
gitcommit 
File Status Lifecycle 
87 
GitBasic
Untracked 
Unmodified 
Modified 
Staged 
initial 
gitinit 
add the file 
add/edit the file 
stage the file 
gitadd filename 
Commit a version 
Remove the file 
gitadd filename 
gitcommit 
gitrmfilename 
File Status Lifecycle 
88 
GitBasic
$ gitstatus 
$ gitrmhello.c 
$ gitstatus 
Use the following commands: 
89 
GitBasic
90 
GitBasic
Untracked 
Unmodified 
Modified 
Staged 
initial 
gitinit 
add the file 
add/edit the file 
stage the file 
gitadd filename 
Commit a version 
gitadd filename 
gitcommit 
File Status Lifecycle 
add/edit the file 
gitcheckout filename 
91 
GitBasic
$ vim hello.c 
Use the following commands: 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
intmain(void){ 
printf(“Hellon”); 
return 0; 
!@#$%%&*($%@#$%& 
} 
92 
GitBasic
$ vim hello.c 
$ gitcheckout hello.c 
Use the following commands: 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
intmain(void){ 
printf(“Hellon”); 
return 0; 
!@#$%%&*($%@#$%& 
} 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
93 
GitBasic
Untracked 
Unmodified 
Modified 
Staged 
initial 
gitinit 
add the file 
add/edit the file 
stage the file 
gitadd filename 
Commit a version 
gitadd filename 
gitcommit 
File Status Lifecycle 
add/edit the file 
gitreset HEAD filename 
stage the file 
gitadd filename 
94 
GitBasic
Use the following commands: 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
intmain(void){ 
printf(“Hellon”); 
return 0; 
!@#$%%&*($%@#$%& 
} 
95 
GitBasic 
$ vim hello.c
Use the following commands: 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
intmain(void){ 
printf(“Hellon”); 
return 0; 
!@#$%%&*($%@#$%& 
} 
96 
GitBasic 
$ vim hello.c 
$ gitadd hello.c
Use the following commands: 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
intmain(void){ 
printf(“Hellon”); 
return 0; 
!@#$%%&*($%@#$%& 
} 
97 
GitBasic 
$ vim hello.c 
$ gitadd hello.c 
$ gitreset HEAD hello.c
$ vim hello.c 
$ gitadd hello.c 
$ gitreset HEAD hello.c 
$ gitcheckout hello.c 
Use the following commands: 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 
intmain(void){ 
printf(“Hellon”); 
return 0; 
!@#$%%&*($%@#$%& 
} 
#include<stdio.h> 
hello.c 
intmain(void){ 
printf(“Hellon”); 
return 0; 
} 98 
GitBasic
$ gitadd <list of files> 
Different ways to add files to staging area 
99 
GitBasic 
$ gitadd *.txt 
$ gitadd main/*.txt 
$ gitadd main/ 
$ gitadd “*.txt” 
$ gitadd --all 
Add the list of files 
Add all files 
Add all txt files in current directory 
Add all txt files in main directory 
Add all files in main directory 
Add all txt files in the whole project 
Useful commands
Specifies intentionally untracked files to ignore. 
100 
GitBasic 
Useful Options 
“.gitignore”
101 
GitBasic
gitlog 
If you want to review all the commits… 
102 
GitBasic
$ gitlog 
commit 71358d83b0249362851174566042d2f3a412f985 
Author: Johnson <johnsonsu@iis.sinica.edu.tw> 
Date: Thu Jul 3 08:52:41 2014 +0800 
modify README.txt and add hello.cfile 
commit 2889fd9d34ad71ea9e29046c1e529c7b0786fcb9 
Author: Johnson <johnsonsu@iis.sinica.edu.tw> 
Date: Thu Jul 3 08:52:41 2014 +0800 
Initial commit 
Use the following commands: 
103 
GitBasic 
master
gitdiff 
If you want to review some differences 
since last commit 
104 
GitBasic
If you want to modify last commit message…? 
105 
GitBasic
$ gitcommit –m “!@#$^%&*()_” 
$ gitlog 
$ gitreset --soft HEAD^ 
$ gitlog 
$ gitcommit –m “add new file xxx” 
$ gitlog 
Use the following commands: 
A 
106 
GitBasic
$ gitcommit –m “!@#$^%&*()_” 
$ gitlog 
$ gitcommit -amend 
$ gitlog 
Use the following commands: 
add new file xxx 
107 
GitBasic 
B
$ gitcommit –m “!@#$^%&*()_” 
$ gitlog 
$ gitcommit -amend 
$ gitlog 
Use the following commands: 
add new file xxx 
108 
GitBasic 
B
$ gitreset ––soft HEAD^ 
Different ways to add files to staging area 
109 
GitBasic 
$ gitreset ––hard HEAD^ 
$ gitreset ––hard HEAD^^ 
$ gitcommit ––amend –m “New Message” 
Undo last commit, put changes into staging 
Change the last commit 
Undo last commit and all changes 
Undo last 2 commits and all changes 
Useful commands
How to share your Gitrepository 
110 
GitBasic
111 
Remote Repository 
Master 
$ gitpush origin master 
GitBasic 
Hosted 
•GitHub 
•OpenFoundry 
•SourceForge 
•Google Code 
•BitBucket 
Self Managed 
•Gitosis 
•Gitorious 
•Gitolite 
•gitlab
112 
Remote Repository 
Master 
$ gitpull 
GitBasic 
$ gitpush origin master
113 
GitBasic
114 
GitBasic
115 
GitBasic
GitBasic 
$ gitremote add origin https://github.com/OpenFoundry/MOST_TRY_GIT.git 
Adding a Remote 
116
GitBasic 
$ gitpush –u origin master 
Pushing to Remote 
117
118 
GitBasic
119 
GitBasic
120 
GitBasic 
$ gitpull 
To pull changes down from the remote
121 
GitBasic 
origin 
master 
production 
test 
Having multiple remotes
122 
GitBasic 
$ gitremote add <name> <address> 
Working with remotes 
$ gitpush –u <name> <branch> 
$ gitremote rm<name> 
To add new remotes 
To remove remotes 
To push to remotes 
Useful commands
123 
GitBasic
$ gitreset ––soft HEAD^ 
Don’t do these after you push 
124 
GitBasic 
$ gitreset ––hard HEAD^ 
$ gitreset ––hard HEAD^^ 
$ gitcommit ––amend –m “New Message” 
Undo last commit, put changes into staging 
Change the last commit 
Undo last commit and all changes 
Undo last 2 commits and all changes
$ gitreset ––soft HEAD^ 
Don’t do these after you push 
125 
GitBasic 
$ gitreset ––hard HEAD^ 
$ gitreset ––hard HEAD^^ 
$ gitcommit ––amend –m “New Message” 
Undo last commit, put changes into staging 
Change the last commit 
Undo last commit and all changes 
Undo last 2 commits and all changes
Topic 
GitWorkflow 
126
GitWorkflow 
127 
Remote Repository 
Johnson 
Vince 
Joseph
GitWorkflow 
128
GitWorkflow 
129 
$ gitclone https://github.com/OpenFoundry/MOST_TRY_GIT.git 
Cloning the Repository
GitWorkflow 
130 
master 
Branching out 
dog
GitWorkflow 
131 
master 
Switch to dog branch and working on it 
dog
GitWorkflow 
132 
master 
List of dog branch 
dog
GitWorkflow 
133 
master 
Back to master branch 
dog
GitWorkflow 
134 
master 
Merge from dog 
dog 
HEAD
GitWorkflow 
135 
Using Command: gitlog 
master 
dog 
HEAD
GitWorkflow 
136 
Branch Clean up 
master 
dog 
HEAD
GitWorkflow 
137 
Back to dog branch 
master 
dog 
HEAD
Topic 
GitWorkflow 
138
Topic 
139 
gittag 
Like most VCSs, Githas the ability to tag specific points in history as being important.
140 
GitBasic 
$ gittag 
v0.0.1 
v0.0.2 
Tagging 
$ gittag –a v0.0.3 –m “version 0.0.3” 
$ gitcheckout v0.0.1 
List all tags 
Check out code at commit 
To add a new tag 
Useful commands 
$ gitpush --tags 
To push new tags
Topic 
GitWorkflow 
141
Topic 
142
Topic 
143
Topic 
144
Topic 
145
Topic 
GitHub Flow 
146
Topic 
GitHub Flow 
147
Topic 
GitHub Flow 
148
Topic 
GitHub Flow 
149
Topic 
GitHub Flow 
150
151 
More… 
•這份投影片大部分的內容都出至於SCOTT CHACON釋出的 文件與Code School Real Git的簡報,若想了解更多Git相關 技術,以下推薦您參考使用。 
•英文推薦 
•Pro Git 
•GitReference 
•Try Git-Code School 
•“Becomea gitguru.”Powered By Atlassian 
•GitHub Help 
•中文推薦 
•ihower{blogging} 
•小惡魔–電腦技術–工作筆記 
•GitMagic
Git版本控制教學 
科技部專案操作與資源表列 
Topics 
152
科技部專案 
要做的事 
科技部專案操作與資源表列 
153
Code Hosting Sites 
154
主要分為兩種 1.國科會專案(doc or pdf) 成果報告書 需求分析 測試文件 
2.規畫釋出(unlimited) 
原始程式碼 
安裝文件 
使用手冊 
上傳檔案類別 
155
科技部專案 
156
上傳文件 
157 
請依規定時程上傳文件
上傳文件 
158 
請注意上傳文件的檔案格式
主要分為兩種 
1.國科會專案(doc or pdf) 
成果報告書 
需求分析 
測試文件 2.規畫釋出(unlimited) 原始程式碼 安裝文件 使用手冊 
上傳檔案類別 
159
放上檔案供人下載 
安裝程式檔、安裝使用手冊 
README、LICENSE、INSTALLATION 
安裝使用手冊 
160
FTP一般檔案上傳 
161
FTP一般檔案上傳 
162
FTP一般檔案上傳 
163
FTP一般檔案上傳 
164
FTP一般檔案上傳 
165
FTP一般檔案上傳 
166
FTP一般檔案上傳 
167
FTP一般檔案上傳 
168
FTP一般檔案上傳 
169
FTP一般檔案上傳 
170
FTP一般檔案上傳 
171
FTP一般檔案上傳 
172
FTP一般檔案上傳 
173
174 
完成釋出
175 
完成釋出
FTP大檔案上傳 
大型檔案請採用FTP上傳! 
參考說明 
176
以上、 
完成一個規畫釋出的上傳流程 
177
線上協助 
參考此處 
178
Johnson J. Su 
Linkedin:https://www.linkedin.com/in/jansu 
E-mail:johnsonsu@iis.sinica.edu.tw 
TEL:(02) 2788-3799 ext. 1478 
179
Q & A 
180

More Related Content

PDF
Understanding git
PDF
Defcon 2011 network forensics 解题记录
PDF
Git and GitHub at the San Francisco JUG
PDF
Git Graphs, Hashes, and Compression, Oh My
PDF
Migrating from Subversion to Git and GitHub
PDF
FOSDEM 2012 vcsh talk
PDF
Startup Camp - Git, Python, Django session
PDF
Introduction to Git for Non-Developers
Understanding git
Defcon 2011 network forensics 解题记录
Git and GitHub at the San Francisco JUG
Git Graphs, Hashes, and Compression, Oh My
Migrating from Subversion to Git and GitHub
FOSDEM 2012 vcsh talk
Startup Camp - Git, Python, Django session
Introduction to Git for Non-Developers

Viewers also liked (19)

PPT
A Guideline to Test Your Own Code - Developer Testing
PDF
Integration
PDF
Code tuning techniques
PDF
程序员发展漫谈
PDF
Coding Style
PDF
高品質軟體的基本動作 101 + 102 for NUU
PPTX
Variables
PDF
Design in construction
PDF
Design in construction
PPTX
程序员实践之路
PDF
Defencive programming
PPTX
Java scriptcore brief introduction
PPT
代码大全(内训)
PDF
Code tuning strategies
PDF
高品質軟體的基本動作 101 for NTHU
PPT
Code Tuning
PDF
The pseudocode
PPT
Rm 1 Intro Types Research Process
A Guideline to Test Your Own Code - Developer Testing
Integration
Code tuning techniques
程序员发展漫谈
Coding Style
高品質軟體的基本動作 101 + 102 for NUU
Variables
Design in construction
Design in construction
程序员实践之路
Defencive programming
Java scriptcore brief introduction
代码大全(内训)
Code tuning strategies
高品質軟體的基本動作 101 for NTHU
Code Tuning
The pseudocode
Rm 1 Intro Types Research Process
Ad

Similar to MOST_OpenFoundry_version control system_Git (20)

PPTX
cs262_intro_slides.pptx
PDF
2.Format Strings
PDF
Let the contribution begin
PPTX
Lecture 04 Programming C for Beginners 001
PDF
Let the contribution begin (EST futures)
DOCX
1 CMPS 12M Introduction to Data Structures Lab La.docx
PDF
GNU Compiler Collection - August 2005
PDF
Git Presentation - Purple Scout AB Malmö
PDF
Hg version control bioinformaticians
KEY
Git talk from Open 2011 conference in Israel
PPT
File handling(some slides only)
PDF
DO YOU WANT TO USE A VCS
PDF
Half-Century of Unix; History, Preservation, and Lessons Learned
 
PPTX
Version Control Systems -- Git -- Part I
PDF
xv6 is a re−implementation of Dennis Ritchie’s and Ken Thompson’s Unix Versio...
PDF
C for Java programmers (part 1)
PPT
C tutorial
PDF
Introduction to GNU Make Programming Language
DOCX
Linux 系統程式--第一章 i/o 函式
cs262_intro_slides.pptx
2.Format Strings
Let the contribution begin
Lecture 04 Programming C for Beginners 001
Let the contribution begin (EST futures)
1 CMPS 12M Introduction to Data Structures Lab La.docx
GNU Compiler Collection - August 2005
Git Presentation - Purple Scout AB Malmö
Hg version control bioinformaticians
Git talk from Open 2011 conference in Israel
File handling(some slides only)
DO YOU WANT TO USE A VCS
Half-Century of Unix; History, Preservation, and Lessons Learned
 
Version Control Systems -- Git -- Part I
xv6 is a re−implementation of Dennis Ritchie’s and Ken Thompson’s Unix Versio...
C for Java programmers (part 1)
C tutorial
Introduction to GNU Make Programming Language
Linux 系統程式--第一章 i/o 函式
Ad

Recently uploaded (20)

PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Construction Project Organization Group 2.pptx
PDF
PPT on Performance Review to get promotions
PDF
737-MAX_SRG.pdf student reference guides
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
Artificial Intelligence
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Safety Seminar civil to be ensured for safe working.
PPT
Project quality management in manufacturing
PPT
Mechanical Engineering MATERIALS Selection
III.4.1.2_The_Space_Environment.p pdffdf
CYBER-CRIMES AND SECURITY A guide to understanding
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
Internet of Things (IOT) - A guide to understanding
Construction Project Organization Group 2.pptx
PPT on Performance Review to get promotions
737-MAX_SRG.pdf student reference guides
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Artificial Intelligence
additive manufacturing of ss316l using mig welding
Fundamentals of safety and accident prevention -final (1).pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Automation-in-Manufacturing-Chapter-Introduction.pdf
Safety Seminar civil to be ensured for safe working.
Project quality management in manufacturing
Mechanical Engineering MATERIALS Selection

MOST_OpenFoundry_version control system_Git

  • 3. Johnson J. Su Linkedin:https://www.linkedin.com/in/jansu E-mail:johnsonsu@iis.sinica.edu.tw TEL:(02) 2788-3799 ext. 1478 2
  • 10. What is Git? GitBasic 9
  • 11. Git is an open source, distributed version control system designed for speed and efficiency GitBasic 10
  • 12. Gitis an open source, distributed version control system designed for speed and efficiency GitBasic 11
  • 13. Gitis an open source, distributedversion control system designed for speed and efficiency GitBasic 12
  • 18. (almost) everything is local GitBasic 17
  • 20. which means everything is fast GitBasic 19
  • 21. which means everything is fast every clone is a backup GitBasic 20
  • 22. which means everything is fast every clone is a backup work offline GitBasic 21
  • 23. No Network Needed GitBasic 22
  • 24. No Network Needed Performing a diff GitBasic 23
  • 25. No Network Needed Performing a diff Viewing file history GitBasic 24
  • 26. No Network Needed Performing a diff Viewing file history Committing changes GitBasic 25
  • 27. No Network Needed Performing a diff Viewing file history Committing changes Merging branches Obtaining other revisions of a file GitBasic 26
  • 28. No Network Needed Performing a diff Viewing file history Committing changes Merging branches Obtaining other revisions of a file Switching branches GitBasic 27
  • 29. (almost) never removes data GitBasic 29
  • 30. Compare with svn… GitBasic 30
  • 31. Snapshots, not Patches GitBasic 31
  • 32. File Based Delta Storage GitBasic 32
  • 33. First… Let’s make an example of svn GitBasic 33
  • 34. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } 34
  • 35. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } README.txt hello.c Commit A This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } . 35
  • 36. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } README.txt hello.c Commit A This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } . 36
  • 37. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Jellon”); return 0; } README.txt hello.c Commit A This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } . 37
  • 38. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Jellon”); return 0; } Commit B -printf("Hellon"); + printf(“Jellon"); README.txt hello.c Commit A This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } . 38
  • 39. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Jellon”); return 0; } Commit B -printf("Hellon"); + printf(“Jellon"); README.txt hello.c Commit A This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } . 39
  • 40. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } Commit B -printf("Hellon"); + printf(“Jellon"); README.txt hello.c Commit A This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } . 40
  • 41. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } Commit B -printf("Hellon"); + printf(“Jellon"); README.txt hello.c Commit A This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } . jello.c (rename) Commit C 41
  • 42. This is Johnson Su’s jelloproject. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } Commit B -printf("Hellon"); + printf(“Jellon"); README.txt hello.c Commit A This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } . jello.c (rename) Commit C 42
  • 43. This is Johnson Su’s jelloproject. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } #include<stdio.h> hello.c intmain(void){ printf(“Jellon”); return 0; } Commit B -printf("Hellon"); + printf(“Jellon"); README.txt hello.c Commit A This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } . jello.c (rename) Commit C 43
  • 44. This is Johnson Su’s jelloproject. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } #include<stdio.h> hello.c intmain(void){ printf(“Jellon”); return 0; } Commit B -printf("Hellon"); + printf(“Jellon"); README.txt hello.c Commit A This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } . jello.c (rename) Commit C Commit D -excellent + Jello (rename) 44
  • 45. This is Johnson Su’s jelloproject. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } #include<stdio.h> hello.c intmain(void){ printf(“Jellon”); return 0; } Commit B -printf("Hellon"); + printf(“Jellon"); README.txt hello.c Commit A This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } . jello.c (rename) Commit C Commit D -excellent + Jello (rename) 45
  • 47. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } 47
  • 48. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 CHECKSUM 48
  • 49. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 CHECKSUM 49
  • 50. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c 50
  • 51. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c 51
  • 52. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } Commit A c3dREADME.txt f13hello.c This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 52
  • 53. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } Commit A c3dREADME.txt f13hello.c This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 53
  • 54. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Jellon”); return 0; } This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c 54
  • 55. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Jellon”); return 0; } This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c Commit B c3dREADME.txt 6d4hello.c #include<stdio.h> intmain(void){ printf(“Jellon”); return 0; } 6d4 55
  • 56. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Jellon”); return 0; } This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c Commit B c3dREADME.txt 6d4hello.c #include<stdio.h> intmain(void){ printf(“Jellon”); return 0; } 6d4 56
  • 57. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Jellon”); return 0; } This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c Commit B c3dREADME.txt 6d4hello.c #include<stdio.h> intmain(void){ printf(“Jellon”); return 0; } 6d4 57
  • 58. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c Commit B c3dREADME.txt 6d4hello.c #include<stdio.h> intmain(void){ printf(“Jellon”); return 0; } 6d4 58
  • 59. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c Commit B c3dREADME.txt 6d4hello.c #include<stdio.h> intmain(void){ printf(“Jellon”); return 0; } 6d4 Commit C c3dREADME.txt 6d4jello.c 59
  • 60. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c Commit B c3dREADME.txt 6d4hello.c #include<stdio.h> intmain(void){ printf(“Jellon”); return 0; } 6d4 Commit C c3dREADME.txt 6d4jello.c 60
  • 61. This is Johnson Su’s excellent project. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c Commit B c3dREADME.txt 6d4hello.c #include<stdio.h> intmain(void){ printf(“Jellon”); return 0; } 6d4 Commit C c3dREADME.txt 6d4jello.c 61
  • 62. This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c Commit B c3dREADME.txt 6d4hello.c #include<stdio.h> intmain(void){ printf(“Jellon”); return 0; } 6d4 Commit C c3dREADME.txt 6d4jello.c This is Johnson Su’s Jelloproject. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } 62
  • 63. This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c Commit B c3dREADME.txt 6d4hello.c #include<stdio.h> intmain(void){ printf(“Jellon”); return 0; } 6d4 Commit C c3dREADME.txt 6d4jello.c This is Johnson Su’s Jelloproject. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } #include<stdio.h> hello.c intmain(void){ printf(“Jellon”); return 0; } 63
  • 64. This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c Commit B c3dREADME.txt 6d4hello.c #include<stdio.h> intmain(void){ printf(“Jellon”); return 0; } 6d4 Commit C c3dREADME.txt 6d4jello.c This is Johnson Su’s Jelloproject. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } #include<stdio.h> hello.c intmain(void){ printf(“Jellon”); return 0; } This is Johnson Su’s Jelloproject. Licensed under GPL. 84f 64
  • 65. This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c Commit B c3dREADME.txt 6d4hello.c #include<stdio.h> intmain(void){ printf(“Jellon”); return 0; } 6d4 Commit C c3dREADME.txt 6d4jello.c This is Johnson Su’s Jelloproject. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } #include<stdio.h> hello.c intmain(void){ printf(“Jellon”); return 0; } This is Johnson Su’s Jelloproject. Licensed under GPL. 84f Commit D 84fREADME.txt 6d4jello.c 6d4hello.c 65
  • 66. This is Johnson Su’s excellent project. Licensed under GPL. #include<stdio.h> intmain(void){ printf(“Hellon”); return 0; } c3d f13 Commit A c3dREADME.txt f13hello.c Commit B c3dREADME.txt 6d4hello.c #include<stdio.h> intmain(void){ printf(“Jellon”); return 0; } 6d4 Commit C c3dREADME.txt 6d4jello.c This is Johnson Su’s Jelloproject. Licensed under GPL. README.txt #include<stdio.h> jello.c intmain(void){ printf(“Jellon”); return 0; } #include<stdio.h> hello.c intmain(void){ printf(“Jellon”); return 0; } This is Johnson Su’s Jelloproject. Licensed under GPL. 84f Commit D 84fREADME.txt 6d4jello.c 6d4hello.c 66
  • 68. 68 GitBasic Gitcommands (Live demo)
  • 69. Beforewe start to use Gitrepository…… 69 GitBasic
  • 71. $ gitconfig--global user.name “Johnson J. Su” $ gitconfig--global user.email“johnsonsu@iis.sinica.edu.tw” Setting Up Git $ gitconfig--global color.uiture 71 GitBasic
  • 72. Let’s start using Git first… Create or Clone a Gitrepository 72 GitBasic
  • 73. Two way to get Gitrepository… $ gitclone https://example.com/example.git $ mkdirproject $ cd project $ gitinit gitclone repository from remote server gitinitial a repository in local system 73 GitBasic
  • 74. 74 GitBasic Johnson creates README.txt file Add file to staging area Commit changes Johnson modifies README.txt file & adds hello.c Add both file to staging area Commit changes
  • 75. Untracked Unmodified Modified Staged initial gitinit File Status Lifecycle 75 GitBasic
  • 76. $ mkdirproject $ cd project $ touch README.txt $ gitinit $ tree -a Use the following commands: 76 GitBasic
  • 77. Untracked Unmodified Modified Staged initial gitinit add the file 1.gitadd filename 2.gitcommit File Status Lifecycle 77 GitBasic
  • 78. $ gitadd . $ gitstatus $ gitcommit –m “Initial commit” Use the following commands: 78 GitBasic
  • 79. Untracked Unmodified Modified Staged initial gitinit add the file add/edit the file gitadd filename File Status Lifecycle 79 GitBasic
  • 80. README.txt Use the following commands: 80 GitBasic
  • 81. $ vim README.txt Use the following commands: This is Johnson Su’s excellentproject. Licensed under GPL. README.txt 81 GitBasic
  • 82. $ vim README.txt $ touch hello.c Use the following commands: This is Johnson Su’s excellentproject. Licensed under GPL. README.txt hello.c 82 GitBasic
  • 83. $ vim README.txt $ touch hello.c $ vim hello.c Use the following commands: This is Johnson Su’s excellentproject. Licensed under GPL. README.txt hello.c 83 GitBasic
  • 84. $ vim README.txt $ touch hello.c $ vim hello.c Use the following commands: This is Johnson Su’s excellentproject. Licensed under GPL. README.txt #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } 84 GitBasic
  • 85. Untracked Unmodified Modified Staged initial gitinit add the file add/edit the file stage the file gitadd filename gitadd filename File Status Lifecycle 85 GitBasic
  • 86. $ gitadd . $ gitstatus $ gitcommit –m “modify README.txt and add hello.cfile” Use the following commands: The commit message must be very clear!! (Recommend) 86 GitBasic
  • 87. Untracked Unmodified Modified Staged initial gitinit add the file add/edit the file stage the file gitadd filename Commit a version gitadd filename gitcommit File Status Lifecycle 87 GitBasic
  • 88. Untracked Unmodified Modified Staged initial gitinit add the file add/edit the file stage the file gitadd filename Commit a version Remove the file gitadd filename gitcommit gitrmfilename File Status Lifecycle 88 GitBasic
  • 89. $ gitstatus $ gitrmhello.c $ gitstatus Use the following commands: 89 GitBasic
  • 91. Untracked Unmodified Modified Staged initial gitinit add the file add/edit the file stage the file gitadd filename Commit a version gitadd filename gitcommit File Status Lifecycle add/edit the file gitcheckout filename 91 GitBasic
  • 92. $ vim hello.c Use the following commands: #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } intmain(void){ printf(“Hellon”); return 0; !@#$%%&*($%@#$%& } 92 GitBasic
  • 93. $ vim hello.c $ gitcheckout hello.c Use the following commands: #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } intmain(void){ printf(“Hellon”); return 0; !@#$%%&*($%@#$%& } #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } 93 GitBasic
  • 94. Untracked Unmodified Modified Staged initial gitinit add the file add/edit the file stage the file gitadd filename Commit a version gitadd filename gitcommit File Status Lifecycle add/edit the file gitreset HEAD filename stage the file gitadd filename 94 GitBasic
  • 95. Use the following commands: #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } intmain(void){ printf(“Hellon”); return 0; !@#$%%&*($%@#$%& } 95 GitBasic $ vim hello.c
  • 96. Use the following commands: #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } intmain(void){ printf(“Hellon”); return 0; !@#$%%&*($%@#$%& } 96 GitBasic $ vim hello.c $ gitadd hello.c
  • 97. Use the following commands: #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } intmain(void){ printf(“Hellon”); return 0; !@#$%%&*($%@#$%& } 97 GitBasic $ vim hello.c $ gitadd hello.c $ gitreset HEAD hello.c
  • 98. $ vim hello.c $ gitadd hello.c $ gitreset HEAD hello.c $ gitcheckout hello.c Use the following commands: #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } intmain(void){ printf(“Hellon”); return 0; !@#$%%&*($%@#$%& } #include<stdio.h> hello.c intmain(void){ printf(“Hellon”); return 0; } 98 GitBasic
  • 99. $ gitadd <list of files> Different ways to add files to staging area 99 GitBasic $ gitadd *.txt $ gitadd main/*.txt $ gitadd main/ $ gitadd “*.txt” $ gitadd --all Add the list of files Add all files Add all txt files in current directory Add all txt files in main directory Add all files in main directory Add all txt files in the whole project Useful commands
  • 100. Specifies intentionally untracked files to ignore. 100 GitBasic Useful Options “.gitignore”
  • 102. gitlog If you want to review all the commits… 102 GitBasic
  • 103. $ gitlog commit 71358d83b0249362851174566042d2f3a412f985 Author: Johnson <johnsonsu@iis.sinica.edu.tw> Date: Thu Jul 3 08:52:41 2014 +0800 modify README.txt and add hello.cfile commit 2889fd9d34ad71ea9e29046c1e529c7b0786fcb9 Author: Johnson <johnsonsu@iis.sinica.edu.tw> Date: Thu Jul 3 08:52:41 2014 +0800 Initial commit Use the following commands: 103 GitBasic master
  • 104. gitdiff If you want to review some differences since last commit 104 GitBasic
  • 105. If you want to modify last commit message…? 105 GitBasic
  • 106. $ gitcommit –m “!@#$^%&*()_” $ gitlog $ gitreset --soft HEAD^ $ gitlog $ gitcommit –m “add new file xxx” $ gitlog Use the following commands: A 106 GitBasic
  • 107. $ gitcommit –m “!@#$^%&*()_” $ gitlog $ gitcommit -amend $ gitlog Use the following commands: add new file xxx 107 GitBasic B
  • 108. $ gitcommit –m “!@#$^%&*()_” $ gitlog $ gitcommit -amend $ gitlog Use the following commands: add new file xxx 108 GitBasic B
  • 109. $ gitreset ––soft HEAD^ Different ways to add files to staging area 109 GitBasic $ gitreset ––hard HEAD^ $ gitreset ––hard HEAD^^ $ gitcommit ––amend –m “New Message” Undo last commit, put changes into staging Change the last commit Undo last commit and all changes Undo last 2 commits and all changes Useful commands
  • 110. How to share your Gitrepository 110 GitBasic
  • 111. 111 Remote Repository Master $ gitpush origin master GitBasic Hosted •GitHub •OpenFoundry •SourceForge •Google Code •BitBucket Self Managed •Gitosis •Gitorious •Gitolite •gitlab
  • 112. 112 Remote Repository Master $ gitpull GitBasic $ gitpush origin master
  • 116. GitBasic $ gitremote add origin https://github.com/OpenFoundry/MOST_TRY_GIT.git Adding a Remote 116
  • 117. GitBasic $ gitpush –u origin master Pushing to Remote 117
  • 120. 120 GitBasic $ gitpull To pull changes down from the remote
  • 121. 121 GitBasic origin master production test Having multiple remotes
  • 122. 122 GitBasic $ gitremote add <name> <address> Working with remotes $ gitpush –u <name> <branch> $ gitremote rm<name> To add new remotes To remove remotes To push to remotes Useful commands
  • 124. $ gitreset ––soft HEAD^ Don’t do these after you push 124 GitBasic $ gitreset ––hard HEAD^ $ gitreset ––hard HEAD^^ $ gitcommit ––amend –m “New Message” Undo last commit, put changes into staging Change the last commit Undo last commit and all changes Undo last 2 commits and all changes
  • 125. $ gitreset ––soft HEAD^ Don’t do these after you push 125 GitBasic $ gitreset ––hard HEAD^ $ gitreset ––hard HEAD^^ $ gitcommit ––amend –m “New Message” Undo last commit, put changes into staging Change the last commit Undo last commit and all changes Undo last 2 commits and all changes
  • 127. GitWorkflow 127 Remote Repository Johnson Vince Joseph
  • 129. GitWorkflow 129 $ gitclone https://github.com/OpenFoundry/MOST_TRY_GIT.git Cloning the Repository
  • 130. GitWorkflow 130 master Branching out dog
  • 131. GitWorkflow 131 master Switch to dog branch and working on it dog
  • 132. GitWorkflow 132 master List of dog branch dog
  • 133. GitWorkflow 133 master Back to master branch dog
  • 134. GitWorkflow 134 master Merge from dog dog HEAD
  • 135. GitWorkflow 135 Using Command: gitlog master dog HEAD
  • 136. GitWorkflow 136 Branch Clean up master dog HEAD
  • 137. GitWorkflow 137 Back to dog branch master dog HEAD
  • 139. Topic 139 gittag Like most VCSs, Githas the ability to tag specific points in history as being important.
  • 140. 140 GitBasic $ gittag v0.0.1 v0.0.2 Tagging $ gittag –a v0.0.3 –m “version 0.0.3” $ gitcheckout v0.0.1 List all tags Check out code at commit To add a new tag Useful commands $ gitpush --tags To push new tags
  • 151. 151 More… •這份投影片大部分的內容都出至於SCOTT CHACON釋出的 文件與Code School Real Git的簡報,若想了解更多Git相關 技術,以下推薦您參考使用。 •英文推薦 •Pro Git •GitReference •Try Git-Code School •“Becomea gitguru.”Powered By Atlassian •GitHub Help •中文推薦 •ihower{blogging} •小惡魔–電腦技術–工作筆記 •GitMagic
  • 155. 主要分為兩種 1.國科會專案(doc or pdf) 成果報告書 需求分析 測試文件 2.規畫釋出(unlimited) 原始程式碼 安裝文件 使用手冊 上傳檔案類別 155
  • 159. 主要分為兩種 1.國科會專案(doc or pdf) 成果報告書 需求分析 測試文件 2.規畫釋出(unlimited) 原始程式碼 安裝文件 使用手冊 上傳檔案類別 159
  • 179. Johnson J. Su Linkedin:https://www.linkedin.com/in/jansu E-mail:johnsonsu@iis.sinica.edu.tw TEL:(02) 2788-3799 ext. 1478 179
  • 180. Q & A 180