70
GIT: Inter-Snapshot SeongJae Park <[email protected]>

Git inter-snapshot public

Embed Size (px)

Citation preview

GIT: Inter-SnapshotSeongJae Park <[email protected]>

This Speak Aims To...

Understanding conceptual inside of git

Grow up a little once again together

Software Is Alive: Keeps Changing

Life Of Files

FileA ver 0 FileB ver 0

Life Of Files

FileB Changed

FileA ver 0 FileB ver 1

Life Of Files

FileA Changed

FileB ver 1 FileA ver 1

Life Of Files

FileB Changed Again

FileB ver 2FileA ver 1

Life Of Files

“I miss FileA ver 0!”“Build fail, why? from when?”

FileB ver 2FileA ver 1

Software Is Alive: Keeps Changing

“How To Keep Software’s Moment?”

Software Is Alive: Keeps Changing

“How To Keep Software’s Moment?”

$ ls

0213_1st.tar

0239_2nd.tar.gzip

0305_final.zip

0307_final2.alz

Software Is Alive: Keeps Changing

“How To Keep Software’s Moment?”

$ ls

0213_1st.tar

0239_2nd.tar.gzip

0305_final.zip

0307_final2.alz We will find a version. We always have.http://nofilmschool.com/sites/default/files/styles/article_wide/public/interstellar.jpg?itok=PDUgBX9v

VCS: Version Control System

Help software history managing

Just remember, You SHOULD use it

CVCS vs DVCS

Centralized vs Distributed

Not detail for this time(not main focus)…

Just remember, CVCS is EVIL

git

Distributed Version Control System

Developed For Kernel SCM By Linus Torvalds“Only wimps use tape backup: real men just upload their important stuff on ftp, and let the rest of the world mirror it ;)” - Linus Torvalds

Just remember, cool programmer uses GIT

TL; DR

Snapshot is a moment of the universe

History is a sequence of snapshots

Parallel universes exist

http://i0.kym-cdn.com/photos/images/newsfeed/000/021/503/tldr_trollcat.jpg?1318992465

GIT: BASIC CONCEPTHistory is a Sequence of Snapshots

Snapshot

A moment of the universe

