an introduction to the git revision control system
DESCRIPTION
An Introduction to the Git Revision Control System. Jonathan Adamczewski. This presentation is not One VCS is better than another Me telling you that you should use Git Anyone suggesting that Insomniac will stop using Perforce This presentation is an introduction to Git : How it works - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/1.jpg)
An Introduction to theGit Revision Control System
Jonathan Adamczewski
![Page 2: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/2.jpg)
This presentation is not• One VCS is better than another• Me telling you that you should use Git• Anyone suggesting that Insomniac will stop
using Perforce
This presentation is an introduction to Git:• How it works• Ways that it is or isn’t like Perforce
![Page 3: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/3.jpg)
GIT VS PERFORCE
FIGHT.
![Page 4: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/4.jpg)
Perforce• Submit
Git• Commit
![Page 5: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/5.jpg)
Perforce• Submit
-> Changelist
Git• Commit (verb)
-> Commit (noun)
![Page 6: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/6.jpg)
Perforce• Centralized storage• Centralized history• Centralized collaboration• Connection to server is
required• p4 edit
Git• Distributed storage• Distributed, divergent
histories• Peer to peer collaboration• Central server optional• ---
![Page 7: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/7.jpg)
Perforce• Files are versioned
• Server-wide incrementing changelist number
Git• Entire working copy is
versioned (snapshots)• Every commit has a unique
SHA-1 hash from:– Parent commit(s)– Description– Author– Content
![Page 8: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/8.jpg)
Perforce• Client view maps file in
depots to local files on client system
Git• Every clone of a git
repository stores the entire history of the repository
![Page 9: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/9.jpg)
“A Perforce branch is a branch of file hierarchy. A Git branch is a branch of workspace history.”
![Page 10: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/10.jpg)
Perforce• One set of local changes per
file• No history stored outside of
the server
Git• Create arbitrary file
histories and store them in local branches
![Page 11: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/11.jpg)
Perforce• Branching
– Cost scales with size– Expressed as a duplication
and divergence in the file hierarchy
• Branch cost depends on the size & number of files being branched
Git• Branching is
– Very cheap– Expressed as a new pointer
associated with a single commit
• Branch cost is constant:One 41 byte file per branch.
![Page 12: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/12.jpg)
Perforce• Changing branches usually
means moving to a different directory
cd \core\users\jadamczewski \code
Git• Changing branches usually
happens in one working copy
git checkout some_branch
![Page 13: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/13.jpg)
Perforce• One set of local changes per
file• Looks like:
– File can be in only one pending changelist
– Easy to miss files when submitting
Git• Arbitrary local histories
• Looks like– Nothing quite like
pending changelists– Modified files are staged and
then committed
![Page 14: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/14.jpg)
With great power comes great blahblablah
![Page 15: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/15.jpg)
Perforce• One set of local changes per
file• One resolve per file before
submit
Git• Potentially many local
changes per file• Potentially many resolves
per file before submit– Not usually that bad– git rebase
![Page 16: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/16.jpg)
Perforce• A mighty server dedicated
to storing all the versions of all the files
• Handles anything and everything – text, binary, large, small
Git• Every user’s machine is
their git server – not dedicated to just git
• Not good with large, frequently changing binary files– Repo size increases quickly
![Page 17: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/17.jpg)
Perforce• shelve
– For backup and collaboration– Stores a copy on the server– Allows local revert without
losing changes
• Generally inconvenient to move uncommitted changes between branches
Git• branch/commit
– Store a copy in the local repo
• clone or push(or just copy the repo)– Duplicate the [contents of] the
repo somewhere else– For backup and collaboration
• Many ways to get commits from another repo
![Page 18: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/18.jpg)
Perforce• shelve
– Sometimes just to stash some changes easily off to the side
Git• stash
– Just to stash some changes easily of to the side
– stashed changes are kept in a stack, and can be re-applied later
![Page 19: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/19.jpg)
Perforce• Submit means there is
redundancy – the data exists on your machine and the server.
Git• Commit only stores changes
on your local HDD
• Need to push, copy, or otherwise share the commit to have a redundant copy
![Page 20: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/20.jpg)
• Git directory structure:
repo_dir/
.git/<git’s many files>
your workspace
![Page 21: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/21.jpg)
• How to commit a file:– Make changes to files in the working directory.
Does not require marking for edit.(edit, add, delete, copy, etc)
– Stage the files for commit. Does not affect the recorded history for the current branchgit add, git rm, git mv
– Commit the files to the repository.git commit
![Page 22: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/22.jpg)
• http://git-scm.com/book/en/Distributed-Git-Distributed-Workflows shows what some real world distributed workflows look like
![Page 23: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/23.jpg)
• http://git-scm.com/book/en/Distributed-Git-Maintaining-a-Project has information about maintaining repos in a distributed environment
![Page 24: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/24.jpg)
Some commonly used git commands
# reset contents of working dir git reset
# manipulate branches git branch
# populate working dir with a commitgit checkout
# merge multiple branchesgit merge
![Page 25: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/25.jpg)
# reapply changes to a different # commitgit rebase
# rewrite history git rebase –i
# stage a file for commitgit add
# stage parts of files for commitgit add -i
![Page 26: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/26.jpg)
# show the current state of the # working dir. Lists new and modified # files and files staged for commitgit status
# list commits in a branch from the # most recentgit log
# list files know to git in a branchgit ls-files
![Page 27: An Introduction to the Git Revision Control System](https://reader036.vdocument.in/reader036/viewer/2022062521/56816388550346895dd475ed/html5/thumbnails/27.jpg)
# search through files known to git – # very fast!git grep
# show changes between thingsgit diff
# get a basic graphical UIgitk
# copy commits from one branch to anothergit cherry-pick