SlideShare ist ein Scribd-Unternehmen logo
1 von 121
Downloaden Sie, um offline zu lesen
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/

Weitere ähnliche Inhalte

Was ist angesagt?

Git 기본개념과 사용법 그리고 어플리케이션
Git 기본개념과 사용법 그리고 어플리케이션Git 기본개념과 사용법 그리고 어플리케이션
Git 기본개념과 사용법 그리고 어플리케이션Dabi Ahn
 
Git branch stregagy & case study
Git branch stregagy & case studyGit branch stregagy & case study
Git branch stregagy & case studyWoo Jin Kim
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practiceMajid Hosseini
 
Formation autour de git et git lab
Formation autour de git et git labFormation autour de git et git lab
Formation autour de git et git labAbdelghani Azri
 
15分でわかるGit入門
15分でわかるGit入門15分でわかるGit入門
15分でわかるGit入門to_ueda
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewRueful Robin
 
Git Terminologies
Git TerminologiesGit Terminologies
Git TerminologiesYash
 
Why Aren't You Using Git Flow?
Why Aren't You Using Git Flow?Why Aren't You Using Git Flow?
Why Aren't You Using Git Flow?John Congdon
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHubVikram SV
 
svn 능력자를 위한 git 개념 가이드
svn 능력자를 위한 git 개념 가이드svn 능력자를 위한 git 개념 가이드
svn 능력자를 위한 git 개념 가이드Insub Lee
 

Was ist angesagt? (20)

Git basics
Git basicsGit basics
Git basics
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Git 기본개념과 사용법 그리고 어플리케이션
Git 기본개념과 사용법 그리고 어플리케이션Git 기본개념과 사용법 그리고 어플리케이션
Git 기본개념과 사용법 그리고 어플리케이션
 
Introducing GitLab
Introducing GitLabIntroducing GitLab
Introducing GitLab
 
Git branch stregagy & case study
Git branch stregagy & case studyGit branch stregagy & case study
Git branch stregagy & case study
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
 
Formation autour de git et git lab
Formation autour de git et git labFormation autour de git et git lab
Formation autour de git et git lab
 
Git advanced
Git advancedGit advanced
Git advanced
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
15分でわかるGit入門
15分でわかるGit入門15分でわかるGit入門
15分でわかるGit入門
 
Git commands
Git commandsGit commands
Git commands
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
 
Git Terminologies
Git TerminologiesGit Terminologies
Git Terminologies
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Git undo
Git undoGit undo
Git undo
 
Why Aren't You Using Git Flow?
Why Aren't You Using Git Flow?Why Aren't You Using Git Flow?
Why Aren't You Using Git Flow?
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
svn 능력자를 위한 git 개념 가이드
svn 능력자를 위한 git 개념 가이드svn 능력자를 위한 git 개념 가이드
svn 능력자를 위한 git 개념 가이드
 

Andere mochten auch

Working with multiple git repositories
Working with multiple git repositoriesWorking with multiple git repositories
Working with multiple git repositoriesJulien 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 MediaDalia Asterbadi
 
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 PieSam Gellar
 
핑그래프(Fingra.ph) 모바일 광고 적용 사례
핑그래프(Fingra.ph) 모바일 광고 적용 사례핑그래프(Fingra.ph) 모바일 광고 적용 사례
핑그래프(Fingra.ph) 모바일 광고 적용 사례Fingra.ph
 

Andere mochten auch (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
 

Ähnlich wie Git: An introduction of plumbing and porcelain commands

Ähnlich wie 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
 
Git 101
Git 101Git 101
Git 101
 
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
 
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
 
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
 
Understanding GIT
Understanding GITUnderstanding GIT
Understanding GIT
 

Kürzlich hochgeladen

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Kürzlich hochgeladen (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

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/