$ tar cf snapshot.tar ShinyProject/*

http://imageserver.moviepilot.com/simpsons-couch-the-simpsons-futurama-crossover-s-couch-gag-gets-weird.png?width=2213&height=1660

History: a Sequence Of Snapshots

$ ls snapshots/

ss.1.tar

ss.2.tar

ss.3.tar

ss.4.tar

ss.5.tarhttp://vintageprintable.swivelchairmedia.com/wp-content/uploads/2011/05/Animal-Stop-motion-Cat-Running-Stop-motion-780x395.jpg

a history

Parallel Universes

Well known theory ;)

For detail, http://www.youtube.com/watch?v=Ywn2Lz5zmYg

Parallel Universes

In short, a snapshot could have multiple parents/children

Parallel histories

GIT: CONCEPT, IN DETAIL

Conceptual Implementation

Working, Staging, Snapshot Dirs

● Based on the snapshot concept,○ VCS could be implemented using 3 types of

directories■ Working, Staging, Snapshot

http://www.make-upstudio.com/files/images/trainingcenter/Large/LIndia-1-6.jpghttp://studio.maginei.com/studioimages/studio.jpghttp://venturebeat.com/wp-content/uploads/2012/05/snapshots.jpg

Working Directory

Sandbox for your funny work, hack, anything

Source code usually reside here

http://www.make-upstudio.com/files/images/trainingcenter/Large/LIndia-1-6.jpg

Staging Directory

Files to be captured in next snapshot

http://studio.maginei.com/studioimages/studio.jpg

Snapshot Directory

Whole snapshots reside here

Every snapshot could be identified uniquely

http://venturebeat.com/wp-content/uploads/2012/05/snapshots.jpg

Simple Example

$ mkdir tars; cd tars

$ echo 80 > sense_of_humor

$ cp sense_of_humor ../staging/

$ tar cf ../snapshots/1st ../staging/*

$ echo 65 > sense_of_humor

$ tar cf ../snapshots/2nd ../staging/*

$ tar xf ../snapshots/1st ./https://pbs.twimg.com/media/B2W_L20CcAAtfGW.jpg:large

GIT: COMMANDSConceptual Implementation of Commands

git init

Create internal directories

$ mkdir ./.git

$ mkdir ./.git/snapshots

$ mkdir ./.git/staging

git add <file path>

Add files to staging directory

$ cp <file path> ./.git/staging/

git commit

Create a snapshot from staging dir

$ tar cf ./git/snapshots/<unique id> \ ./git/staging/*

Branch

Pointer to latest snapshot of a history

branch ‘master’

Branch

Pointer to latest snapshot of a historyFollows subsequent snapshots automatically

branch ‘master’

branch ‘master’

git branch <name>

Create a branch with <name>Created branch follows current history(Below code does not implement history following feature, though)

$ ln -S ./git/snapshots/<name> \

./git/snapshots/<id>

git checkout <id or branch>

● Restore a snapshot <id> or <branch> is pointing on working directory

● If <branch>, transit to the branch’s history○ <branch> will follows subsequent snapshots

$ tar xf ./git/snapshots/<id> ./

GIT: PARALLEL HISTORIESThere are parallel universes

Parallel Universes

Well known theory ;)

For detail, http://www.youtube.com/watch?v=Ywn2Lz5zmYg

Parallel Universes

In short, a snapshot could have multiple parents/children

Parallel histories

Parallel Universes

In short, a snapshot could have multiple parents/children

Parallel histories

Parallel history 1

Parallel Universes

In short, a snapshot could have multiple parents/children

Parallel histories

Parallel history 1

Parallel history 2

Parallel Universes

In short, a snapshot could have multiple parents/children

Parallel histories

Parallel history 1

Parallel history 2

Parallel history 3

Parallel Universes

Branch is useful to manage parallel histories

branch ‘foo’

branch ‘master’

GIT: SCENARIOSIt’s easy if you know parallel universes

“Wait, I did something wrong!”

Past can’t be fixed(Available, actually… though not recommended)

http://therecordingrevolution.com/wordpress/wp-content/uploads/2011/08/mistakes.gif

“Wait, I did something wrong!”

Past can’t be fixed(Available, actually… though not recommended)

Go back and start again from new parallel universe(no time-machine paradox!)

http://d36xcvrkegf0f1.cloudfront.net/images/worlds/2755/HomerTimeTravels.jpg

Scenario: Horrible Thing Committed

branch A

Scenario: Horrible Thing Committed

Make new branch from last sane snapshot

branch A

branch B

Scenario: Horrible Thing Committed

Do things right in this time

branch A

branch B

Scenario: Horrible Thing Committed

Life goes on...

branch A

branch B

git merge <other branch>

Create new child snapshot ofCurrently checked out(HEAD) snapshot and<other branch>

branch A(HEAD)

branch B

$ git merge branch_B\r

git merge <other branch>

Create new child snapshot ofCurrently checked out(HEAD) snapshot and<other branch>

branch A(HEAD)

branch B

$ git merge branch_B\r$

Topic Branch

New branch for every new topic coding

branch master

branch topic2

branch topic1

Topic Branch

New branch for every new topic coding

New topic could be progressed parallel easily

branch master

branch topic2

branch topic1

Topic Branch

New branch for every new topic coding

New topic could be progressed parallel easily

It could be discarded or merged easily

branch master

branch topic2

branch topic1

Topic Branch: Scenario

1. New feature required

branch master

1. New feature requireda. Create a topic branch

Topic Branch: Scenario

branch topic1

branch master

Topic Branch: Scenario

branch topic1

branch master

1. New feature requireda. Create a topic branch and work on it

Topic Branch: Scenario

1. New feature requireda. Create a topic branch and work on it

2. Critical bug founda. Create a topic branch

branch topic2

branch topic1

branch master

Topic Branch: Scenario

1. New feature requireda. Create a topic branch and work on it

2. Critical bug founda. Create a topic branch and work on it

branch topic2

branch topic1

branch master

Topic Branch: Scenario

1. New feature requireda. Create a topic branch and work on it

2. Critical bug founda. Create a topic branch and work on it

3. Merge finished branch

branch master

branch topic2

branch topic1

git rebase --onto <new base> <from> <to>

Apply changes from <from> to <to> on <new base> and checkout applied snapshot

a b c d e f

branch “new_base”

g h branch “to”

branch “from”

git rebase --onto <new base> <from> <to>

Apply changes from <from> to <to> on <new base> and checkout applied snapshot

a b c d e f

branch “new_base”

g h branch “to”

branch “from”

h’

GIT: REMOTEInter-stellar git repositories

Remote Repository

● Just Other’s snapshots directory

● It could be connected via○ file system○ http protocol○ https protocol○ ssh protocol○ git protocol

git clone <remote repo path>

Just fetch <remote repo> and checkout master branch of it

The <remote repo> be named as ‘origin’ by default

git fetch <remote>

Fetch <remote>’s snapshots to local repo

<remote> is ‘origin’ by default

cp <remote>/.git/snapshots/* ./git/snapshots/

git pull

Just git fetch && git merge

git push <remote> <branch>

Push <branch>’s snapshots to <remote>

Free GIT Repo Hosting Service

● GitHub○ Popular service○ Money for private repository

● Bitbucket○ Popular, though less than GitHub○ Free for restricted private repositories

● GitLab○ GitHub like rich-features○ Installable on your private machine○ No limitation at all

Thank you :)

http://jeancharpentier.files.wordpress.com/2012/02/capture-plein-c3a9cran-01022012-230955.jpg

This work by SeongJae Park is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported

License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/.