soonho kong - carnegie mellon school of computer …soonhok/talks/20140519_git.pdf · git ≃ dag...

98
Soonho Kong Soonho Kong 2014/05/19, CMU http://www.cs.cmu.edu/~soonhok

Upload: vokhanh

Post on 01-Sep-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Soonho KongSoonho Kong

2014/05/19, CMU

http://www.cs.cmu.edu/~soonhok

Page 2: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

IntroductionIntroduction

Page 3: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers
Page 4: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Google Trend: git vs. svn

Page 5: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Ohloh: Compare Repositories

Page 6: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Git: "The stupid content tracker"

Page 7: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

"I did not really expect anyone to use itbecause it’s so hard to use…"

-"Linus Torvalds goes off on Linux and Git"(Fake Interview)

Page 8: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

ConceptsConcepts

Page 9: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Git Git DAG DAG≃≃

"Once you realize that git is just a DAGwith commit objects as vertices,and pointers (refs) into that graph,

it becomes a lot simpler to understand"

Page 10: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Git Git DAG DAG≃≃

Repository Graph≃Node (Commit) Files≃

Label (refs) Branch / Tag / etc≃

Page 11: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Commit Three Stage ThinkingCommit Three Stage Thinking

working staging history

Page 12: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Commit Three Stage ThinkingCommit Three Stage Thinking

working staging history

Page 13: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Commit Three Stage ThinkingCommit Three Stage Thinking

working staging historyadd

Page 14: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Commit Three Stage ThinkingCommit Three Stage Thinking

working staging historyadd commit

Page 15: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

WorkflowWorkflow

Page 16: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Install and ConfigInstall and Config

Page 17: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

InstallInstallOSX

$ brew install git

Linux$ sudo apt-get install git

WindowsVisit http://git-scm.com/

Page 18: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Config: Name & EmailConfig: Name & Email$ git config --global user.name "your-name"$ git config --global user.email "your-email-address"

Page 19: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Config: Useful SettingsConfig: Useful Settings# Colorize console output$ git config --global color.ui auto

# Force files to be LF on Mac/Linux$ git config --global core.autocrlf input

# Force Windows to convert to CRLF# on checkout and to LF on `add`$ git config --global core.autocrlf true

Page 20: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Config: Like a Boss!Config: Like a Boss!By default for "git log –all"

Page 21: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Config: Like a Boss!Config: Like a Boss!Now, "git la"

http://www.jayway.com/2012/11/27/configure-git-like-a-boss/

Page 22: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Basic(init/add/commit)Basic(init/add/commit)http://try.github.io

Page 23: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

InitInitFrom Scratch

# New project$ git init newproject$ cd newproject# ...start coding

Page 24: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

InitInitFrom Existing Dir

# Legacy project tree$ cd existingproject$ git init

# Add all the code$ git add .$ git commit -m "Initial import"

Page 25: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Commit Your First CommitCommit Your First Commitgit add git statusgit commit -m "Helpful message"

Page 26: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

NetworkNetwork

Page 27: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

NetworkNetwork

local

Page 28: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

NetworkNetwork

local origin

Page 29: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

NetworkNetwork

Page 30: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

NetworkNetwork

local originclone

$ git clone [email protected]:soonhokong/drealCloning into 'dreal'...remote: Reusing existing pack: 79707, done.remote: Counting objects: 127, done.remote: Compressing objects: 100% (98/98), done.remote: Total 79834 (delta 37), reused 74 (delta 29)Receiving objects: 100% (79834/79834), 49.25 MiB | 2.34 MiB/s, done.Resolving deltas: 100% (39555/39555), done.Checking connectivity... done.

Page 31: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

NetworkNetwork

local originclone

$ git remote -vorigin [email protected]:soonhokong/dreal (fetch)origin [email protected]:soonhokong/dreal (push)

Page 32: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

NetworkNetwork

local originpush

$ git pushCounting objects: 9, done.Delta compression using up to 4 threads.Compressing objects: 100% (3/3), done.Writing objects: 100% (3/3), 286 bytes | 0 bytes/s, done.Total 3 (delta 2), reused 0 (delta 0)To [email protected]:soonhokong/dreal bee5818..40155b4 master -> master

Page 33: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

NetworkNetwork

local originpush

remotesfetch

$ git fetch originremote: Counting objects: 3, done.remote: Compressing objects: 100% (3/3), done.remote: Total 3 (delta 0), reused 0 (delta 0)Unpacking objects: 100% (3/3), done.From github.com:soonhokong/dreal bee5818..40155b4 master -> origin/master

Page 34: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

NetworkNetwork

