Git
Sébastien Cevey <seb@cine7.net>
http://bytes.inso.cc/
Purple Scout presentation (April 17, 2009)
Swiss Federal Institute
- f Technology, Lausanne
XMMS2 Music Player Playlouder MSP
Git Sbastien Cevey <seb@cine7.net> http://bytes.inso.cc/ - - PowerPoint PPT Presentation
Git Sbastien Cevey <seb@cine7.net> http://bytes.inso.cc/ Purple Scout presentation (April 17, 2009) Swiss Federal Institute XMMS2 Music Player Playlouder MSP of Technology, Lausanne Outline 1. Introduction 2. Concepts & Local
Sébastien Cevey <seb@cine7.net>
http://bytes.inso.cc/
Purple Scout presentation (April 17, 2009)
Swiss Federal Institute
XMMS2 Music Player Playlouder MSP
2
3
4
Repository
Working Copy Working Copy Working Copy
permissions branches
checkout commit update
5
Repository
Working Copy
Repository
Working Copy
Repository
Working Copy
Repository Repository Repository
clone push pull
6
(public/private)
7
8
Linux kernel, Freedesktop (X.org), Ruby on Rails, XMMS2, Android, Gnome, GCC, etc.
9
email, etc
“Jacko is a git.”
“I'm an egotistical bastard, and I name all my projects after
10
(Mercurial, Darcs, Bazaar, Monotone, etc)
11
(Mercurial, Darcs, Bazaar, Monotone, etc)
12
Source: http://whygitisbetterthanx.com/
13
14
15
.git/objects/
a23f 3347 8e9b f943 601a cc39 1432 efa4 1798 1260 3e93 5592 dd85 335e 57bc 332e 23a7 34fe cca6 2211 5390 93a4 cc5e b3ca
6679 eab4
16
.git/objects/8e/9b...
a23f 3347 8e9b f943 601a cc39 1432 efa4 1798 1260 3e93 5592 dd85 335e 57bc 332e 23a7 34fe cca6 2211 5390 93a4 cc5e b3ca
#include <stdio.h> int main () { printf(”Hello World”); return 0; } 6679 eab4
17
git cat-file -p 93a4
a23f 3347 8e9b f943 601a cc39 1432 efa4 1798 1260 3e93 5592 dd85 335e 57bc 332e 23a7 34fe cca6 2211 5390 93a4 cc5e b3ca
040000 tree cc5e src 100644 blob 93a4 hw.c 6679 eab4
18
git cat-file -p 1260
a23f 3347 8e9b f943 601a cc39 1432 efa4 1798 1260 3e93 5592 dd85 335e 57bc 332e 23a7 34fe cca6 2211 5390 93a4 cc5e b3ca
tree 1260... parent f943... author Tom <tom@...> 1204666883 +0100 committer Max <max@...> 1204666883 +0100 Fixed a major bug in Hello World. 6679 eab4
19
git cat-file -p 1432 Note: identity is a function of the whole history! i.e. build-in integrity check
a23f 3347 8e9b f943 601a cc39 1432 efa4 1798 1260 3e93 5592 dd85 335e 57bc 332e 23a7 34fe cca6 2211 5390 93a4 cc5e b3ca
6679 eab4
type commit tag v1.0.7 tagger Jack <jack@...> 1136523576 -0800 GIT 1.0.7
SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8D…
SIGNATURE-----
20
git cat-file -p 335e
a23f 3347 8e9b f943 601a cc39 1432 efa4 1798 1260 3e93 5592 dd85 335e 57bc 332e 23a7 34fe cca6 2211 5390 93a4 cc5e b3ca 6679 eab4
v1.0 alpha-3 master feature-X
branches tags
point to a commit in the graph
21
point to an
commit)
git branch git tag
a23f 3347 8e9b f943 601a cc39 1432
v1.0 alpha-3 master feature-X
branches tags
22
HEAD
23
$ find
. ./src ./src/Makefile ./src/helloworld.c ./src/helloworld.h ./Makefile ./IDEAS ./README
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
24
$ git init
Initialized empty Git repository in /path/example/.git/
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
25
$ git status
# On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # IDEAS # Makefile # README # src/ nothing added to commit but untracked files present (use "git add" to track)
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
26
$ git add .
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
27
$ git status
# On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: IDEAS # new file: Makefile # new file: README # new file: src/Makefile # new file: src/helloworld.c # new file: src/helloworld.h
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
28
$ git commit -a -m "First import"
Created initial commit 04f087b: First import 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 IDEAS create mode 100644 Makefile create mode 100644 README create mode 100644 src/Makefile create mode 100644 src/helloworld.c create mode 100644 src/helloworld.h
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
29
$ echo "Blah blah" >> README $ rm IDEAS
04f087b
master
Makefile README <- edited src |-- Makefile |-- helloworld.c `-- helloworld.h
30
$ git status
# On branch master # Changed but not updated: # (use "git add/rm <file>..." to update what will be committed) # # deleted: IDEAS # modified: README # no changes added to commit (use "git add" and/or "git commit -a")
04f087b
master
Makefile README <- edited src |-- Makefile |-- helloworld.c `-- helloworld.h
31
$ git commit -a -m "More stuff"
Created commit 54eda77: More stuff 1 files changed, 1 insertions(+), 0 deletions(-) delete mode 100644 IDEAS
04f087b
master
54eda77
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
32
$ git show
commit 54eda77a85b0e5d1891653a36ff08faf133df030 Author: Sebastien Cevey <seb@cine7.net> Date: Mon Apr 13 21:23:02 2009 +0200 More stuff diff --git a/IDEAS b/IDEAS deleted file mode 100644 index e69de29..0000000 diff --git a/README b/README index e69de29..579c5b1 100644
+++ b/README @@ -0,0 +1 @@ +Blah blah
04f087b
master
54eda77
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
33
$ git show --pretty=raw
commit 54eda77a85b0e5d1891653a36ff08faf133df030 tree 524f0cfe293064d18ac0c12a55baaf2b34d42e8d parent 04f087b23ce96c2b24f9f6b5f7cf437af33e19c6 author Sebastien Cevey <seb@cine7.net> 1239650582 +0200 committer Sebastien Cevey <seb@cine7.net> 1239650582 +0200 More stuff [...]
04f087b
master
54eda77 524f0c
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
34
$ git log
commit 54eda77a85b0e5d1891653a36ff08faf133df030 Author: Sebastien Cevey <seb@cine7.net> Date: Mon Apr 13 21:23:02 2009 +0200 More stuff commit 04f087b23ce96c2b24f9f6b5f7cf437af33e19c6 Author: Sebastien Cevey <seb@cine7.net> Date: Mon Apr 13 21:11:58 2009 +0200 First import
04f087b
master
54eda77
Makefile README src |-- Makefile |-- helloworld.c <- edited `-- helloworld.h
35
$ echo "/* End of fil */" >> src/helloworld.c
04f087b
master
54eda77
Makefile README src |-- Makefile |-- helloworld.c <- edited `-- helloworld.h
36
$ git diff
diff --git a/src/helloworld.c b/src/helloworld.c index e69de29..54a606d 100644
+++ b/src/helloworld.c @@ -0,0 +1 @@ +/* End of fil */
04f087b
master
54eda77
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
37
$ git commit -a -m “Hasty commit”
Created commit 3b5ba16: Hasty commit 1 files changed, 1 insertions(+), 0 deletions(-)
04f087b
master
54eda77 3b5ba16
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
38
$ git reset --hard HEAD^ # parent of HEAD
HEAD is now at 54eda77 More stuff
$ git status
# On branch master nothing to commit (working directory clean)
04f087b
master
54eda77
Makefile README src |-- Makefile |-- helloworld.c <- edited `-- helloworld.h
39
$ git reset HEAD^ # parent of HEAD
src/helloworld.c: locally modified
$ git diff
diff --git a/src/helloworld.c b/src/helloworld.c index e69de29..54a606d 100644
+++ b/src/helloworld.c @@ -0,0 +1 @@ +/* End of fil */
04f087b
master
54eda77
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
40
$ $EDITOR src/helloworld.c $ git commit -a -m "Proper commit"
Created commit 0657c63: Proper commit 1 files changed, 1 insertions(+), 0 deletions(-)
04f087b
master
54eda77 0657c63
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
41
$ git tag stable
04f087b
master
54eda77 0657c63
stable
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
42
$ git branch feature-X 54eda77 $ git branch
feature-X * master
04f087b
master
54eda77 0657c63
stable feature-X
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
43
$ git checkout feature-X
Switched to branch "feature-X"
$ git branch
* feature-X master
04f087b
master
54eda77 0657c63
stable feature-X
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
44
$ $EDITOR src/helloworld.c $ git commit -a -m "Work on X"
Created commit 6195849: Work on X 1 files changed, 1 insertions(+), 0 deletions(-)
04f087b
master
54eda77 0657c63
stable feature-X
6195849
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
45
$ $EDITOR README $ git commit -a -m "Edit README for X"
Created commit 20fbfdd: Edit README for X 1 files changed, 1 insertions(+), 0 deletions(-)
04f087b
master
54eda77 0657c63
stable feature-X
20fbfdd 02bbf10
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
46
$ git checkout master
Switched to branch "master"
$ git diff feature-X
diff --git a/README b/README index 29a6a68..579c5b1 100644
+++ b/README @@ -1,2 +1 @@ Blah blah
[...]
04f087b
master
54eda77 0657c63
stable feature-X
1e4cfe4 02bbf10
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
47
$ git merge feature-X
Merge made by recursive. README | 1 + src/helloworld.h | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
04f087b
master
54eda77 0657c63
stable feature-X
1e4cfe4 02bbf10 69e105
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
48
$ git show
commit 69e105f3d1991c34d74d079197d5f1b1917d3120 Merge: 0657c63... 20fbfdd... Author: Sebastien Cevey <seb@cine7.net> Date: Mon Apr 13 22:49:16 2009 +0200 Merge branch 'feature-X'
04f087b
master
54eda77 0657c63
stable feature-X
1e4cfe4 02bbf10 69e105
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
49
$ git reset --hard stable # undo last merge
HEAD is now at 0657c63 Proper commit
$ git checkout feature-X
Switched to branch "feature-X"
04f087b
master
54eda77 0657c63
stable feature-X
20fbfdd 02bbf10
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
50
$ git rebase master
First, rewinding head to replay your work on top of it... Applying: Work on X Applying: Edit README for X
$ git show-branch
* [feature-X] Edit README for X ! [master] Proper commit
* [feature-X] Edit README for X * [feature-X^] Work on X *+ [master] Proper commit
04f087b
master
54eda77 0657c63
stable feature-X
aeaf0a 2e309b
Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
51
$ git checkout master
Switched to branch "master"
$ git merge feature-X
Updating 0657c63..aeaf0a9 Fast forward README | 1 + src/helloworld.h | 1 + 2 files changed, 2 insertions(+), 0 deletions(-)
04f087b
master
54eda77 0657c63
stable feature-X
aeaf0a 2e309b
52
53
54
55
public repo
master fix-segfault
A B C D E
56
(over local filesystem, ssh://, git://, rsync://, ftp://etc)
57
public repo
master fix-segfault
A B C D E
local repo
master fix-segfault
A B C D E
$ git clone $URL
Initialized empty Git repository in local/ copy/.git/
58
public repo
master fix-segfault
A B C D E
local repo
master fix-segfault
A B C D E
master
$ git branch --all
*master
public repo
59
master fix-segfault
A B C D E
local repo
master fix-segfault
A B C D E F
master
local repo public repo
60
master fix-segfault
A B C D E
master fix-segfault
A B C D E
$ git fetch origin
remote: Counting objects: 5, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From /public/repo E..F fix-segfault -> origin/fix-segfault
F F
master
local repo public repo
61
master fix-segfault
A B C D E
master fix-segfault
A B C D E
$ git checkout -b work \
Branch work set up to track remote branch refs/remotes/origin/fix-segfault. Switched to a new branch "work"
F F
master work
“topic branch” “tracking branches”
local repo public repo
62
master fix-segfault master fix-segfault
B C D E
$ $EDITOR $ git commit -a -m "Another fix"
[...]
F
master work
G B C D E F
local repo public repo
63
master fix-segfault
B C D E
master fix-segfault
B C D E
$ git push origin work:fix-segfault
Total 0 (delta 0), reused 0 (delta 0) To /public/repo F..G work -> feature-X
F F
master work
G G
local repo public repo
64
master fix-segfault
C D E
master fix-segfault
B C D E F F
master work
G G H
local repo public repo
65
master fix-segfault
C D E
master fix-segfault
C D
$ git fetch origin
[...] From /public/repo G..H fix-segfault -> origin/fix-segfault
F F
master work
G G H H
local repo public repo
66
master fix-segfault
C D E
master fix-segfault
C D
$ git pull origin
Updating G..H Fast forward README | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
F F
master work
G G H H
67
dev/ stable/
local repo stable
68
master fix-segfault master fix-segfault master work pre-merge master
anna
master fix-segfault experimental
dev
master buggy-crap test
dev/ anna/ stable/
local repo stable
69
master fix-segfault master fix-segfault master work pre-merge master
anna
master fix-segfault experimental
dev
master buggy-crap test
git remote add anna $URL
dev/ anna/ stable/
local repo stable
70
master fix-segfault master fix-segfault master work pre-merge experimental fix-segfault master master
anna
master fix-segfault experimental
dev
master buggy-crap test
git fetch anna
dev/ anna/ stable/
local repo stable
71
master fix-segfault master fix-segfault master work pre-merge experimental fix-segfault master master
anna
master fix-segfault experimental
dev
master buggy-crap test
mine
git --bare init
“just a repo, not in .git/”
dev/ anna/ stable/
local repo stable
72
master fix-segfault master fix-segfault master work pre-merge experimental fix-segfault master master
anna
master fix-segfault experimental
dev
master buggy-crap test
mine
git remote add mine $URL
mine/ dev/ anna/ stable/
local repo x stable
73
master fix-segfault master master work pre-merge experimental fix-segfault master master
anna
master fix-segfault experimental
dev
master buggy-crap test
mine
master pre-merge master pre-merge
“remotes”
git push mine work:master pre-merge
74
tru anders theefer public theefer public tru Joe Sixpack stable devel
developer maintainers user
75
tru anders theefer public theefer public tru Joe Sixpack stable devel
developer maintainers user
public
contributer
76
77
78
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
79
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
80
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
git add/rm git commit
81
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
git commit -a
82
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h test.c <- new file TODO <- new file IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
83
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h test.c <- new file TODO <- new file IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h
$ git status
# On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # # modified: test.c # modified: TODO # no changes added to commit (use "git add" and/or "git commit -a")
84
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h test.c <- new file TODO IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO <- new file
git add TODO
85
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h test.c <- new file TODO IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO <- new file
git add TODO
$ git status
# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: TODO # # Changed but not updated: [...]
86
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h test.c <- new file TODO IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO
git commit
deadbeef
87
04f087b
master
IDEAS Makefile README <- edited src |-- Makefile |-- helloworld.c `-- helloworld.h test.c <- new file TODO IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO
deadbeef
88
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h test.c <- new file TODO IDEAS Makefile README <- edited src |-- Makefile |-- helloworld.c `-- helloworld.h TODO
deadbeef
git add README
89
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h test.c <- new file TODO IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO
git commit
deadbeef f4ec56
90
04f087b
master
IDEAS <- 3 hunks Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h test.c <- new file TODO IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO
deadbeef f4ec56
91
04f087b
master
IDEAS <- 2 hunks Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h test.c <- new file TODO IDEAS <- 1 hunk Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO
deadbeef f4ec56
git add -p IDEAS
(also see git add --interactive)
92
04f087b
master
IDEAS <- 2 hunks Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h test.c <- new file TODO IDEAS <- 1 hunk Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO
deadbeef f4ec56
git add -p IDEAS
(also see git add --interactive) $ git add -p src/xmms/testclient.c
[...] @@ -44,7 +44,7 @@ int main (int argc, char **argv) fd = xmms_ipc_transport_fd_get (transport);
+ msg = xmms_ipc_msg_string_new (42, "apan!"); i = 5; Stage this hunk [y/n/a/d/j/J/?]?
93
04f087b
master
IDEAS <- 2 hunks Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h test.c <- new file TODO IDEAS <- 1 hunk Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO
deadbeef f4ec56
git diff git diff --cached git diff HEAD
94
04f087b
master
IDEAS <- merged Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO IDEAS <- conflicted Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO
deadbeef f4ec56
95
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO
deadbeef f4ec56
96
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO
deadbeef
git reset --hard deadbeef
reset the repository HEAD, the index and the working directory.
Warning: any uncommitted change is lost!
deadbeef deadbeef f4ec56
97
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO
deadbeef
git reset --soft deadbeef
repository HEAD.
f4ec56 f4ec56 f4ec56
Previous commit becomes “changes to be committed”.
98
04f087b
master
IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO IDEAS Makefile README src |-- Makefile |-- helloworld.c `-- helloworld.h TODO
deadbeef
git reset --mixed deadbeef
f4ec56 deadbeef
reset the repository HEAD and the index, but not the working directory.
Keep changes but not marked for commit.
f4ec56
99
100
Source: http://osteele.com/archives/2008/05/commit-policies
101
102
master
A B C D
K
103
master
A B C D
K
104
E F
master
A B C D
105
E F
master
A B C D T (E+F) B S (D)
106
107
master
A B C D H
HEAD
108
master
A B C D H
HEAD
109
master
A B C D H
HEAD
110
master
A B C D H
HEAD
111
master
A B C D H
HEAD
112
master
modifs
113
master stash@{0}
modifs
114
master stash@{0}
modifs
115
modifs
master stash@{0}
modifs
116
Git Repository
Git Working Copy
SVN Repository
SVN Working Copy
git svn svn Git SVN
117
118
Source: http://chem-bla-ics.blogspot.com/2008/10/git-eclipse-integration.html
119
Source: http://bogolisk.blogspot.com/
120
121
Url: http://github.com/
http://git-scm.com/
http://www.youtube.com/watch?v=8dhZ9BXQgc4
http://www.youtube.com/watch?v=4XpnKHJAok8
http://whygitisbetterthanx.com/
122
123
124
125