SlideShare a Scribd company logo
Welcome!
Jingwei "John" Liu
刘敬威
@th507
http://ljw.me
Quick Poll
How many of you have use Git?

SVN?

git rebase?
Let’s look at git from another perspective.
• distributed version control

• working/staging area

• how it works
VCS: Version Control System
Version Control System
• storing content

• tracking changes to the content

• distributing the content

• keep accurate yet human-readable history
VCS: Types and choices
• No remote repository

• Central repository

• Distributed (with remote) repository
Brutal Force VCS
• Been there, done that.

• Really not very informative

• Which version to use?
essay.doc
essay_2.doc
essay3.doc
essay_final.doc
essay_final2.doc
eassay_final3.doc
esassy_finalfinal.doc
esassy_finalfinal2.doc
Centralized vs. Distributed
VCS Design
Centralized model
all changes to the repository must transact via one
specific repository for it to be recorded in history at all.

Distributed model
where there will often be publicly accessible repositories
for collaborators to "push" to, but commits can be made
locally and pushed to these public nodes later, allowing
offline work.
Centralized model
Repository
Working CopyWorking Copy
checkout
update
log
diff
commit
Distributed Model
Remote Repository
pull push
commit commit
checkoutcheckout
Working Copy Working Copy
log
diff
Local Repositories
Centralized vs. Distributed
• Delta-based changeset (linear history)

• Directed Acyclic Graphs (DAG) representation
Distributed VCS
• distributed workflows

• safeguard against data corruption

• (reasonably) high performance

• collaborators could work offline

• collaborators could determine when their work are
ready to share
Plumbing and Porcelain
Git Commands: Plumbing and Porcelain
plumbing

plumbing consists of low-level commands that enable
basic content tracking and the manipulation of directed
acyclic graphs (DAG)

porcelain

smaller subset of git commands that most Git end users
are likely to need to use for maintaining repositories and
communicating between repositories for collaboration
Low Level Commands (Plumbing)
cat-file, commit-tree, count-objects, diff-index, for-
each-ref, hash-object, merge-base, read-tree, rev-
list, rev-parse, show-ref, symbolic-ref, update-index,
update-ref, verify-pack, write-tree
High Level Commands (Porcelain)
commit/push/pull/merge/…
• meant to be readable by human

• not meant to be parsed

• susceptible to changes/evolutions
Describing Changeset with Hash Value
Pros
• Same content never duplicate

Cons
• Managing multiple files?

• Managing history?

• Hard to understand hash values
Vernaculars and Plumbing Commands
Git Vernaculars
blob
	 stores file content.

tree
	 stores directory layouts and filenames.

commit
	 stores commit info and forms the Git commit graph.

tag
	 stores annotated tag
Git: A Quick Glance
• Content address-able database

• Key is SHA-1 hash of object’s content

• Value is the content

• Same content never duplicate
Setup
$ git init demo; cd demo

Initialized empty Git repository in demo/.git/
# monitoring .git folder

# if you are using bash, then…

$ while :; do tree .git; sleep 2; done
object in Git
Same content never duplicate
Parsing Object
$ echo "test content" | git hash-object -w --stdin

d670460b4b4aece5915caf5c68d12f560a9fe3e4
$ find .git/objects/ -type f

.git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4
$ git cat-file -p d670

test content
$ git cat-file -t d670

blob
hash-object in Git
content 	 = 	"test content"

header = 	"blob %d0", length_of(content)

store 	 	 = 	header + content

sha1 = 	sha1_of(store)

dir 	 	 	 = 	".git/objects/" + sha1[0:2] + "/"

filename 	 = 	sha1[2:]

write(dir + filename, store)

# Save compressed header + content
hash-object in Git
$ echo "Simon" > test.txt
$ git hash-object -w test.txt

83fba84900292b2feb7e955c72eda04a1faa1273
$ echo "Garfunkel" > test.txt
$ git hash-object -w test.txt

6cc4930db0f5ccd17f0bc7bfe0ae850b1b0c06a2
$ git cat-file -p 83fb

Simon
cat test.txt

Garfunkel
tree Object
• point to other objects (hashed)
with name

• a root tree Object is a snapshot
tree Object
$ mkdir favorites; echo "fantastic" > favorites/band
$ git update-index --add test.txt favorites/band
$ git write-tree

d0ef546493e53c3beb98e5da4f437e581ff3c7e0
$ git cat-file -p d0ef

040000 tree 94b88a81db61ed617621138bc172aa6f3a408545
favorites

100644 blob 6cc4930db0f5ccd17f0bc7bfe0ae850b1b0c06a2
test.txt
$ git cat-file -p 94b8

100644 blob 744c44c7d1ffb9be8db8cd9f1e2c47830ca6f10b band
Data Structure
T1
F1
F2
6cc4
test.txt
94b8
favorites
1db7
band
T2
3266
tree
tree Object
$ echo "Byrds" > test.txt
$ git update-index --add test.txt
$ git write-tree

3266237ac900a5f09c266b7d6bc79bde6a2386df
$ git cat-file -p 3266

040000 tree 94b88a81db61ed617621138bc172aa6f3a408545
favorites

100644 blob 1db792a2c726b393332a882fe105bc3ade4ddb66
test.txt
$ git cat-file -p 1db7

Byrds
T1
F1
F2
6cc4
test.txt
94b8
favorites
6cc4
band
T2
T3
F3
Data Structure
1db7
test.txt
d0ef
tree
3266
tree
commit Object
• explain a change: who/when/why

• point to a tree object with above info

• pointer, not delta
commit Object
$ echo "test commit" | git commit-tree d0ef

1fa215b14c27f2739515eb8410f06478eb0c423e
$ git cat-file -p 1fa2

tree d0ef546493e53c3beb98e5da4f437e581ff3c7e0

