Source Code Management
Version Control System!
Revision Control System
! because we need to keep track of changes:
what was the content? !
who? (very important, right? :))
! centralized SCMs: Subversion, CVS
! distributed SCMs: GIT, Mercurial
5. Centralized vs. Distributed
master copy in one
everyone has a full
copy - distributed!
single point of failure!
works offline or
disconnected from a
considers data as a list
of file -based changes
(initial version + deltas) !
a commit operates over
the central repository
saves snapshots of data
it manages !
a commit operates over
the local repository
6. SVN model
7. GIT model
Client 1 !
8. GIT --history
British slang for "pig headed, think they are always
2005, Linux kernel maintenance (35000 files)!
written in C
"So I'm sorry, but for something like git, where efficiency was a primary !
objective, the "advantages" of C++ is just a huge mistake. The fact that !
we also piss off people who cannot see that is just a big additional !
modern, robust, fast, distributed, great branching
system, complex merges, open source!
available on Mac, Windows, Linux
9. GIT --philosophy
a git repository is a....graph, Directed Acyclic Graph!
node = commit!
edge = pointers from child nodes to parent node(s)!
nodes are identified by SHA-1 hashes from: content change +
parent(s) commit identifier => speed!
a lot of the work done by git involves moving references
(labels) around => speed
10. GIT --philosophy
git references = labels assigned to commits !
several types: branch (local/remote), tag, stash!
references are stored in .git/refs/heads ( the SHA-1
identifier of the commit it points to, 41 bytes)!
there are references to references -> HEAD, for example,
which points to the current branch!
references make commits reachable
11. GIT --philosophy
fast forward merge
12. GIT --philosophy
13. GIT --concepts
git manages its content via 3 states: modified, staged,
14. GIT --concepts
Workspace (working directory)
one version of the content, extracted from git database to be
used or modified
15. GIT --concepts
Staging area (index)
allows you to elect files/content that is going to participate in
the next commit!
you can see how the next snapshot would look like before
actually creating it - avoid mistakes!
allows you to break changes in workspace into more than 1
16. GIT --concepts
where object database and metadata is stored!
the .git folder inside your repository root folder
17. GIT --concepts
git manages its content via 3 4 states: modified,
staged, committed, stashed!
here you can save changes you want to keep but
not ready to commit yet!
stashes are in fact labeled nodes on the
18. GIT --concepts
19. GIT --concepts
git repository located on another machine, usually!
the local repository may be a mirror of the remote one!
write into it via push, read from it via pull & fetch
20. GIT --concepts
21. GIT --concepts
blobs - contents of a file!
tree - directories of blobs or other trees!
commits - SHA-1 of a tree, parent commit(s), message!
22. GIT --@work
Create a repository
initializes a new, empty repository, inside the current directory
git clone https://email@example.com/
clones the remote repository on the local machine, inside a
newly created git-scm-remote folder
23. GIT --@work
Prepare a commit (stage)
git add <file> | <pattern>
marks the file(s) as belonging to the next commit, i.e. changes
git reset <file>
removes the file from the staging area
24. GIT --@work
git commit -m "Commit message"
records the commit in the repository history
git commit --amend
modifies the last commit by adding the staged changes
25. GIT --@work
git checkout -- <file>
the <file> contents in working directory is replaced with the
last committed one
git reset --hard <branch/commit/tag>
discards commits until the one pointed to by the reference
git revert <commit>
reverses the specified commit by creating a new one
26. GIT --@work
saves the working directory state and pushes it on the stashes
git stash apply
gets the most recent stash and applies it to the working
27. GIT --@work
git push <server> <branch>
pushes your changes on the specified branch of the remote
git format-patch HEAD --stdout > mypatch.patch
git fetch <server>
pulls down all the data from the remote repo that you don't
have yet on tracked branches
does a git pull and merges those on your current branch
28. GIT --@work
git branch <branch name>
creates a new branch starting from your last commit
git checkout -b <branch name>
creates a new branch starting from your last commit and
switches to it
git branch -d <branch name>
deletes the specified branch
29. GIT --@work
git merge <branch name>
merges the specified branch into the current one
git rebase <branch name>
rebases the specified branch onto the current one
30. GIT --@work : merge
31. GIT --a branching model
32. GIT --@work
prints out the commit tree from the current HEAD
shows info like: current branch, working directory status,
git stash show
shows the most recent stash
shows where you are in repository history relatively to the latest
tag, i.e a revision number. Eg: v1.0.0-50-g1f8115b
33. GIT --@work
git diff <commit>
shows the diff between working directory and specified commit
git branch [-r]
lists either local or remote (-r) branches
34. GIT --@work
35. GIT --@work
git tag v1.0.0 -m "My first release"
creates a "lightweight" tag, i.e. an immovable reference on the
git tag v1.0.0 -a -m "My first release"
creates an "annotated" tag, i.e. an immovable reference on the
current head + info like: tagger, email, date which are stored in
the git database
36. GIT --@work
git cherry-pick <commit>
integrates changes in specified commit into the current branch
given a start and an end commit reference it will checkout
commits within that range allowing to find a regression
annotates each line in a file with that last commit to change it
37. GIT --repository
.gitignore file to express ignore patterns, can be put in
git repos smaller than SVN ones, 30x in case of Mozilla!
steep learning curve (debatable)!
can't checkout part of a repository!
oriented towards content rather than files !
for transport it supports: HTTP, SSH, GIT protocols!
objects are generally added not deleted, reason for git gc
38. GIT --how to
latest release http:/
works from CLI!
good GUI clients:
Github for Mac/Win, free ("optimized" for github.com remotes,
but works with others too)!
SourceTree (Mac & Win), free!
39. (Em)Powered by GIT
40. GIT SCM
local, flexible, fast
non-linear, facilitates collaboration