local originpush

remotesfetch

merge

$ git merge origin/masterUpdating bee5818..40155b4Fast-forward README.md | 1 + 1 file changed, 1 insertion(+)

Page 35: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

NetworkNetwork

local originpush

remotespull

pull

$ git pull origin masterFrom github.com:soonhokong/dreal * branch master -> FETCH_HEADUpdating bee5818..40155b4Fast-forward README.md | 1 + 1 file changed, 1 insertion(+)

Page 36: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

NetworkNetwork

local originpush

remotespull

pull

Don't use git pull!Use git fetch and then git rebase (or git merge)

http://longair.net/blog/2009/04/16/git-fetch-and-merge

Page 37: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Centralized WorkflowCentralized Workflow

Page 38: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Centralized WorkflowCentralized Workflow

The way people are using SVN

Page 39: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Centralized WorkflowCentralized Workflow

You can use git in this way, too

Page 40: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Centralized WorkflowCentralized WorkflowWhat's a problem?

Page 41: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Problem of Centralized WorkflowProblem of Centralized Workflow

I'm working at CMU…

Page 42: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Problem of Centralized WorkflowProblem of Centralized Workflow

I want to go home and resume the work.

Page 43: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Problem of Centralized WorkflowProblem of Centralized Workflow

So I push what I've done so far to the repo

Page 44: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Problem of Centralized WorkflowProblem of Centralized Workflow

@Home, I pull what I pushed and resume the work.

Page 45: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Problem of Centralized WorkflowProblem of Centralized Workflow

In the meantime, Leo pushed a commit to the repo.

Page 46: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Problem of Centralized WorkflowProblem of Centralized Workflow

I finished my part at home, push to the repo.

Page 47: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Problem of Centralized WorkflowProblem of Centralized Workflow

Problem: Repo will be filled with intermediate commits

Page 48: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Problem of Centralized WorkflowProblem of Centralized Workflow

Problem: Single Sync Point = Merge Conflicts↑

Page 49: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Problem of Centralized WorkflowProblem of Centralized Workflow

Not Scalable ( 5 members)≤

Page 50: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Distributed workflowDistributed workflow

Page 51: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Distributed workflowDistributed workflow

There is the Blessed repository.

Page 52: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Distributed workflowDistributed workflow

Page 53: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Distributed workflowDistributed workflow

Page 54: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Distributed workflowDistributed workflow

Page 55: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Distributed workflowDistributed workflow

Clone personal repo (origin):$ git clone [email protected]:soonhokong/dreal.git$ git remote -vorigin [email protected]:soonhokong/dreal.git (fetch)origin [email protected]:soonhokong/dreal.git (push)

Add blessed repo:$ git remote add blessed [email protected]:dreal/dreal$ git remote -vblessed [email protected]:dreal/dreal.git (fetch)blessed [email protected]:dreal/dreal.git (push)origin [email protected]:soonhokong/dreal.git (fetch)origin [email protected]:soonhokong/dreal.git (push)

Page 56: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Distributed workflowDistributed workflow

Most of time, we push to personal repos.

Page 57: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Distributed workflowDistributed workflow

You can do destructive update (forced push) on your repo.

Page 58: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Distributed workflowDistributed workflow

When the work is solid, we push to the blessed.

Page 59: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Distributed workflowDistributed workflow

or make a pull-request.https://help.github.com/articles/using-pull-requests

Page 60: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

RebaseRebaseMany meaningful git operations

can be expressedin terms of the rebase command.

Page 61: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Merge vs. RebaseMerge vs. Rebase

Page 62: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Merge vs. RebaseMerge vs. Rebase

Page 63: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Merge vs. RebaseMerge vs. Rebase

Page 64: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Merge vs. RebaseMerge vs. Rebase

Page 65: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Merge vs. RebaseMerge vs. Rebase$ git push blessed masterCounting objects: 28, done.Delta compression using up to 4 threads.Compressing objects: 100% (9/9), done.Writing objects: 100% (9/9), 955 bytes | 0 bytes/s, done.Total 9 (delta 6), reused 0 (delta 0)To [email protected]:dreal/dreal.git ! [rejected] master -> master (non-fast-forward)error: failed to push some refs to '[email protected]:dreal/dreal.git'hint: Updates were rejected because a pushed branch tip is behind its remotehint: counterpart. Check out this branch and integrate the remote changeshint: (e.g. 'git pull ...') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.

non-fast-forward??

Page 66: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Merge vs. RebaseMerge vs. Rebase

Page 67: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Merge vs. RebaseMerge vs. Rebase

Page 68: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