author Jingwei "John" Liu <liujingwei@gmail.com>
1407123580 +0800

committer Jingwei "John" Liu <liujingwei@gmail.com>
1407123580 +0800



test commit
T1
F1
F2
6cc4
test.txt
94b8
favorites
6cc4
band
T2
Data Structure
Commit 1
d0ef
tree
1fa2
commit
commit Object
$ echo "another test commit" | git commit-tree 3266 -p
1fa2

ded15c0a38dcf226cfbc4838a9d78cd3f8d82baf
$ git cat-file -p ded1

tree 3266237ac900a5f09c266b7d6bc79bde6a2386df

parent 1fa215b14c27f2739515eb8410f06478eb0c423e

author Jingwei "John" Liu <liujingwei@gmail.com>
1407123885 +0800

committer Jingwei "John" Liu <liujingwei@gmail.com>
1407123885 +0800



another test commit
commit Object Anatomy
$ echo "another test commit" | git commit-tree 3266 -p
1fa2

ded15c0a38dcf226cfbc4838a9d78cd3f8d82baf
$ git cat-file -p ded1

tree [SHA-1]

parent [SHA-1]

author [name] [email] [timestamp] [timezone]

committer [name] [email] [timestamp] [timezone]



[commit message]
T1
F1
F2
6cc4
test.txt
94b8
favorites
6cc4
band
T2
T3
F3
Data Structure
1db7
test.txt
Commit 1 Commit 2
parent
d0ef
tree
3266
tree
1fa2
commit
ded1
commit
commit Object
• contains metadata about its ancestors

• can have zero or many (theoretically unlimited) parent commits

• initial commit has no parent

• three-way merge commit has three parents
reference in Git
• stored in .git/refs

• SHA-1
reference in Git
# create a branch

$ echo "1fa215b14c27f2739515eb8410f06478eb0c423e"
> .git/refs/heads/test-branch
$ git branch

* master

test-branch
$ git log --pretty=oneline test-branch

1fa215b14c27f2739515eb8410f06478eb0c423e test commit
$ find .git/refs/heads -type f

.git/refs/heads/master

.git/refs/heads/test-branch
reference in Git
$ git update-refs refs/heads/master
ded15c0a38dcf226cfbc4838a9d78cd3f8d82baf
$git log --pretty=oneline master

ded15c0a38dcf226cfbc4838a9d78cd3f8d82baf another test
commit

1fa215b14c27f2739515eb8410f06478eb0c423e test commit
$ cat .git/refs/heads/master

ded15c0a38dcf226cfbc4838a9d78cd3f8d82baf

reference in Git
$ cat .git/HEAD

ref: refs/heads/master
$ git branch

test-branch

* master
$ git symbolic-ref HEAD refs/heads/test-branch
$ cat .git/HEAD

ref: refs/heads/test-branch
T1
F1
F2
6cc4
test.txt
94b8
favorites
6cc4
band
T2
T3
F3
Data Structure
1db7
test.txt
Commit 1 Commit 2
parent
refs/heads/test-branch refs/heads/master
d0ef
tree
3266
tree
1fa2
commit
ded1
commit
HEAD/head in Git
• HEAD is symbolic references. It points to another
reference

• use ref, not SHA-1

$ cat .git/HEAD

ref: refs/heads/master
$ git branch

* master
T1
F1
F2
83fb
test.txt
94b8
favorites
6cc4
test.txt
T2
T3
F3
Data Structure
1db7
test.txt
Commit 1 Commit 2
parent
refs/heads/test-branch refs/heads/master .git/HEAD
d0ef
tree
3266
tree
ded1
commit
1fa2
commit
Other references in Git
tag

once created, it will never change

unless explicitly updated with --force

useful for marking specific versions

Let’s talk porcelain.
Git Porcelain Commands
commit/push/pull/merge/…
• build upon plumbing commands
diff
$ git diff HEAD
# equivalent of…
$ git ls-files -m
cherry
$ git cherry master origin/master
# equivalent of…
$ git rev-parse master..origin/master
status
$ git status
# equivalent of…
$ git ls-files --exclude-per-directory=.gitignore
—exclude-from=.git/info/exclude —others --modified
-t
commit
$ git update-index --add
F1
$ git update-index --add
$ echo "commit-msg" | 

git commit-tree
[SHA-1]
commit
T1
F1
Commit 1
$ git update-index --add
$ echo "commit-msg" | 

git commit-tree
[SHA-1]
$ git write-tree
commit
T1
F1
Commit 1
$ git update-index --add
$ echo "commit-msg" | 

git commit-tree
[SHA-1]
$ git write-tree
$ git update-refs refs/
heads/master
T1
F1
Commit 1
refs/heads/master
commit
Commits in DAG
Commit 1 CommitCommit
Blob/File info
Tree info
Create a New File (File 3)
Commit 1
Create a New File (File 3)
Commit 1
Create a New File (File 3)
Commit 1
Commit a New File (File 3)
Commit 1 Commit 2
Edit and Commit File1
Commit 1 Commit 2
Edit and Commit File1
Commit 1 Commit 2
Edit and Commit File1
Commit 1 Commit 2
Edit and Commit File1
Commit 1 Commit 2 Commit 3
merge
merge is a commit with N parents,
retaining merge history
$ git merge
$ git merge —-squash
Basic Merge
$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: index.html
no changes added to commit (use "git add" and/or "git commit -a")
Basic Merge Conflicts
<<<<<<< HEAD
<div id="footer">contact : email.support@github.com</div>
=======
<div id="footer">
please contact us at support@github.com
</div>
>>>>>>> some-remote-branch
<<<<<<< HEAD
(local) HEAD content is here
=======
some-remote-branch content is here
>>>>>>> some-remote-branch
Basic Merge Conflicts
$ git mergetool

