Download presentation
Presentation is loading. Please wait.
1
Git All hail the octo-cat
Sean Dague
2
The Bad (not so) Old Days
3
Selective SCM History SCCS Original source code control system
Local only, single file at a time RCS GNU implementation of local SCM (same basic limitations as SCCS) CVS Wrapped RCS with concept “changesets” Provided a network server
4
Selective SCM History SVN “CVS done right”
global repository versioning support for file renames Bitkeeper Not open source Designed around Linux Kernel workflow license revoked “reverse engineering” spat Then the anti market kicked in... git, hg, monotone, bzr
5
The Concurency Issue Master Tree Sean Joe
6
The Locking Solution Master Tree Sean Joe
7
The Opportunistic Locking Solution
Master Tree Sean Joe
8
The Keep Everything Solution
Master Tree Sean Joe
9
The Keep Everything Solution
Master Tree Sean Keep this in mind, we'll come back to it later Joe
10
Content Addressable Storage
/home/sdague/foo.txt Inode: 569 Some file
11
Content Addressable Storage
/home/sdague/foo.txt SHA1: f4ed Some file Inode: 569
12
Content Addressable Storage
cp foo.txt foo2.txt /home/sdague/foo.txt /home/sdague/foo2.txt SHA1: f4ed Some file Inode: 569
13
Content Addressable Storage
It doesn't matter where the file is, if it's the same contents /usr/local/file.txt /home/sdague/foo.txt SHA1: f4ed SHA1: f4ed Inode: 569 Some file
14
CAS + Directed Graph Courtesy
15
Git Truisms Changes in local content addressable storage
Uses cryptographically strong SHA1 hash to identify changes Each change includes a reference to the parent change(s) that it is based Every repository is an equal clone Git makes it really hard to loose data
16
Git Basic Commands Network/Repo init – create a new repository
clone – make a local copy of a tree pull – update tree from remote tree push – push changes to remote tree Making Changes add – add a file to be versioned commit – add changes rm – remove a file mv – move a file (often not needed)
17
Git Basic Commands Inspecting diff - show what's changed
log - show a time linear log of changes status - show what would be commited on a commit Oh Crap! Undo! Undo! Undo! reset --hard - get back to the last commit checkout -- $file - reset a single file from commit revert $version - revert a previous commit
18
Simple git workflow for 1
git clone $repo make changes git add $file1 $file2 … git commit -a rinse, wash, repeat git push Demo time!
19
Branching Quick in tree branching is one of the git selling points
Branching Commands branch - displays current branches branch $name - creates a new branch checkout $name - switches to a branch You'll get yelled at if you try to switch branches with outstanding changes.
20
Merging Most of the time, it just happens and you don't realize it
Commands that merge pull - automatically generates a merge commit if needed merge - for manual operations, you rarely need this
21
A note on diagrams to come
Arrows point in flow direction instead of towards parents Different colors are meant to represent different hash values Courtesy
22
Branching & Merging Master Tree Ok, we're keeping everything
but now we have a new problem. Which change represents head? Bug 1 Bug 2
23
Rules of Trees A branch should only have 1 head. If you do something that would make a second head, git will try to stop you A changeset can have more than 1 parent A changeset doesn't need to have content in the traditional sense
24
Merging Master Tree Can't push from bug 1 branch because it would
make 2 headed master Bug 1 Bug 2
25
Merging Master Tree git pull pulls down changes Bug 1
26
Merging Master Tree git pull pulls down changes automatically builds a
merge commit Bug 1
27
Merging Master Tree now a git push works correctly Bug 1
28
Merging Master Tree And once we are all done we have identical trees
Bug 1
29
Merging with conflicts
Git will handle most merges automatically new files file renames multiple changes in files (as long as they aren't the same lines) combinations of the above If git can't automatically create the merge commit it will stop and dump out to an interactive mode. You manually create the fix up patch that lets things move forward
30
Fixing Screwups reset --hard revert checkout -- uncommitted files
31
Rebase... there be dragons...
There is another merge like operations that deserves attention - rebase rewrites your changesets to be based on a different parent common usage for side patches private fixes you can't release (yet) working changes for upstream Important: do not publicly expose rebased trees, it makes life difficult for everyone
32
Rebase Master Tree Bug 1
33
Rebase Master Tree rebase first pulls in all the new changes
from the target tree Bug 1
34
Rebase Master Tree rewrites your changes to be against a new parent
Bug 1
35
Rebase Master Tree Destroys old changes Bug 1
36
Rebase Master Tree Destroys old changes Bug 1
37
Rebase Master Tree Rebase does not push changes. At this point you
could push cleanly, or hold onto your changes for future rebasing Bug 1
38
Why you don't rebase public trees
Master Tree Bug 1 Bob
39
Why you don't rebase public trees
Master Tree Bug 1 Bob now can't make a sane merge tree with Bug 1, as it got rid of changes his merge was working with Bob
40
Why you don't rebase public trees
Master Tree The fix sucks. First you have to purge out nodes in your tree (through creating a branch and rewinding). Then 1 rebase against the new base. Bug 1 Bob
41
Why you don't rebase public trees
Master Tree Bug 1 Then another rebase against the newly pulled changes. Bob
42
Git with teams When using git with multiple people the typical pattern is that everyone has 1 or more public trees and pull is used to integrate other people's changes. push is really only used within a set of trees/branches that you own.
43
Git with teams Sean Master Tree Sean Working Joe Working
44
Git with teams Sean Master Tree changes are done, pull into master
Sean Working Joe Working
45
Git with teams Sean Master Tree
Joe is ready to get his changes in, so he syncs with master, and puts his tree up somewhere public Sean Working Joe Working
46
Git with teams Sean Master Tree Sean pulls in Joe's changes
including the merge into public master Sean Working Joe Working
47
Git with teams Sean Master Tree Rinse, Wash Sean Working Joe Working
48
Git with teams Sean Master Tree Rinse, Wash Repeat Sean Working
Joe Working
49
Setting up your own public repo
If it's open source, consider using github.com if on ubuntu/debian use git-daemon-run uses a git custom protocol to get changes it is also possible to set up git server with vanilla http it's over 100x slower for large trees
50
Git Advantages O(1) runtime for access to changes
Cryptographicly secure Branching/Merging make it really simple to try out new things Very space efficient Versions metadata as well as data (+x bits) No bloody line ending convert games Plays mostly well with others
51
Git Gui (Linux)
52
More Bits of Git Windows Support via TortoiseGit (like TortoiseSVN)
complete enough now that git on windows is a real otpion git-svn bridge extendable via plugins git format-patch / send- - for workflows
53
Learning more on Git consult your man pages
54
Backup
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.