MergeMerge vs. Rebase vs. Rebase

Page 69: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

MergeMerge vs. Rebase vs. Rebase

Page 70: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

MergeMerge vs. Rebase vs. Rebase

OK?

Page 71: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

MergeMerge vs. Rebase vs. Rebase

OK?

Page 72: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

MergeMerge vs. Rebase vs. Rebase

Merge Hell

Page 73: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Version Controll PitfallsVersion Controll Pitfalls1. History should be written in chronological order.2. Commits are immutable and immovable objects.

git rebase will free you!!

Page 74: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Merge vs. RebaseMerge vs. Rebase

Page 75: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Merge vs. Merge vs. RebaseRebase

Page 76: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Merge vs. Merge vs. RebaseRebase

Page 77: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Merge vs. Merge vs. RebaseRebase

Page 78: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Merge vs. Merge vs. RebaseRebase

Page 79: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Interactive RebaseInteractive Rebase

Page 80: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Interactive RebaseInteractive Rebase

Page 81: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Interactive RebaseInteractive Rebase

Page 82: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Interactive RebaseInteractive Rebase

Page 83: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Interactive RebaseInteractive Rebase

I want to combine the three commits into one.

Page 84: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Interactive RebaseInteractive Rebase

git rebase origin/master doesn't do anything.

Page 85: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Interactive RebaseInteractive Rebase

Run git rebase -i origin/master

Page 86: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Interactive RebaseInteractive RebaseRun git rebase -i origin/master

pick 40155b4 Fix an Issue #1pick 42e5db9 Minor Fix of Previous Fixpick a31c7cd Minor Minor Fix or Previous Fix

# Rebase ec2ae2b..cf0977c onto ec2ae2b## Commands:# p, pick = use commit# r, reword = use commit, but edit the commit message# e, edit = use commit, but stop for amending# s, squash = use commit, but meld into previous commit# f, fixup = like "squash", but discard this commit's log message# x, exec = run command (the rest of the line) using shell## These lines can be re-ordered; they are executed from top to bottom.## If you remove a line here THAT COMMIT WILL BE LOST.## However, if you remove everything, the rebase will be aborted.#

Page 87: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Interactive RebaseInteractive RebaseRun git rebase -i origin/master

pick 40155b4 Fix an Issue #1f 42e5db9 Minor Fix of Previous Fixf a31c7cd Minor Minor Fix or Previous Fix

# Rebase ec2ae2b..cf0977c onto ec2ae2b## Commands:# p, pick = use commit# r, reword = use commit, but edit the commit message# e, edit = use commit, but stop for amending# s, squash = use commit, but meld into previous commit# f, fixup = like "squash", but discard this commit's log message# x, exec = run command (the rest of the line) using shell## These lines can be re-ordered; they are executed from top to bottom.## If you remove a line here THAT COMMIT WILL BE LOST.## However, if you remove everything, the rebase will be aborted.#

Page 88: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Interactive RebaseInteractive Rebase

Page 89: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

WarningWarning on Rebase on Rebase

Rebase will create a new commit.

Page 90: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

WarningWarning on Rebase on Rebase

It's OK to rebase and destructively update personal repo.

Page 91: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

WarningWarning on Rebase on Rebase

It's OK to rebase and destructively update personal repo.

Page 92: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

WarningWarning on Rebase on Rebase

But you should not destructively update the blessed repo.

Page 93: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

WarningWarning on Rebase on Rebase

Because other users base on blessed/master.

Page 94: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

ResetReset"Git Reset Demystified"

http://git-scm.com/blog/2011/07/11/reset.html

Page 95: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Magit (emacs's git-mode)Magit (emacs's git-mode)(Available from package-list)

https://github.com/mtdavidson/magit-cheatsheet/http://vickychijwani.github.io/2011/09/09/Magit-Part-I/http://vickychijwani.github.io/2011/11/26/An-Introduction-to-Magit-Part-II/

Page 96: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Github tipsGithub tipshttps://github.com/tiimgreen/github-cheat-sheet

Page 97: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Other Useful ResourcesOther Useful ResourcesQuick Guide : Complete Reference : Visual Git Reference :

Nice Interactive Tutorial on Git Branches:

http://rogerdudler.github.io/git-guide/http://git-scm.com/book

http://marklodato.github.io/visual-git-guide/index-en.html

http://pcottle.github.io/learnGitBranching/

Page 98: Soonho Kong - Carnegie Mellon School of Computer …soonhok/talks/20140519_Git.pdf · Git ≃ DAG "Once you realize that git is just a DAG with commit objects as vertices, and pointers

Thank youThank you