This message is displayed because 'merge.tool' is not configured.
See 'git mergetool --tool-help' or 'git help config' for more
details.
'git mergetool' will now attempt to use one of the following tools:
opendiff kdiff3 tkdiff xxdiff meld tortoisemerge gvimdiff diffuse
diffmerge ecmerge p4merge araxis bc3 codecompare vimdiff emerge
Merging:
index.html
Normal merge conflict for 'index.html':
{local}: modified file
{remote}: modified file
Hit return to start merge resolution tool (opendiff):
Basic Merge Conflicts
$ git merge —-abort
Aborting Merge
$ git merge —s ours
$ git merge —s theirs
Merge with Strategy
pull
• fetch + merge

• conflict is possible

$ git pull origin/master
# equivalent of …
$ git fetch origin/master

$ git merge origin/master
pull
• fetch + merge

• conflict is possible

$ git pull
fetch
$ cat .git/config | grep remote

[remote "origin"]

url = git://127.0.0.1/git/demo.git

fetch = +refs/heads/*:refs/remotes/origin/*

———————————— ———————————————————

source destination
rebase
replay commits one by one

on top of a branch
• fun

• dangerous

• use with caution, esp. working with others

• only use in local repositories/branches
Changing History is…
rebase
# equivalent to git pull —rebase

$ git fetch origin/master; git rebase origin/master
A---B---C topic
/
D---E---F---G master
to:
A'--B'--C' topic
/
D---E---F---G master
rebase
$ git rebase -i
$ git rebase --onto
• replays commits

• moves commits

• changes commit history

• changes commit parent/ancestor
rebase
Branches in Git
• just like parallel universes

• nothing more than references to
commit
# list local branches
$ git branch
# list local and remote branches
$ git branch -a
# show branches with reference
$ git branch -v
# show branch tracking info
$ git branch -vv
List all Branches
$ git remote -vv
$ git remote set-url http://example.com/foo.git
$ git remote add staging git://git.kernel.org/.../gregkh/staging.git
# or just edit .git/info
Setting Tracking Info
Caret and Tilde
• caret(~n): depth-first n-th parent
commit

• tilde(^n): breadth-first n-th
parent commit

• See

$ git help rev-parse
Revision Selection
G H I J
 /  /
D E F
 | / 
 | / |
|/ |
B C
 /
 /
A
A = = A^0
B = A^ = A^1 = A~1
C = A^2 = A^2
D = A^^ = A^1^1 = A~2
E = B^2 = A^^2
F = B^3 = A^^3
G = A^^^ = A^1^1^1 = A~3
H = D^2 = B^^2 = A^^^2 = A~2^2
I = F^ = B^3^ = A^^3^
J = F^2 = B^3^2 = A^^3^2
push.default
nothing
do not push anything (error out) unless a refspec is explicitly given. This is primarily meant for people
who want to avoid mistakes by always being explicit.

current
push the current branch to update a branch with the same name on the receiving end. Works in both
central and non-central workflows.

upstream
push the current branch back to the branch whose changes are usually integrated into the current
branch (which is called @{upstream}). This mode only makes sense if you are pushing to the same
repository you would normally pull from (i.e. central workflow).

simple
in centralized workflow, work like upstream with an added safety to refuse to push if the upstream
branch's name is different from the local one. When pushing to a remote that is different from the
remote you normally pull from, work as current.

This is the safest option and is suited for beginners.
Cheat Sheet
stash working
area
staging
area
local
repository
upstream
repository
stash working
area
staging
area
local
repository
upstream
repository
stash working
area
staging
area
local
repository
upstream
repository
stash save
stash apply
stash pop
stash list
stash show
stash drop
stash clear
stash branch
stash working
area
staging
area
local
repository
upstream
repository
stash working
area
staging
area
local
repository
upstream
repository
status
diff
diff [commit or branch]
add
rm
mv
commit -a
reset —hard
checkout
merge
rebase
cherry-pick
revert
clone
pull
clean
stash pop
stash save
stash working
area
staging
area
local
repository
upstream
repository
stash working
area
staging
area
local
repository
upstream
repository
reset HEAD
reset —soft
diff —cached
commit
stash working
area
staging
area
local
repository
upstream
repository
stash working
area
staging
area
local
repository
upstream
repository
log
branch
fetch
push
push —delete
stash working
area
staging
area
local
repository
upstream
repository
stash working
area
staging
area
local
repository
upstream
repository
branch -r
Find Stuff in Git
Find Stuff by…
# find file by content

$ git grep
# find file by its name

$ git ls-file | grep
# find changes by line number

$ git blame -L
Find Stuff in log
# find changes by commit message

$ git log | grep
# find changes with specific string

$ git log -S
# find changes by file name

$ git log -p
# find changes by author/committer

$ git log --author

$ git log --committer
#find changes within given time span

$ git --since

$ git --until
More about log
# ignore merges

$ git log --no-merges
# customize how log looks

$ git log --graph
$ git log --online
$ git log --pretty="…"
$ git log --stat
Undo & Cleanup in Git
Change Last Commit
$ git commit —-amend
$ git commit —-amend --no-edit
$ git commit ; git rebase -i HEAD~2
Unstage Staged Files
$ git reset HEAD [filename]
$ git reset .
Undo Working Modifications
$ git checkout -- [filename]
$ git checkout .
$ git stash
$ git stash drop
Cleanup Untracked Files
$ git clean -df
$ git add .
$ git stash
$ git stash drop
Delete Remote Branch
# check for proper remote branch name

$ git branch -a
$ git push origin —-delete [branch_name]
$ git push origin :[branch_name]
# ————————— Explanation ————————— #

$ cat .git/config | grep remote

[remote "origin"]

url = git://127.0.0.1/git/demo.git

fetch = +refs/heads/*:refs/remotes/origin/*

———————————— ———————————————————

source destination
# pushing empty source/reference to destination
Be the Last Committer in a Branch
# use with caution

$ git commit --allow-empty
Basic Recoveries in Git
Recover Deleted Branch
$ git branch -d test-branch

Deleted branch test-branch (was 1fa215b).
$ git checkout 1fa215b

HEAD is now at 1fa215b... test commit
$ git co -b test-branch
• Do it before garbage collection
Reset Indices
$ git reset --soft

Does not touch the index file or the working tree at all (but resets the head
to <commit>, just like all modes do). This leaves all your changed files
"Changes to be committed", as git status would put it.
$ git reset --mixed

Resets the index but not the working tree (i.e., the changed files are
preserved but not marked for commit) and reports what has not been
updated.

This is the default action.
$ git reset --hard

Resets the index and working tree. Any changes to tracked files in the
working tree since <commit> are discarded.
Diagnose Problems
$ git reflog

1fa215b HEAD@{0}: checkout: moving from 1fa215b to test-branch

1fa215b HEAD@{1}: checkout: moving from master to 1fa215b

ded15c0 HEAD@{2}:
…
Extending Git
Put git-[command] in your $PATH
# show differences between two branches, group by commit
$ git peach
ded15c0 another test commit (2 days ago) <Jingwei "John" Liu>
test.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Put git-[command] in your $PATH (cont)
#!/usr/bin/env bash
# Author: Jingwei Liu <liujingwei02@meituan.com>
# Last Modified: Mar 26 2014 05:52:42 PM
set -e
# show changed files in git cherry
if [[ -n $1 ]]; then
if [[ $1 =~ ^[0-9]*$ ]] ; then
upstream="HEAD~$1"
else
upstream=$1
fi
else
upstream="master"
fi
git cherry $upstream | awk '{print $2}' | xargs git show --stat --
pretty=format:'%Cred%h%Creset %Creset %s %Cgreen(%cr) %C(bold blue)<
%an>%Creset'
Other…
• Hooks

• Aliases

• Config

• Submodule
References
• git-scm.com

• gitready.com

• ProGit

• Deep Darkside of Git (source of a large portion of slides)

• Just use it, and read git help [command]

http://xkcd.com/1296/
Thank you!
http://creativecommons.org/licenses/by-sa/3.0/

More Related Content

What's hot

Git tutorial
Git tutorialGit tutorial
Git tutorial
Pham Quy (Jack)
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
Arulmurugan Rajaraman
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
Md. Ahsan Habib Nayan
 
Git 101
Git 101Git 101
Git 101
jayrparro
 
Learning git
Learning gitLearning git
Learning git
Sid Anand
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
Craig Smith
 
Git - Level 2
Git - Level 2Git - Level 2
Git - Level 2
민태 김
 
Git n git hub
Git n git hubGit n git hub
Git n git hub
Jiwon Baek
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
KMS Technology
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
glen_a_smith
 
Workshop on Git and GitHub
Workshop on Git and GitHubWorkshop on Git and GitHub
Workshop on Git and GitHub
DSCVSSUT
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control System
Mohammad Imam Hossain
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
Majid Hosseini
 
[PUBLIC] Git – Concepts and Workflows.pdf
[PUBLIC] Git – Concepts and Workflows.pdf[PUBLIC] Git – Concepts and Workflows.pdf
[PUBLIC] Git – Concepts and Workflows.pdf
ChimaEzeamama1
 
Git the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version controlGit the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version control
Becky Todd
 
Git and Github Session
Git and Github SessionGit and Github Session
Git and Github Session
GoogleDevelopersStud1
 
Git
GitGit
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
E Carter
 
Git Sunumu
Git SunumuGit Sunumu
Git Sunumu
Zafer Gürel
 
Git undo
Git undoGit undo
Git undo
Avilay Parekh
 

What's hot (20)

Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Git 101
Git 101Git 101
Git 101
 
Learning git
Learning gitLearning git
Learning git
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
 
Git - Level 2
Git - Level 2Git - Level 2
Git - Level 2
 
Git n git hub
Git n git hubGit n git hub
Git n git hub
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Workshop on Git and GitHub
Workshop on Git and GitHubWorkshop on Git and GitHub
Workshop on Git and GitHub
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control System
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
 
[PUBLIC] Git – Concepts and Workflows.pdf
[PUBLIC] Git – Concepts and Workflows.pdf[PUBLIC] Git – Concepts and Workflows.pdf
[PUBLIC] Git – Concepts and Workflows.pdf
 
Git the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version controlGit the Docs: A fun, hands-on introduction to version control
Git the Docs: A fun, hands-on introduction to version control
 
Git and Github Session
Git and Github SessionGit and Github Session
Git and Github Session
 
Git
GitGit
Git
 
The everyday developer's guide to version control with Git
The everyday developer's guide to version control with GitThe everyday developer's guide to version control with Git
The everyday developer's guide to version control with Git
 
Git Sunumu
Git SunumuGit Sunumu
Git Sunumu
 
Git undo
Git undoGit undo
Git undo
 

Viewers also liked

Linux HA anno 2014
Linux HA anno 2014Linux HA anno 2014
Linux HA anno 2014
Julien Pivotto
 
Git Submodules
Git SubmodulesGit Submodules
Git Submodules
Maciej Lasyk
 
Working with multiple git repositories
Working with multiple git repositoriesWorking with multiple git repositories
Working with multiple git repositories
Julien Pivotto
 
realSociable Social Prospecting & Increasing Earned Value in Media
realSociable Social Prospecting & Increasing Earned Value in MediarealSociable Social Prospecting & Increasing Earned Value in Media
realSociable Social Prospecting & Increasing Earned Value in Media
Dalia Asterbadi
 
Regex lecture
Regex lectureRegex lecture
Regex lecture
Jun Shimizu
 
Slicing Up the Mobile Services Revenue Pie
Slicing Up the Mobile Services Revenue PieSlicing Up the Mobile Services Revenue Pie
Slicing Up the Mobile Services Revenue Pie
Sam Gellar
 
핑그래프(Fingra.ph) 모바일 광고 적용 사례
핑그래프(Fingra.ph) 모바일 광고 적용 사례핑그래프(Fingra.ph) 모바일 광고 적용 사례
핑그래프(Fingra.ph) 모바일 광고 적용 사례
Fingra.ph
 

Viewers also liked (8)

Linux HA anno 2014
Linux HA anno 2014Linux HA anno 2014
Linux HA anno 2014
 
Git Submodules
Git SubmodulesGit Submodules
Git Submodules
 
Working with multiple git repositories
Working with multiple git repositoriesWorking with multiple git repositories
Working with multiple git repositories
 
realSociable Social Prospecting & Increasing Earned Value in Media
realSociable Social Prospecting & Increasing Earned Value in MediarealSociable Social Prospecting & Increasing Earned Value in Media
realSociable Social Prospecting & Increasing Earned Value in Media
 
Regex lecture
Regex lectureRegex lecture
Regex lecture
 
Slicing Up the Mobile Services Revenue Pie
Slicing Up the Mobile Services Revenue PieSlicing Up the Mobile Services Revenue Pie
Slicing Up the Mobile Services Revenue Pie
 
핑그래프(Fingra.ph) 모바일 광고 적용 사례
핑그래프(Fingra.ph) 모바일 광고 적용 사례핑그래프(Fingra.ph) 모바일 광고 적용 사례
핑그래프(Fingra.ph) 모바일 광고 적용 사례
 
The beatles
The beatlesThe beatles
The beatles
 

Similar to Git: An introduction of plumbing and porcelain commands

GIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control SystemGIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control System
Tommaso Visconti
 
Version control with GIT
Version control with GITVersion control with GIT
Version control with GIT
Zeeshan Khan
 
Git basics
Git basicsGit basics
Git basics
Malihe Asemani
 
Gitlikeapro 2019
Gitlikeapro 2019Gitlikeapro 2019
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
Nguyen Van Hung
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
Max Claus Nunes
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
sample.pptx
sample.pptxsample.pptx
sample.pptx
UshaSuray
 
Git_new.pptx
Git_new.pptxGit_new.pptx
Git_new.pptx
BruceLee275640
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
Prakash Dantuluri
 
Mini git tutorial
Mini git tutorialMini git tutorial
Mini git tutorial
Cristian Lucchesi
 
git.pptx
git.pptxgit.pptx
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
dropsolid
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
Venkat Malladi
 
Git is a distributed version control system .
Git is a distributed version control system .Git is a distributed version control system .
Git is a distributed version control system .
HELLOWorld889594
 
An introduction to Git
An introduction to GitAn introduction to Git
An introduction to Git
Muhil Vannan
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucketazwildcat
 
Design Systems + Git = Success - Clarity Conference 2018
Design Systems + Git  = Success - Clarity Conference 2018Design Systems + Git  = Success - Clarity Conference 2018
Design Systems + Git = Success - Clarity Conference 2018
Katie Sylor-Miller
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
Nilay Binjola
 
The Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubThe Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHub
BigBlueHat
 

Similar to Git: An introduction of plumbing and porcelain commands (20)

GIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control SystemGIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control System
 
Version control with GIT
Version control with GITVersion control with GIT
Version control with GIT
 
Git basics
Git basicsGit basics
Git basics
 
Gitlikeapro 2019
Gitlikeapro 2019Gitlikeapro 2019
Gitlikeapro 2019
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 
Git_new.pptx
Git_new.pptxGit_new.pptx
Git_new.pptx
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Mini git tutorial
Mini git tutorialMini git tutorial
Mini git tutorial
 
git.pptx
git.pptxgit.pptx
git.pptx
 
Git session Dropsolid.com
Git session Dropsolid.comGit session Dropsolid.com
Git session Dropsolid.com
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Git is a distributed version control system .
Git is a distributed version control system .Git is a distributed version control system .
Git is a distributed version control system .
 
An introduction to Git
An introduction to GitAn introduction to Git
An introduction to Git
 
git-and-bitbucket
git-and-bitbucketgit-and-bitbucket
git-and-bitbucket
 
Design Systems + Git = Success - Clarity Conference 2018
Design Systems + Git  = Success - Clarity Conference 2018Design Systems + Git  = Success - Clarity Conference 2018
Design Systems + Git = Success - Clarity Conference 2018
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
The Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubThe Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHub
 

Recently uploaded

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 

Recently uploaded (20)

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 

Git: An introduction of plumbing and porcelain commands

  • 1.
  • 4. Quick Poll How many of you have use Git? SVN? git rebase?
  • 5. Let’s look at git from another perspective.
  • 6.
  • 7. • distributed version control • working/staging area • how it works
  • 9. Version Control System • storing content • tracking changes to the content • distributing the content • keep accurate yet human-readable history
  • 10. VCS: Types and choices • No remote repository • Central repository • Distributed (with remote) repository
  • 11. Brutal Force VCS • Been there, done that. • Really not very informative • Which version to use? essay.doc essay_2.doc essay3.doc essay_final.doc essay_final2.doc eassay_final3.doc esassy_finalfinal.doc esassy_finalfinal2.doc
  • 13. VCS Design Centralized model all changes to the repository must transact via one specific repository for it to be recorded in history at all. Distributed model where there will often be publicly accessible repositories for collaborators to "push" to, but commits can be made locally and pushed to these public nodes later, allowing offline work.
  • 14. Centralized model Repository Working CopyWorking Copy checkout update log diff commit
  • 15. Distributed Model Remote Repository pull push commit commit checkoutcheckout Working Copy Working Copy log diff Local Repositories
  • 16. Centralized vs. Distributed • Delta-based changeset (linear history) • Directed Acyclic Graphs (DAG) representation
  • 17. Distributed VCS • distributed workflows • safeguard against data corruption • (reasonably) high performance • collaborators could work offline • collaborators could determine when their work are ready to share
  • 19. Git Commands: Plumbing and Porcelain plumbing
 plumbing consists of low-level commands that enable basic content tracking and the manipulation of directed acyclic graphs (DAG) porcelain
 smaller subset of git commands that most Git end users are likely to need to use for maintaining repositories and communicating between repositories for collaboration
  • 20. Low Level Commands (Plumbing) cat-file, commit-tree, count-objects, diff-index, for- each-ref, hash-object, merge-base, read-tree, rev- list, rev-parse, show-ref, symbolic-ref, update-index, update-ref, verify-pack, write-tree
  • 21. High Level Commands (Porcelain) commit/push/pull/merge/… • meant to be readable by human • not meant to be parsed • susceptible to changes/evolutions
  • 22. Describing Changeset with Hash Value Pros • Same content never duplicate Cons • Managing multiple files? • Managing history? • Hard to understand hash values
  • 24. Git Vernaculars blob stores file content. tree stores directory layouts and filenames. commit stores commit info and forms the Git commit graph. tag stores annotated tag
  • 25. Git: A Quick Glance • Content address-able database • Key is SHA-1 hash of object’s content • Value is the content • Same content never duplicate
  • 26. Setup $ git init demo; cd demo
 Initialized empty Git repository in demo/.git/ # monitoring .git folder
 # if you are using bash, then…
 $ while :; do tree .git; sleep 2; done
  • 27. object in Git Same content never duplicate
  • 28. Parsing Object $ echo "test content" | git hash-object -w --stdin
 d670460b4b4aece5915caf5c68d12f560a9fe3e4 $ find .git/objects/ -type f
 .git/objects/d6/70460b4b4aece5915caf5c68d12f560a9fe3e4 $ git cat-file -p d670
 test content $ git cat-file -t d670
 blob
  • 29. hash-object in Git content = "test content" header = "blob %d0", length_of(content) store = header + content sha1 = sha1_of(store) dir = ".git/objects/" + sha1[0:2] + "/" filename = sha1[2:] write(dir + filename, store) # Save compressed header + content
  • 30. hash-object in Git $ echo "Simon" > test.txt $ git hash-object -w test.txt
 83fba84900292b2feb7e955c72eda04a1faa1273 $ echo "Garfunkel" > test.txt $ git hash-object -w test.txt
 6cc4930db0f5ccd17f0bc7bfe0ae850b1b0c06a2 $ git cat-file -p 83fb
 Simon cat test.txt
 Garfunkel
  • 31. tree Object • point to other objects (hashed) with name • a root tree Object is a snapshot
  • 32. tree Object $ mkdir favorites; echo "fantastic" > favorites/band $ git update-index --add test.txt favorites/band $ git write-tree
 d0ef546493e53c3beb98e5da4f437e581ff3c7e0 $ git cat-file -p d0ef
 040000 tree 94b88a81db61ed617621138bc172aa6f3a408545 favorites
 100644 blob 6cc4930db0f5ccd17f0bc7bfe0ae850b1b0c06a2 test.txt $ git cat-file -p 94b8
 100644 blob 744c44c7d1ffb9be8db8cd9f1e2c47830ca6f10b band
  • 34. tree Object $ echo "Byrds" > test.txt $ git update-index --add test.txt $ git write-tree
 3266237ac900a5f09c266b7d6bc79bde6a2386df $ git cat-file -p 3266
 040000 tree 94b88a81db61ed617621138bc172aa6f3a408545 favorites
 100644 blob 1db792a2c726b393332a882fe105bc3ade4ddb66 test.txt $ git cat-file -p 1db7
 Byrds
  • 36. commit Object • explain a change: who/when/why • point to a tree object with above info • pointer, not delta
  • 37. commit Object $ echo "test commit" | git commit-tree d0ef
 1fa215b14c27f2739515eb8410f06478eb0c423e $ git cat-file -p 1fa2
 tree d0ef546493e53c3beb98e5da4f437e581ff3c7e0
 author Jingwei "John" Liu <liujingwei@gmail.com> 1407123580 +0800
 committer Jingwei "John" Liu <liujingwei@gmail.com> 1407123580 +0800
 
 test commit
  • 39. commit Object $ echo "another test commit" | git commit-tree 3266 -p 1fa2
 ded15c0a38dcf226cfbc4838a9d78cd3f8d82baf $ git cat-file -p ded1
 tree 3266237ac900a5f09c266b7d6bc79bde6a2386df
 parent 1fa215b14c27f2739515eb8410f06478eb0c423e
 author Jingwei "John" Liu <liujingwei@gmail.com> 1407123885 +0800
 committer Jingwei "John" Liu <liujingwei@gmail.com> 1407123885 +0800
 
 another test commit
  • 40. commit Object Anatomy $ echo "another test commit" | git commit-tree 3266 -p 1fa2
 ded15c0a38dcf226cfbc4838a9d78cd3f8d82baf $ git cat-file -p ded1
 tree [SHA-1]
 parent [SHA-1]
 author [name] [email] [timestamp] [timezone]
 committer [name] [email] [timestamp] [timezone]
 
 [commit message]
  • 41. T1 F1 F2 6cc4 test.txt 94b8 favorites 6cc4 band T2 T3 F3 Data Structure 1db7 test.txt Commit 1 Commit 2 parent d0ef tree 3266 tree 1fa2 commit ded1 commit
  • 42. commit Object • contains metadata about its ancestors • can have zero or many (theoretically unlimited) parent commits • initial commit has no parent • three-way merge commit has three parents
  • 43. reference in Git • stored in .git/refs • SHA-1
  • 44. reference in Git # create a branch
 $ echo "1fa215b14c27f2739515eb8410f06478eb0c423e" > .git/refs/heads/test-branch $ git branch
 * master
 test-branch $ git log --pretty=oneline test-branch
 1fa215b14c27f2739515eb8410f06478eb0c423e test commit $ find .git/refs/heads -type f
 .git/refs/heads/master
 .git/refs/heads/test-branch
  • 45. reference in Git $ git update-refs refs/heads/master ded15c0a38dcf226cfbc4838a9d78cd3f8d82baf $git log --pretty=oneline master
 ded15c0a38dcf226cfbc4838a9d78cd3f8d82baf another test commit
 1fa215b14c27f2739515eb8410f06478eb0c423e test commit $ cat .git/refs/heads/master
 ded15c0a38dcf226cfbc4838a9d78cd3f8d82baf

  • 46. reference in Git $ cat .git/HEAD
 ref: refs/heads/master $ git branch
 test-branch
 * master $ git symbolic-ref HEAD refs/heads/test-branch $ cat .git/HEAD
 ref: refs/heads/test-branch
  • 47. T1 F1 F2 6cc4 test.txt 94b8 favorites 6cc4 band T2 T3 F3 Data Structure 1db7 test.txt Commit 1 Commit 2 parent refs/heads/test-branch refs/heads/master d0ef tree 3266 tree 1fa2 commit ded1 commit
  • 48. HEAD/head in Git • HEAD is symbolic references. It points to another reference • use ref, not SHA-1 $ cat .git/HEAD
 ref: refs/heads/master $ git branch
 * master
  • 49. T1 F1 F2 83fb test.txt 94b8 favorites 6cc4 test.txt T2 T3 F3 Data Structure 1db7 test.txt Commit 1 Commit 2 parent refs/heads/test-branch refs/heads/master .git/HEAD d0ef tree 3266 tree ded1 commit 1fa2 commit
  • 50. Other references in Git tag once created, it will never change
 unless explicitly updated with --force
 useful for marking specific versions

  • 53. diff $ git diff HEAD # equivalent of… $ git ls-files -m
  • 54. cherry $ git cherry master origin/master # equivalent of… $ git rev-parse master..origin/master
  • 55. status $ git status # equivalent of… $ git ls-files --exclude-per-directory=.gitignore —exclude-from=.git/info/exclude —others --modified -t
  • 57. $ git update-index --add $ echo "commit-msg" | 
 git commit-tree [SHA-1] commit T1 F1 Commit 1
  • 58. $ git update-index --add $ echo "commit-msg" | 
 git commit-tree [SHA-1] $ git write-tree commit T1 F1 Commit 1
  • 59. $ git update-index --add $ echo "commit-msg" | 
 git commit-tree [SHA-1] $ git write-tree $ git update-refs refs/ heads/master T1 F1 Commit 1 refs/heads/master commit
  • 60. Commits in DAG Commit 1 CommitCommit Blob/File info Tree info
  • 61. Create a New File (File 3) Commit 1
  • 62. Create a New File (File 3) Commit 1
  • 63. Create a New File (File 3) Commit 1
  • 64. Commit a New File (File 3) Commit 1 Commit 2
  • 65. Edit and Commit File1 Commit 1 Commit 2
  • 66. Edit and Commit File1 Commit 1 Commit 2
  • 67. Edit and Commit File1 Commit 1 Commit 2
  • 68. Edit and Commit File1 Commit 1 Commit 2 Commit 3
  • 69. merge merge is a commit with N parents, retaining merge history
  • 70. $ git merge $ git merge —-squash Basic Merge
  • 71. $ git status On branch master You have unmerged paths. (fix conflicts and run "git commit") Unmerged paths: (use "git add <file>..." to mark resolution) both modified: index.html no changes added to commit (use "git add" and/or "git commit -a") Basic Merge Conflicts
  • 72. <<<<<<< HEAD <div id="footer">contact : email.support@github.com</div> ======= <div id="footer"> please contact us at support@github.com </div> >>>>>>> some-remote-branch <<<<<<< HEAD (local) HEAD content is here ======= some-remote-branch content is here >>>>>>> some-remote-branch Basic Merge Conflicts
  • 73. $ git mergetool
 This message is displayed because 'merge.tool' is not configured. See 'git mergetool --tool-help' or 'git help config' for more details. 'git mergetool' will now attempt to use one of the following tools: opendiff kdiff3 tkdiff xxdiff meld tortoisemerge gvimdiff diffuse diffmerge ecmerge p4merge araxis bc3 codecompare vimdiff emerge Merging: index.html Normal merge conflict for 'index.html': {local}: modified file {remote}: modified file Hit return to start merge resolution tool (opendiff): Basic Merge Conflicts
  • 74. $ git merge —-abort Aborting Merge
  • 75. $ git merge —s ours $ git merge —s theirs Merge with Strategy
  • 76. pull • fetch + merge • conflict is possible $ git pull origin/master # equivalent of … $ git fetch origin/master
 $ git merge origin/master
  • 77. pull • fetch + merge • conflict is possible $ git pull
  • 78. fetch $ cat .git/config | grep remote
 [remote "origin"]
 url = git://127.0.0.1/git/demo.git
 fetch = +refs/heads/*:refs/remotes/origin/*
 ———————————— ———————————————————
 source destination
  • 79. rebase replay commits one by one on top of a branch
  • 80. • fun • dangerous • use with caution, esp. working with others • only use in local repositories/branches Changing History is…
  • 81. rebase # equivalent to git pull —rebase
 $ git fetch origin/master; git rebase origin/master A---B---C topic / D---E---F---G master to: A'--B'--C' topic / D---E---F---G master
  • 82. rebase $ git rebase -i $ git rebase --onto
  • 83. • replays commits • moves commits • changes commit history • changes commit parent/ancestor rebase
  • 84. Branches in Git • just like parallel universes • nothing more than references to commit
  • 85. # list local branches $ git branch # list local and remote branches $ git branch -a # show branches with reference $ git branch -v # show branch tracking info $ git branch -vv List all Branches
  • 86. $ git remote -vv $ git remote set-url http://example.com/foo.git $ git remote add staging git://git.kernel.org/.../gregkh/staging.git # or just edit .git/info Setting Tracking Info
  • 87. Caret and Tilde • caret(~n): depth-first n-th parent commit • tilde(^n): breadth-first n-th parent commit • See $ git help rev-parse Revision Selection G H I J / / D E F | / | / | |/ | B C / / A A = = A^0 B = A^ = A^1 = A~1 C = A^2 = A^2 D = A^^ = A^1^1 = A~2 E = B^2 = A^^2 F = B^3 = A^^3 G = A^^^ = A^1^1^1 = A~3 H = D^2 = B^^2 = A^^^2 = A~2^2 I = F^ = B^3^ = A^^3^ J = F^2 = B^3^2 = A^^3^2
  • 88. push.default nothing do not push anything (error out) unless a refspec is explicitly given. This is primarily meant for people who want to avoid mistakes by always being explicit. current push the current branch to update a branch with the same name on the receiving end. Works in both central and non-central workflows. upstream push the current branch back to the branch whose changes are usually integrated into the current branch (which is called @{upstream}). This mode only makes sense if you are pushing to the same repository you would normally pull from (i.e. central workflow). simple in centralized workflow, work like upstream with an added safety to refuse to push if the upstream branch's name is different from the local one. When pushing to a remote that is different from the remote you normally pull from, work as current. This is the safest option and is suited for beginners.
  • 92. stash working area staging area local repository upstream repository stash save stash apply stash pop stash list stash show stash drop stash clear stash branch
  • 94. stash working area staging area local repository upstream repository status diff diff [commit or branch] add rm mv commit -a reset —hard checkout merge rebase cherry-pick revert clone pull clean stash pop stash save
  • 102. Find Stuff by… # find file by content
 $ git grep # find file by its name
 $ git ls-file | grep # find changes by line number
 $ git blame -L
  • 103. Find Stuff in log # find changes by commit message
 $ git log | grep # find changes with specific string
 $ git log -S # find changes by file name
 $ git log -p # find changes by author/committer
 $ git log --author
 $ git log --committer #find changes within given time span
 $ git --since
 $ git --until
  • 104. More about log # ignore merges
 $ git log --no-merges # customize how log looks
 $ git log --graph $ git log --online $ git log --pretty="…" $ git log --stat
  • 105. Undo & Cleanup in Git
  • 106. Change Last Commit $ git commit —-amend $ git commit —-amend --no-edit $ git commit ; git rebase -i HEAD~2
  • 107. Unstage Staged Files $ git reset HEAD [filename] $ git reset .
  • 108. Undo Working Modifications $ git checkout -- [filename] $ git checkout . $ git stash $ git stash drop
  • 109. Cleanup Untracked Files $ git clean -df $ git add . $ git stash $ git stash drop
  • 110. Delete Remote Branch # check for proper remote branch name
 $ git branch -a $ git push origin —-delete [branch_name] $ git push origin :[branch_name] # ————————— Explanation ————————— #
 $ cat .git/config | grep remote
 [remote "origin"]
 url = git://127.0.0.1/git/demo.git
 fetch = +refs/heads/*:refs/remotes/origin/*
 ———————————— ———————————————————
 source destination # pushing empty source/reference to destination
  • 111. Be the Last Committer in a Branch # use with caution
 $ git commit --allow-empty
  • 113. Recover Deleted Branch $ git branch -d test-branch
 Deleted branch test-branch (was 1fa215b). $ git checkout 1fa215b
 HEAD is now at 1fa215b... test commit $ git co -b test-branch • Do it before garbage collection
  • 114. Reset Indices $ git reset --soft
 Does not touch the index file or the working tree at all (but resets the head to <commit>, just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it. $ git reset --mixed
 Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated.
 This is the default action. $ git reset --hard
 Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.
  • 115. Diagnose Problems $ git reflog
 1fa215b HEAD@{0}: checkout: moving from 1fa215b to test-branch
 1fa215b HEAD@{1}: checkout: moving from master to 1fa215b
 ded15c0 HEAD@{2}: …
  • 117. Put git-[command] in your $PATH # show differences between two branches, group by commit $ git peach ded15c0 another test commit (2 days ago) <Jingwei "John" Liu> test.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
  • 118. Put git-[command] in your $PATH (cont) #!/usr/bin/env bash # Author: Jingwei Liu <liujingwei02@meituan.com> # Last Modified: Mar 26 2014 05:52:42 PM set -e # show changed files in git cherry if [[ -n $1 ]]; then if [[ $1 =~ ^[0-9]*$ ]] ; then upstream="HEAD~$1" else upstream=$1 fi else upstream="master" fi git cherry $upstream | awk '{print $2}' | xargs git show --stat -- pretty=format:'%Cred%h%Creset %Creset %s %Cgreen(%cr) %C(bold blue)< %an>%Creset'
  • 119. Other… • Hooks • Aliases • Config • Submodule
  • 120. References • git-scm.com • gitready.com • ProGit • Deep Darkside of Git (source of a large portion of slides) • Just use it, and read git help [command] http://xkcd.com/1296/