116
GIT (FS AND DVCS) by generated: Michal Jurosz (mj41) 8.6.2015

Git (FS and DVCS)

Embed Size (px)

Citation preview

Page 2: Git (FS and DVCS)

GIT FS"I really really designed it coming atthe problem from the viewpoint of a

filesystem person (hey, kernels is whatI do), and I actually have absolutely

zero interest in creating a traditionalSCM system."

-- Linus Torvals

Page 3: Git (FS and DVCS)

GITa content-addressable filesystemmanages tree snapshots (joined by commits)over timedistributed version control system

Page 4: Git (FS and DVCS)

WHY GIT? LINUX2002 - 2005 proprietary BitKeeper

Apr 7, Linus Torvals - based on BitKeeperconcepts

May 26 - Linux 2.6.12 - the first release with Git

December 21 - Git 1.0

Msg: Initial revision of "git", the information manager from hellAuthor: Linus Torvalds <[email protected]>Date: Thu Apr 7 15:13:13 2005 0700Files: catfile.c, committree.c, showdiff.c, ...

Page 5: Git (FS and DVCS)

LINUX NEEDSdistributed, fast, many files, robusteffective storage - full historynon-linear development, trial branches, complexmergestoolkit-based design, pluggable merge strategiescryptographic authentication of history

Page 6: Git (FS and DVCS)

ANNUAL LINUX DEVELOPMENT REPORTby Linux Foundation - April 3, 2012Linux 3.2 release - Apr 1, 2012

15,004,006 lines of code72 days since 3.1.

11,881 patches, 6.88 per hour1,316 developers from 226 organizations

2005-201512,000 developers from 1200 organizations

Page 7: Git (FS and DVCS)

