Introduction to Git (Greg Lonnon)
-
Upload
boise-web-technologies-group -
Category
Technology
-
view
6.786 -
download
2
Transcript of Introduction to Git (Greg Lonnon)
Git Intro
agenda
source code management (SCM) tools
gitdesign
usage
Who is Greg?
SCM geek...Sccs,rcs,cvs,svn,clearcase,perforce, and now git
Master Architect @ HPFutureSmart product line enterprise imaging products
YouTube FutureSmart Video
I still use the tag...I don't care about IE...
SCM???
Attributes of a SCM toolTrack (folders and files)Individually or in sets (change sets)
Branch Independent changes
Common starting points
Release, feature development, etc...
Merge Combine 2..N branches into 1
HistoryWhat, when, why questions
SCM Evolution
tar/zip
RCS
SVN
CVS
clearcaseperforce
git/hg/bazaar
SCM: the new guys
git, hg, bazaar
peer to peer architecture
atomic change set basedfile changes are grouped together as a transaction
takes advantage of local machine featuresCPU and Disk
What is git?
One of the new guys
A tree based content management storage systemwith SCM'ish commands
Developed for Linux kernelLinus Torvald wrote the first version
Ported to Windows, OSX, any posix based OS
Many GUI clients
git Storage Design
git storage design is the key concept to understand
It's simple, based on...Cryptography theory
Database theory
Graph theory
Set theory
git storage (repository)
Object based Storage(Key,Data) tuple key = SHA1(data)
keys are 20 byte arrays.
SHA1 algorithm crypto algorithm
Datablobs : files, sym-links
trees : directories
commit : points to a tree, and other commits
tag : points to a commit
Git: blobs
#include int main(){printf(hello world); return 0;}
Blobs: files (text and binary), symlinks
git: tree
permission
object
hash
name
100644
blob
82354a1...
README
100755
blob
02342c5...
a.out
040000
tree
a67ef32...
02342c...
src
Trees: aka directories
git: commit
date
author
parents
comment
tree
Mon Dec 20 16:10:41 2010 -0700
joe developer
234ab23...
Fixed the border defect
89023a2...
git: tag
date
tagger
Mon Dec 20 16:10:41 2010 -0700
joe developer
234ab23...
commit
comment
Release 1.0
git: repo
C3C1C2
T1
B2B1
T1T2
B2
B1
T1B1
git initecho hello > B1git add B1git commit
echo world > B2git add B2git commit
C3C1C2
T2
B2B1
T3T2
B2
B1
T1B1
git initecho hello > B1git add B1git commit
mkdir T2git mv B1 B2 T2cp T2/B1 B3git add B3git commit
Time
git: repo
C3C1C2
T1
T1T1B1
C3C1C2
T2B2
T3
T1B1
git : DAG
Wikipedia...In mathematics and computer science, a directed acyclic graph (commonly abbreviated to DAG), is a directed graph with no directed cycles. That is, it is formed by a collection of vertices and directed edges, each edge connecting one vertex to another, such that there is no way to start at some vertex v and follow a sequence of edges that eventually loops back to v again.
git : DAG
C1C1C1C2C1C3C1C6C1C8
C4C5C7
masterHEAD
work_br
V1.0
git referencesbranches (master, work_br)
tags : immutable (V1.0)
git: DAG
C1C1masterHEAD
git initgit commit
git: DAG
C1C1masterHEAD
git branch work_br
work_br
git: DAG
C1C1C1C2
masterHEAD
git commit
work_br
git: DAG
C1C1C1C2C1C3
masterHEAD
work_br
git commit
git: DAG
C1C1C1C2C1C3
C4
masterHEAD
work_br
git checkout work_brgit commit
git: DAG
C1C1C1C2C1C3
C4C5
masterHEAD
work_br
git commit
git: DAG
C1C1C1C2C1C3C1C6
C4C5
masterHEAD
work_br
git checkout mastergit merge work_br
git: DAG
C1C1C1C2C1C3C1C6
C4C5C7
masterHEAD
work_br
git checkout work_brgit commit
git: DAG
C1C1C1C2C1C3C1C6C1C8
C4C5C7
masterHEAD
work_br
git checkout mastergit commit
git repository
Each git repo contains complete historyAll git objects are stored in the repo
Peer to Peer Design
.git directoryobjects
referencesbranches, tags : files that contain commit hash
HEAD : current checkout hash
git clone
C1C1C2C1C3
C4C5
masterwork_br
C1C1C2C1C3
C4C5
origin/masterHEAD
origin/work_br
http:/github.com// origin
git clone http://github.com// local
git clone copies the remote objects/references to anew repositoryThe remote repo is nicknamed origin, a remote tracking branch is created to track origin/master
local
master
git fetch
C1C2C3C4C5masterwork_brC6
C1C2C3C4C5origin/masterHEAD
work_br
C1C2C3C4C5origin/masterHEAD
work_brC6
C7
git fetch origin
origin
local
local
Fetch moves C6 commit objects to the local repo, and updates the tracking branch origin/master
master
masterorigin/work_br
origin/work_br
git push
C1C2C3C4C5masterwork_brC6
git push origin
origin
Push local to origin.The local work_br is a proper superset ofthe origin work_br branch, and the origin isupdated.The local master push fails, it is NOT a not a proper superset of the origin master branch
C1C2C3C4C5masterwork_brC6
C7
origin
C1C2C3C4C5origin/masterHEAD
work_brC6
C7
local
masterorigin/work_br
git pull
git pullgit fetch + git merge
git: merge algorithms
git mergeMerges 1..N branches into current branch (HEAD)
git merge --squashgit merge with no parent tracking (merge tracking)
git cherry-pickCalculates the file differences of the commit and applies them to current branch (HEAD)
git rebaseMoves a related set of commits to a new base reference.
git merge
C1C1C1C2C1C3
C4C5
masterHEAD
work_br
git merge work_br
C1C1C1C2C1C3C1C6
C4C5
masterHEAD
work_br
Merges 1 or more branch into the current branch.
git merge --squash
C1C1C1C2C1C3
C4C5
masterHEAD
work_br
git merge --squash work_br
C1C1C1C2C1C3C1C6
C4C5
masterHEAD
work_br
Merges a branch, but does not track the merge.Useful in large repositories with a lot of activity.
git cherry-pick
C1C1C1C2C1C3
C4C5
masterHEAD
work_br
git cherry-pick C5
C1C1C1C2C1C3
C4C5
work_br
C5'
master
HEAD
Calculates and applies the file changes of a commit. Useful for moving changes between a release branch and main development
git rebase
C1C1C1C2C1C3
C4C5
masterHEAD
work_br
git rebase master
C1C1C1C2C1C3
C4C5
masterHEAD
work_br
C4'C5'
Moves a family of commits to a new baseUseful for developers to refresh their branch.
git rebase: a closer look
C1C1C1C2C1C3
C4C5
masterHEAD
work_br
C4'C5'
d1d2d1d2Step 1: Apply d1 to C3
Step 2: Apply d2 to C4'
git commands
porcelain
Repositorygit init, git clone, git fetch, git pull, git push, git gc, git config
Working treegit checkout, git reset, git clean, git add, git commit
Branchgit branch, git tag, git merge, git rebase, git cherry-pick, git revert, git mergetool
Historygit log, git diff, git difftool, git reflog
git commands
plumbing
Git low level commandsEasy to parse output
Stable API
Use them for scripting git
100+ commands...
gitk
git gui
git hints
CommitWhen something compiles, passes a test, before refactoring, before going to lunch/home/sleep, or... when you have nothing else to do...
Use commits to separate out features, debug, temporary work, etc...
git != svn, don't treat it like svn...
Use git reflog to find lost commits
Create a sandbox (git init) and play...
git : Web Resources
Use google...http://git-scm.com/
Free Pro Git bookhttp://progit.org/book/
Free Webcastshttp://gitcasts.com/
http://oreillynet.com/pub/e/1394
Free Open Source Hosting (cheap commerical hosting)https://github.com/
Gitolite : git server supports complex security models
https://github.com/sitaramc/gitolite
Windows executableGit-extensions or msysgit
Muokkaa otsikon tekstimuotoa napsauttamalla
Muokkaa jsennyksen tekstimuotoa napsauttamallaToinen jsennystasoKolmas jsennystasoNeljs jsennystasoViides jsennystasoKuudes jsennystasoSeitsems jsennystasoKahdeksas jsennystasoYhdekss jsennystaso
Muokkaa otsikon tekstimuotoa napsauttamalla
Muokkaa jsennyksen tekstimuotoa napsauttamallaToinen jsennystasoKolmas jsennystasoNeljs jsennystasoViides jsennystasoKuudes jsennystasoSeitsems jsennystasoKahdeksas jsennystasoYhdekss jsennystaso
Muokkaa otsikon tekstimuotoa napsauttamalla
Muokkaa jsennyksen tekstimuotoa napsauttamallaToinen jsennystasoKolmas jsennystasoNeljs jsennystasoViides jsennystasoKuudes jsennystasoSeitsems jsennystasoKahdeksas jsennystasoYhdekss jsennystaso
Muokkaa otsikon tekstimuotoa napsauttamalla
Muokkaa jsennyksen tekstimuotoa napsauttamallaToinen jsennystasoKolmas jsennystasoNeljs jsennystasoViides jsennystasoKuudes jsennystasoSeitsems jsennystasoKahdeksas jsennystasoYhdekss jsennystaso
Muokkaa otsikon tekstimuotoa napsauttamalla
Muokkaa jsennyksen tekstimuotoa napsauttamallaToinen jsennystasoKolmas jsennystasoNeljs jsennystasoViides jsennystasoKuudes jsennystasoSeitsems jsennystasoKahdeksas jsennystasoYhdekss jsennystaso