NO SILVER BULLETpermissions, ownership, empty directories, ...individual files (not project's files)large binary files ( )GitHub: Git LFS

complexity - commit/push, checkout/cloneno subtree of repository checkoutno sequentially revision numbers

CVS 10%, Git 38%, Subversion 46% - ohloh.net

Page 8: Git (FS and DVCS)

PIT STOP 1short intro

Questions?

Page 9: Git (FS and DVCS)

GIT HELP> git helpusage: git [version] [help] [C <path>] [c name=value] [execpath[=<path>]] [htmlpath] [manpath] [infopath] [p|paginate|nopager] [noreplaceobjects] [bare] [gitdir=<path>] [worktree=<path>] [namespace=<name>] <command> [<args>]

The most commonly used git commands are: add Add file contents to the index bisect Find by binary search the change that introduced a bug branch List, create, or delete branches checkout Checkout a branch or paths to the working tree clone Clone a repository into a new directory commit Record changes to the repository diff Show changes between commits, commit and working tree, etc fetch Download objects and refs from another repository grep Print lines matching a pattern init Create an empty Git repository or reinitialize an existing one

Page 10: Git (FS and DVCS)

PORCELAIN/PLUMBINGporcelain

high leveluser

plumbinglow levelscripts (e.g. null string separators)upward compatible

Page 11: Git (FS and DVCS)

GIT HELP -A> git help ausage: git [version] [help] [C <path>] [c name=value] [execpath[=<path>]] [htmlpath] [manpath] [infopath] [p|paginate|nopager] [noreplaceobjects] [bare] [gitdir=<path>] [worktree=<path>] [namespace=<name>] <command> [<args>]

available git commands in '/usr/libexec/gitcore'

add mergeonefile addinteractive mergeours am mergerecursive annotate mergeresolve apply mergesubtree archive mergetree bisect mergetool bisecthelper mktag blame mktree

Page 12: Git (FS and DVCS)

GIT INIT> cd ~/gittt

> mkdir repoMJ

> cd repoMJ

> git initInitialized empty Git repository in /home/linus/gittt1433775564435/repoMJ/.git/

> ls a....git

Page 13: Git (FS and DVCS)

GIT FILES (EMPTY)> tree aF .git.git| HEAD| branches/| config*| description| hooks/| info/| exclude| objects/| | info/| pack/ refs/

| heads/ tags/

9 directories, 4 files

Page 14: Git (FS and DVCS)

THE THREE TREES 1/2"HEAD tree" (in local repository)

HEAD - the snapshot of your last commitindex - cache, staging area

proposed next commit snapshotworking directory (working tree)

sandbox, files you see

Page 15: Git (FS and DVCS)

Upstream Origin

Local repository

Index (cache)

Working directory

Page 16: Git (FS and DVCS)

WORKING DIRECTORY> pwd/home/linus/gittt1433775564435/repoMJ

> echo "textA line 1" > fileA.txt

> echo "textB line 1" > fileB.txt

> ls a....gitfileA.txtfileB.txt

Page 17: Git (FS and DVCS)

GIT STATUS> git statusOn branch master

Initial commit

Untracked files: (use "git add <file>..." to include in what will be committed)

fileA.txt fileB.txt

nothing added to commit but untracked files present (use "git add" to track)

> git status short?? fileA.txt?? fileB.txt

Page 18: Git (FS and DVCS)

INDEX (STAGE, CACHE)NAME gitlsfiles Show information about files in the index and the working tree

> git lsfiles cached

> git add fileA.txt

> git lsfiles cachedfileA.txt

Page 19: Git (FS and DVCS)

GIT STATUS (AGAIN)> git statusOn branch master

Initial commit

Changes to be committed: (use "git rm cached <file>..." to unstage)

new file: fileA.txt

Untracked files: (use "git add <file>..." to include in what will be committed)

fileB.txt

> git status shortA fileA.txt?? fileB.txt

Page 20: Git (FS and DVCS)

ADD TO INDEX (STAGE, CACHE)objects - blob, tree, commit, tag

type, size, contentSHA-1 hash/checksum - 160-bit, 20 bytes

40 hexadecimal number - e.g.8e4b68ee140cfbeaee5d38671cb03c83d1b6f2a4default 7 shown- e.g. 8e4b68eminimum 4 required - e.g. 8e4b

> git hashobject fileA.txt8e4b68ee140cfbeaee5d38671cb03c83d1b6f2a4

Page 21: Git (FS and DVCS)

.GIT AFTER INDEX CHANGE 1/4> find .git/objects type f.git/objects/8e/4b68ee140cfbeaee5d38671cb03c83d1b6f2a4

> git add fileA.txt

> find .git/objects type f.git/objects/8e/4b68ee140cfbeaee5d38671cb03c83d1b6f2a4

> tree aF .git

Page 22: Git (FS and DVCS)

.GIT AFTER INDEX CHANGE 2/4.git .git| HEAD | HEAD| branches/ | branches/| config* | config*| description | description| hooks/ | hooks/ > | index| info/ | info/| exclude | exclude| objects/ | objects/ > | | 8e/ > | | 4b68ee140cfbea| | info/ | | info/| pack/ | pack/ refs/ refs/

| heads/ | heads/ tags/ tags/

Page 23: Git (FS and DVCS)

.GIT AFTER INDEX CHANGE 3/4> hexdump .git/objects/8e/4b68ee140cfbeaee5d38671cb03c83d1b6f2a4 | head n10000000 0178 ca4b 4fc9 3052 6634 4928 28ad 5471

gitcatfile Provide content or type and size information

> git catfile p 8e4b68ee140cfbeaee5d38671cb03c83d1b6f2a4textA line 1

> git catfile t 8e4b68ee140cfbeaee5d38671cb03c83d1b6f2a4blob

> git catfile s 8e4b68ee140cfbeaee5d38671cb03c83d1b6f2a413

Page 24: Git (FS and DVCS)

.GIT AFTER INDEX CHANGE 4/4> git hashobject fileA.txt8e4b68ee140cfbeaee5d38671cb03c83d1b6f2a4

> git catfile t 8e4b68ee140cfbeaee5d38671cb03c83d1b6f2a4blob

> file .git/index.git/index: Git index, version 2, 1 entries

> git lsfiles cachedfileA.txt

> find .git/objects type f | head n 5.git/objects/8e/4b68ee140cfbeaee5d38671cb03c83d1b6f2a4

Page 25: Git (FS and DVCS)

GIT OBJECTSblobtreecommittag

Page 26: Git (FS and DVCS)

GIT OBJECTS: BLOB, TREEa blob object - content of a file

no file name, time stamps, or other metadataa tree object - the equivalent of a directory

describes a snapshot of the source treenames of blob and tree objects (type bits)

Page 27: Git (FS and DVCS)

GIT OBJECTS: COMMITa commit object

links tree objects together into a historythe name of a tree object (of the top-levelsource directory)a time stamp, a log messagethe names of zero or more parent commitobjects

Page 28: Git (FS and DVCS)

GIT OBJECTS: TAGa tag object

a container that contains reference to anotherobjectand can hold additional meta-data

Page 29: Git (FS and DVCS)
Page 30: Git (FS and DVCS)

FIRST COMMIT (ATTEMPT)> git commit m"commit 01 message"[master (rootcommit) 7d6e090] commit 01 message 1 file changed, 1 insertion(+) create mode 100644 fileA.txt

Page 31: Git (FS and DVCS)

CONFIG --GLOBAL (USER)> cat ~/.gitconfig[user] email = [email protected] name = Michal Jurosz[alias] st = status ci = commit co = checkout br = branch

> git config global user.email "[email protected]"

> git config global user.name "Michal Jurosz"

> cat ~/.gitconfig[user] email = [email protected] name = Michal Jurosz[alias] st = status

Page 32: Git (FS and DVCS)

ci = commit co = checkout br = branch

Page 33: Git (FS and DVCS)

CONFIG --LOCAL (DIRECTORY)> git config local gitcourseconf.localvar1 mj41

> git config gitcourseconf.localvar1 mj41

> grep gitcourseconf A 2 .git/config[gitcourseconf] localvar1 = mj41

> git config removesection gitcourseconf

> grep gitcourseconf A 2 .git/config

Page 34: Git (FS and DVCS)

CONFIG --SYSTEM (/ETC)> sudo git config system gitcourseconf.systemvar1 systemmj41

> cat /etc/gitconfigcat: /etc/gitconfig: No such file or directory

Page 35: Git (FS and DVCS)

GIT ALIASES> git config global alias.st status

> git config global alias.ci commit

> git config global alias.co checkout

> git config global alias.br branch

Page 36: Git (FS and DVCS)

FIRST COMMIT (FINALLY)> git commit m"commit 01 message"On branch masterUntracked files: fileB.txt

nothing added to commit but untracked files present

> git logcommit 7d6e09068aa3db89e331ab902a86438b4b929941Author: Michal Jurosz <[email protected]>Date: Mon Jun 8 10:59:24 2015 0400

commit 01 message

> git log oneline decorate7d6e090 (HEAD, master) commit 01 message

Page 37: Git (FS and DVCS)
Page 38: Git (FS and DVCS)

.GIT AFTER FIRST COMMIT 1/5> tree aF .git

.git .git > | COMMIT_EDITMSG| HEAD | HEAD| branches/ | branches/| config* | config*| description | description| hooks/ | hooks/| index | index| info/ | info/| exclude | exclude > | logs/ > | | HEAD > | refs/ > | heads/ > | master| objects/ | objects/

Page 39: Git (FS and DVCS)

.GIT AFTER FIRST COMMIT 2/5| objects/ | objects/ > | | 4a/ > | | f19c541178897f > | | 7d/ > | | 6e09068aa3db89| | 8e/ | | 8e/| | 4b68ee140cfbea | | 4b68ee140cfbea| | info/ | | info/| pack/ | pack/ refs/ refs/

| heads/ | heads/ > | master tags/ tags/

Page 40: Git (FS and DVCS)

.GIT AFTER FIRST COMMIT 3/5> cat .git/COMMIT_EDITMSGcommit 01 message

> find .git/objects type f.git/objects/7d/6e09068aa3db89e331ab902a86438b4b929941.git/objects/4a/f19c541178897fb76436c785b2b86d8e9fb9f7.git/objects/8e/4b68ee140cfbeaee5d38671cb03c83d1b6f2a4

Page 41: Git (FS and DVCS)

TREE OBJECT> git catfile t 4af19c541178897fb76436c785b2b86d8e9fb9f7tree

> git catfile p 4af19c541178897fb76436c785b2b86d8e9fb9f7100644 blob 8e4b68ee140cfbeaee5d38671cb03c83d1b6f2a4 fileA.txt

Page 42: Git (FS and DVCS)

COMMIT OBJECT> git catfile t 7d6e09068aa3db89e331ab902a86438b4b929941commit

> git catfile p 7d6e09068aa3db89e331ab902a86438b4b929941tree 4af19c541178897fb76436c785b2b86d8e9fb9f7author Michal Jurosz <[email protected]> 1433775564 0400committer Michal Jurosz <[email protected]> 1433775564 0400

commit 01 message

> git log n1commit 7d6e09068aa3db89e331ab902a86438b4b929941Author: Michal Jurosz <[email protected]>Date: Mon Jun 8 10:59:24 2015 0400

commit 01 message

Page 43: Git (FS and DVCS)

.GITIGNORE 1/2> touch tempf.tmp

> mkdir p tmp ; touch tmp/tf.txt

> git status short?? fileB.txt?? tempf.tmp?? tmp/

Page 44: Git (FS and DVCS)

.GITIGNORE 2/2> echo 'tmp/' > .gitignore

> echo '*.tmp' >> .gitignore

> git status short?? .gitignore?? fileB.txt

> git add .gitignore

Page 45: Git (FS and DVCS)

SECOND COMMIT> cat fileB.txttextB line 1

> git add fileB.txt

> git commit m"commit 02 message"[master ec23b35] commit 02 message 2 files changed, 3 insertions(+) create mode 100644 .gitignore create mode 100644 fileB.txt

> git log decorate graph pretty=format:'%h %d %s <%ae>' all* ec23b35 (HEAD, master) commit 02 message <[email protected]>* 7d6e090 commit 01 message <[email protected]>

> git branch BRc2

Page 46: Git (FS and DVCS)

THIRD COMMIT 1/3> echo "textB line 2" >> fileB.txt

> cat fileB.txttextB line 1textB line 2

> mkdir dirH

> echo "textHC line 1" > dirH/fileHC.txt

Page 47: Git (FS and DVCS)

THIRD COMMIT 2/3> git statusOn branch masterChanges not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout <file>..." to discard changes in working directory)

modified: fileB.txt

Untracked files: (use "git add <file>..." to include in what will be committed)

dirH/

no changes added to commit (use "git add" and/or "git commit a")

Page 48: Git (FS and DVCS)

THIRD COMMIT 3/3> git add fileB.txt

> git add dirH

> git statusOn branch masterChanges to be committed: (use "git reset HEAD <file>..." to unstage)

new file: dirH/fileHC.txt modified: fileB.txt

> git commit m"commit 03 message"[master fcb9538] commit 03 message 2 files changed, 2 insertions(+) create mode 100644 dirH/fileHC.txt

Page 49: Git (FS and DVCS)

FOURTH COMMIT (-A)> echo "textHC line 2" >> dirH/fileHC.txt

> git statusOn branch masterChanges not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout <file>..." to discard changes in working directory)

modified: dirH/fileHC.txt

no changes added to commit (use "git add" and/or "git commit a")

> git commit a m"commit 04 message"[master e4d63af] commit 04 message 1 file changed, 1 insertion(+)

Page 50: Git (FS and DVCS)

CAT TREE (THE REAL ONE) 1/2> git catfile t 2afe2cf674f123661ecbf68b698f1ffd4a1f5f23tree

> git catfile p 2afe2cf674f123661ecbf68b698f1ffd4a1f5f23100644 blob 60d6882bff469b815a3ba2334520ee7987f0bc92 .gitignore040000 tree f584e5928a3315c4dc8dcf09b46d3e4d8d711f83 dirH100644 blob 8e4b68ee140cfbeaee5d38671cb03c83d1b6f2a4 fileA.txt100644 blob 3d67da922cae213e0ba10593c31c763543c97fee fileB.txt

> git catfile t f584e5928a3315c4dc8dcf09b46d3e4d8d711f83tree

> git catfile p f584e5928a3315c4dc8dcf09b46d3e4d8d711f83100644 blob 7dd188dd69574eee96bc02f5783a01eceb30f8c3 fileHC.txt

Page 51: Git (FS and DVCS)

CAT TREE (THE REAL ONE) 2/2> git catfile t 7dd188dd69574eee96bc02f5783a01eceb30f8c3blob

> git catfile p 7dd188dd69574eee96bc02f5783a01eceb30f8c3textHC line 1textHC line 2

Page 52: Git (FS and DVCS)

CRYPTOGRAPHICthe last commit - sha1cryptographic authentication of historycommit

-> working tree -> trees + blobs-> parent commit(s)

-> working tree(s) ......

the first commit (without any parent)

Page 53: Git (FS and DVCS)

CLEAN INDEX> git status short

> git lsfiles s100644 60d6882bff469b815a3ba2334520ee7987f0bc92 0 .gitignore100644 7dd188dd69574eee96bc02f5783a01eceb30f8c3 0 dirH/fileHC.txt100644 8e4b68ee140cfbeaee5d38671cb03c83d1b6f2a4 0 fileA.txt100644 3d67da922cae213e0ba10593c31c763543c97fee 0 fileB.txt

> echo "textHC line 3" >> dirH/fileHC.txt

> git add A ; git status shortM dirH/fileHC.txt

> git lsfiles s100644 60d6882bff469b815a3ba2334520ee7987f0bc92 0 .gitignore100644 69694edab7d1f25fc6565ce60c6818dd615833e1 0 dirH/fileHC.txt100644 8e4b68ee140cfbeaee5d38671cb03c83d1b6f2a4 0 fileA.txt100644 3d67da922cae213e0ba10593c31c763543c97fee 0 fileB.txt

Page 54: Git (FS and DVCS)

SYMBOLIC-REF (HEAD), REFS> git log oneline decorate n2e4d63af (HEAD, master) commit 04 messagefcb9538 commit 03 message

> cat .git/HEADref: refs/heads/master

> git symbolicref HEADrefs/heads/master

> cat .git/refs/heads/mastere4d63afacf3d1d5782aacc97158092b5e4a1b096

> git revparse short refs/heads/mastere4d63af

Page 55: Git (FS and DVCS)

PIT STOP 2working dir, index, object database (repository)blob, tree, commit, tagmaster, HEAD

Questions?

Page 56: Git (FS and DVCS)

GARBAGEGarbage accumulates unless collectedPeriodic explicit object packing

Page 57: Git (FS and DVCS)

OBJECTS (AFTER COMMITS)> find .git/objects type f | wc l17

> du hs .git/objects140K .git/objects

> find .git/objects type f | head n 10.git/objects/fc/b953879a566ea607d58948a0f520b1f75ad277.git/objects/44/dba16a657baed8a09f68312c985dff84e3134c.git/objects/ec/23b35681d22f0c6d6f14572cab119bbebbac85.git/objects/f5/84e5928a3315c4dc8dcf09b46d3e4d8d711f83.git/objects/7d/d188dd69574eee96bc02f5783a01eceb30f8c3.git/objects/7d/6e09068aa3db89e331ab902a86438b4b929941.git/objects/e4/d63afacf3d1d5782aacc97158092b5e4a1b096.git/objects/69/694edab7d1f25fc6565ce60c6818dd615833e1.git/objects/8c/87fa6ad6c88318d1a528e99b810a6a49c65ffe.git/objects/4a/f19c541178897fb76436c785b2b86d8e9fb9f7

Page 58: Git (FS and DVCS)

GIT GC 1/2> git gc aggressive prune

> tree aF .git/objects.git/objects| 69/| 694edab7d1f25fc6565ce60c6818dd615833e1| info/| packs pack/

| packdf426cfa7c95a7dbaeca9659a3f9e11f4453a6f7.idx packdf426cfa7c95a7dbaeca9659a3f9e11f4453a6f7.pack

3 directories, 4 files

> du hs .git/objects32K .git/objects

Page 59: Git (FS and DVCS)

GIT GC 2/2> git catfile p 7dd188dd69574eee96bc02f5783a01eceb30f8c3textHC line 1textHC line 2

> tree aF .git/refs.git/refs| heads/ tags/

2 directories, 0 files

> cat .git/packedrefs# packrefs with: peeled fullypeeled ec23b35681d22f0c6d6f14572cab119bbebbac85 refs/heads/BRc2e4d63afacf3d1d5782aacc97158092b5e4a1b096 refs/heads/master

Page 60: Git (FS and DVCS)

ADD AFTER GIT GC> echo "textA line 2" >> fileA.txt ; git add A

> tree noreport aF .git | grep A 100 'objects/'| objects/| | 69/| | 694edab7d1f25fc6565ce60c6818dd615833e1| | e3/| | 1d478f6c73239c2452b571b9b07c33d568d330| | info/| | packs| pack/| | packdf426cfa7c95a7dbaeca9659a3f9e11f4453a6f7.idx| packdf426cfa7c95a7dbaeca9659a3f9e11f4453a6f7.pack| packedrefs refs/

| heads/ tags/

Page 61: Git (FS and DVCS)

GIT DIFF (PREPARE)> git reset hard HEADHEAD is now at e4d63af commit 04 message

> echo "textA line 2" >> fileA.txt

> git add A

> echo "textA line 3" >> fileA.txt

Page 62: Git (FS and DVCS)

GIT DIFF (INTRO)

Page 63: Git (FS and DVCS)

GIT DIFF> git diffdiff git a/fileA.txt b/fileA.txtindex e31d478..abd231e 100644 a/fileA.txt+++ b/fileA.txt@@ 1,2 +1,3 @@ textA line 1 textA line 2+textA line 3

Page 64: Git (FS and DVCS)

GIT DIFF --CACHED> git diff cacheddiff git a/fileA.txt b/fileA.txtindex 8e4b68e..e31d478 100644 a/fileA.txt+++ b/fileA.txt@@ 1 +1,2 @@ textA line 1+textA line 2

Page 65: Git (FS and DVCS)

GIT DIFF HEAD> git diff HEADdiff git a/fileA.txt b/fileA.txtindex 8e4b68e..abd231e 100644 a/fileA.txt+++ b/fileA.txt@@ 1 +1,3 @@ textA line 1+textA line 2+textA line 3

Page 66: Git (FS and DVCS)

GIT DIFF <REF1> <REF2>> git diff HEAD~3 HEAD~2diff git a/.gitignore b/.gitignorenew file mode 100644index 0000000..60d6882 /dev/null+++ b/.gitignore@@ 0,0 +1,2 @@+tmp/+*.tmpdiff git a/fileB.txt b/fileB.txtnew file mode 100644index 0000000..44dba16 /dev/null+++ b/fileB.txt@@ 0,0 +1 @@+textB line 1

Page 67: Git (FS and DVCS)

REVISIONS - <REV> 1/3<sha1> - e.g. 8e4b68e<refname> - e.g. HEAD, master, origin/master

.git/<refname>

.git/refs<refname>

.git/tags/<refname>

.git/heads/<refname>

.git/remotes/<refname>

......

Page 68: Git (FS and DVCS)

REVISIONS - <REV> 2/3<rev>~<n> - e.g. master~3

> git log n3 oneline decoratee4d63af (HEAD, master) commit 04 messagefcb9538 commit 03 messageec23b35 (BRc2) commit 02 message

> git revparse short HEAD ; git revparse short HEADe4d63afe4d63af

> git revparse short HEAD~2ec23b35

> git catfile t ec23b35commit

Page 69: Git (FS and DVCS)

REVISIONS - <REV> 3/3<rev>:<path>, e.g. HEAD:dirH/fileHC.txt

> git revparse short HEAD~1:dirH/fileHC.txt5df063b

> git catfile t 5df063bblob

Page 70: Git (FS and DVCS)

REVISIONS RANGES 1/3<rev> - reachable from <rev>

> git log onelinee4d63af commit 04 messagefcb9538 commit 03 messageec23b35 commit 02 message7d6e090 commit 01 message

> git log HEAD~2 onelineec23b35 commit 02 message7d6e090 commit 01 message

> git log 'master/commit 03' onelinefcb9538 commit 03 messageec23b35 commit 02 message7d6e090 commit 01 message

Page 71: Git (FS and DVCS)

REVISIONS RANGES 2/3<rev1>..<rev2>

include commits reachable from <rev2>exclude commits reachable from <rev1>

<rev1>...<rev2>include commits reachable from either <rev1>or <rev2>exclude reachable from both

Page 72: Git (FS and DVCS)

REVISIONS RANGES 3/3> git log 'master/01'..'master/03' onelinefcb9538 commit 03 messageec23b35 commit 02 message

> git log 'master/03'...'master/01' onelinefcb9538 commit 03 messageec23b35 commit 02 message

Page 73: Git (FS and DVCS)

GIT GREPlook for specified patterns in the tracked files

in the work treeblobs in given tree objects

> git grep n 'line 3'fileA.txt:3:textA line 3

> git grep n e 'line 2' HEAD~1 HEAD~2HEAD~1:fileB.txt:2:textB line 2

Page 74: Git (FS and DVCS)

GIT GREP --CACHEDlook for specified patterns in the tracked files

blobs registered in the index file

> git grep n cached 'line 3'

> git grep n cached 'line 2'dirH/fileHC.txt:2:textHC line 2fileA.txt:2:textA line 2fileB.txt:2:textB line 2

Page 75: Git (FS and DVCS)

GIT LOG -- <PATHS>commits modifying the given are selectedgitk -- <string>

> git log oneline dirHe4d63af commit 04 messagefcb9538 commit 03 message

Page 76: Git (FS and DVCS)

GIT LOG -S <STRING> 1/2... introduce or remove an instance of <string>gitk -S <string>

Page 77: Git (FS and DVCS)

GIT LOG -S <STRING> 2/2> git log S 'line 2' onelinee4d63af commit 04 messagefcb9538 commit 03 message

> git show e4d63afcommit e4d63afacf3d1d5782aacc97158092b5e4a1b096Author: Michal Jurosz <[email protected]>Date: Mon Jun 8 10:59:25 2015 0400

commit 04 message

diff git a/dirH/fileHC.txt b/dirH/fileHC.txtindex 5df063b..7dd188d 100644 a/dirH/fileHC.txt+++ b/dirH/fileHC.txt@@ 1 +1,2 @@ textHC line 1+textHC line 2

Page 78: Git (FS and DVCS)

GIT BLAMElast change of each linegit gui blame

> git blame dirH/fileHC.txtfcb95387 (Michal Jurosz 20150608 10:59:24 0400 1) textHC line 1e4d63afa (Michal Jurosz 20150608 10:59:25 0400 2) textHC line 2

Page 79: Git (FS and DVCS)

RESET AND CHECKOUTthe three trees

working directoryindexHEAD

Page 80: Git (FS and DVCS)

GIT RESET --HARD <REV>move HEAD (and the branch)reset indexreset working tree

Page 81: Git (FS and DVCS)

GIT RESET [--MIXED] <REV>move HEAD (and the branch)reset indexreset working tree

Page 82: Git (FS and DVCS)

GIT RESET --SOFT <REV>move HEAD (and the branch)reset indexreset working tree

Page 83: Git (FS and DVCS)

GIT CHECKOUT/RESET -- FILES

Page 84: Git (FS and DVCS)

PIT STOP 3git diff<rev> - sha1, HEAD, master, moje-branchAgitk, git gui blame

git grep, git log -S 'use utf8', git blamegit reset --hard

Questions?

Page 85: Git (FS and DVCS)

BRANCHES> git branch v BRc2 ec23b35 commit 02 message* master e4d63af commit 04 message

> git branch mjtest

> git branch v BRc2 ec23b35 commit 02 message* master e4d63af commit 04 message mjtest e4d63af commit 04 message

> git showref head abbreve4d63af HEADec23b35 refs/heads/BRc2e4d63af refs/heads/mastere4d63af refs/heads/mjtest

Page 86: Git (FS and DVCS)

GIT CHECKOUT <BRANCH>move only HEAD (switch branch)reset index

reset not modified filesmerge modified

reset working treereset not modified filesmerge modified

Page 87: Git (FS and DVCS)

GIT CHECKOUT BRC2 1/2> git branch v BRc2 ec23b35 commit 02 message* master e4d63af commit 04 message mjtest e4d63af commit 04 message

> git reset hard masterHEAD is now at e4d63af commit 04 message

> cat fileA.txttextA line 1

> echo "textA line 2" >> fileA.txt

> git add A

> echo "textA line 3" >> fileA.txt

Page 88: Git (FS and DVCS)

GIT CHECKOUT BRC2 2/2> git checkout BRc2Switched to branch 'BRc2'M fileA.txt

> git status shortMM fileA.txt

> git diff cached | grep '+textA'+textA line 2

> git diff | grep '+textA'+textA line 3

Page 89: Git (FS and DVCS)

NEW BRANCH> git branch BRc2pokus

> git branch v | grep '*'* BRc2 ec23b35 commit 02 message

> git checkout BRc2pokusSwitched to branch 'BRc2pokus'M fileA.txt

> git branch v | grep '*'* BRc2pokus ec23b35 commit 02 message

> cat .git/HEADref: refs/heads/BRc2pokus

Page 90: Git (FS and DVCS)

CHECKOUT -B (NEW BRANCH)> git checkout b BRc2modSwitched to a new branch 'BRc2mod'M fileA.txt

> git branch d BRc2pokusDeleted branch BRc2pokus (was ec23b35).

> git branch v BRc2 ec23b35 commit 02 message* BRc2mod ec23b35 commit 02 message master e4d63af commit 04 message mjtest e4d63af commit 04 message

Page 91: Git (FS and DVCS)

NEW BRANCH COMMITS 1/2> git ci m"branch c2mod commit A"[BRc2mod 4956cc7] branch c2mod commit A 1 file changed, 1 insertion(+)

> git ci a m"branch c2mod commit B"[BRc2mod b3c71e7] branch c2mod commit B 1 file changed, 1 insertion(+)

> echo "textX line 1" >> fileX.txt

> git add fileX.txt

> git ci a m"branch c2mod commit C add fileX"[BRc2mod 791c5fe] branch c2mod commit C add fileX 1 file changed, 1 insertion(+) create mode 100644 fileX.txt

Page 92: Git (FS and DVCS)

NEW BRANCH COMMITS 2/2> git log all graph dateorder decorate oneline* 791c5fe (HEAD, BRc2mod) branch c2mod commit C add fileX* b3c71e7 branch c2mod commit B* 4956cc7 branch c2mod commit A| * e4d63af (mjtest, master) commit 04 message| * fcb9538 commit 03 message|/ * ec23b35 (BRc2) commit 02 message* 7d6e090 commit 01 message

> git branch D mjtestDeleted branch mjtest (was e4d63af).

Page 93: Git (FS and DVCS)

MERGE> git checkout masterSwitched to branch 'master'

> git merge BRc2modMerge made by the 'recursive' strategy. fileA.txt | 2 ++ fileX.txt | 1 + 2 files changed, 3 insertions(+) create mode 100644 fileX.txt

> git log all graph dateorder decorate oneline* b89ef4a (HEAD, master) Merge branch 'BRc2mod'|\ | * 791c5fe (BRc2mod) branch c2mod commit C add fileX| * b3c71e7 branch c2mod commit B| * 4956cc7 branch c2mod commit A* | e4d63af commit 04 message* | fcb9538 commit 03 message|/ * ec23b35 (BRc2) commit 02 message

Page 94: Git (FS and DVCS)

* 7d6e090 commit 01 message

Page 95: Git (FS and DVCS)

Upstream Origin

Local repository

Index (cache)

Working directory

Page 96: Git (FS and DVCS)

GITHUBa web-based hosting service

3.7M people, 7.1M repositories investment - July 2012, $100 million USD

a pastebin-style site called Gistprivate

US$7/month for five repositoriesup to US$200/month for 125 repositories

Bitbucket, Gitorious, SourceForge, CodePlex,Google Code, Launchpad

June 2013A16Z

Page 97: Git (FS and DVCS)

GIT INIT --BARE> cd ~/gittt

> git init gittutorigin bareInitialized empty Git repository in /home/linus/gittt1433775564435/gittutorigin/

> ls gittutoriginHEADbranchesconfigdescriptionhooksinfoobjectsrefs

Page 98: Git (FS and DVCS)

GIT REMOTE - ORIGIN> cd ~/gittt/repoMJ

> git remote add origin file:///home/linus/gittt1433775564435/gittutorigin

> git push origin HEADTo file:///home/linus/gittt1433775564435/gittutorigin * [new branch] HEAD > master

> git log decorate onelineb89ef4a (HEAD, origin/master, master) Merge branch 'BRc2mod'791c5fe (BRc2mod) branch c2mod commit C add fileXb3c71e7 branch c2mod commit B4956cc7 branch c2mod commit Ae4d63af commit 04 messageec23b35 (BRc2) commit 02 messagefcb9538 commit 03 message7d6e090 commit 01 message

Page 99: Git (FS and DVCS)

GIT FETCH> cd ~/gittt/repoMJ

> git remote vorigin file:///home/linus/gittt1433775564435/gittutorigin (fetch)origin file:///home/linus/gittt1433775564435/gittutorigin (push)

gitfetch Download objects and refs from another repository

> git fetch

Page 100: Git (FS and DVCS)

[PEPA] GIT CLONE 1/2> cd ~/gittt

> git clone file:///home/linus/gittt1433775564435/gittutorigin repoPepyCloning into 'repoPepy'...

> cd repoPepy

> git remote vorigin file:///home/linus/gittt1433775564435/gittutorigin (fetch)origin file:///home/linus/gittt1433775564435/gittutorigin (push)

> lsdirHfileA.txtfileB.txtfileX.txt

Page 101: Git (FS and DVCS)

[PEPA] GIT CLONE 2/2> lsdirHfileA.txtfileB.txtfileX.txt

> git branch a* master remotes/origin/HEAD > origin/master remotes/origin/master

Page 102: Git (FS and DVCS)

[PEPA] GIT LOG> git log decorate oneline graph all* b89ef4a (HEAD, origin/master, origin/HEAD, master) Merge branch 'BRc2mod'|\ | * 791c5fe branch c2mod commit C add fileX| * b3c71e7 branch c2mod commit B| * 4956cc7 branch c2mod commit A* | e4d63af commit 04 message* | fcb9538 commit 03 message|/ * ec23b35 commit 02 message* 7d6e090 commit 01 message

Page 103: Git (FS and DVCS)

GIT REMOTE - UPSTREAM> cd ../repoMJ

> git remote add upstream [email protected]:mj41/gitfsdvcsup.git

> git fetch upstream

Page 104: Git (FS and DVCS)

GIT REMOTE - CONFIGURATION> git remote vorigin file:///home/linus/gittt1433775564435/gittutorigin (fetch)origin file:///home/linus/gittt1433775564435/gittutorigin (push)upstream [email protected]:mj41/gitfsdvcsup.git (fetch)upstream [email protected]:mj41/gitfsdvcsup.git (push)

> git config local list | grep remoteremote.origin.url=file:///home/linus/gittt1433775564435/gittutoriginremote.origin.fetch=+refs/heads/*:refs/remotes/origin/*[email protected]:mj41/gitfsdvcsup.gitremote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*

Page 105: Git (FS and DVCS)

GIT PUSH> git checkout b BRnpSwitched to a new branch 'BRnp'

> echo "textA line 4 BRnp" >> fileA.txt

> git commit a m"branch np commit k"[BRnp 957ee02] branch np commit k 1 file changed, 1 insertion(+)

> git push origin HEADTo file:///home/linus/gittt1433775564435/gittutorigin * [new branch] HEAD > BRnp

Page 106: Git (FS and DVCS)

GIT PUSH --FORCEplease no to masteryour topic branche

use fixupsdo it once before merging

Page 107: Git (FS and DVCS)

[PEPA] GIT FETCH> cd ../repoPepy

> git fetchFrom file:///home/linus/gittt1433775564435/gittutorigin * [new branch] BRnp > origin/BRnp

> git log decorate oneline graph* b89ef4a (HEAD, origin/master, origin/HEAD, master) Merge branch 'BRc2mod'|\ | * 791c5fe branch c2mod commit C add fileX| * b3c71e7 branch c2mod commit B| * 4956cc7 branch c2mod commit A* | e4d63af commit 04 message* | fcb9538 commit 03 message|/ * ec23b35 commit 02 message* 7d6e090 commit 01 message

Page 108: Git (FS and DVCS)

GIT RESET --HARD ORIGIN/... 1/2> cd ../repoMJ

> git checkout masterSwitched to branch 'master'

> git log decorate oneline all graph | head n5* 957ee02 (origin/BRnp, BRnp) branch np commit k* b89ef4a (HEAD, origin/master, master) Merge branch 'BRc2mod'|\ | * 791c5fe (BRc2mod) branch c2mod commit C add fileX| * b3c71e7 branch c2mod commit B

Page 109: Git (FS and DVCS)

GIT RESET --HARD ORIGIN/... 2/2> git reset hard origin/BRnpHEAD is now at 957ee02 branch np commit k

> git log decorate oneline all graph | head n5* 957ee02 (HEAD, origin/BRnp, master, BRnp) branch np commit k* b89ef4a (origin/master) Merge branch 'BRc2mod'|\ | * 791c5fe (BRc2mod) branch c2mod commit C add fileX| * b3c71e7 branch c2mod commit B

> git push origin HEADTo file:///home/linus/gittt1433775564435/gittutorigin b89ef4a..957ee02 HEAD > master

Page 110: Git (FS and DVCS)

PIT STOP 4git checkoutremote repositoriesgit pushgit fetch

Questions?

Page 111: Git (FS and DVCS)

GUIgitk --all --date-ordergit gui

git gui blameWindows: TortoiseGitMAC: GitX, GitNub

Page 112: Git (FS and DVCS)

GIT MORE 1/2git cleangit commit --amendgit ci --fixupgit rebase -igit cherry-pickgit revertgit tag

Page 113: Git (FS and DVCS)

GIT MORE 2/2git bisecgit refloggit filter-branchgit gcgit fsck...

Page 114: Git (FS and DVCS)

LINKS

Pro Git, Scott Chaconlicense

- Czech translation

git-scm.com

CC BY 3.0knihy.nic.cz

git-cheatsheet

Page 115: Git (FS and DVCS)

THANK YOUMichal Jurosz (mj41)

www.GoodData.com

Generated from sourceby inside .

Powered by .

github.com/mj41/git-course-mj41Presentation::Builder prbuilder Docker container

reveal.js

Page 116: Git (FS and DVCS)

QUESTIONS?