Smacking Git Around - Advanced Git Tricks

  • View
    7

  • Download
    3

Embed Size (px)

DESCRIPTION

Much of the Ruby and Rails community is now using Git, but there are a number of fun things that are a bit more difficult to get the hang of that are incredibly helpful to know when using Git. This session will go over some advanced Git usage for the casual or intermediate Git user.

Text of Smacking Git Around - Advanced Git Tricks

Smacking Git Aroundby Scott Chacon

Me

Scott Chacon

github.com/schacon

Scott Chacon has an understandable but borderline unhealthy obsession with Git- Ilya Grigorik igvita.com

git-scm.com

book.git-scm.com

schacon@gmail.com

previously, on Git...

GIT

Git

image by matthew mccullough

Scott

Scott Chacon

Scott Chacon is a Git

v1

v2

v3

98ca9.. committree author committer

34ac2.. committree parent author committer

f30ab.. committree parent author committer

size0de24 Scott Scott

size184ca 98ca9 Scott Scott

size92ec2 34ac2 Scott Scott

initial commit of my project

fixed bug #1328 - stack overflow under certain

add feature #32 - ability to add new formats to the central

snapshot A

snapshot B

snapshot C

98ca9.. committree parent author committernil Scott Scott

size0de24

e8455..

0de24.. 0de24..treeblob tree

blob== LICENSE: (The MIT License)

size

sizee8455 README 10af9 lib

Copyright (c) 2007 Tom PrestonPermission is hereby granted, f ree of charge, to any person ob

my commit message goes here and it is really, really cool

10af9.. treeblob tree

bc52a.. size blobrequire 'grit/index' require 'grit/status'

size

bc52a mylib.rb b70f8 inc

module Grit class > test $ git commit -m C2

topic

C2master

C1

$ echo version three >> test $ git commit -m C3topic

C3

C2master

C1

$ git checkout master $ echo version four >> test $ git commit -m C4topic

master

C3

C4

C2

C1

$ echo version five >> test $ git commit -m C5master topic

C5

C3

C4

C2

C1

master

topic

C5

C3

$ git diff topic

C4

C2

C1

master

topic

C5

what does topic have $ git diff that I dont have?C3 C2

topic

C4

C1

master

topic

C5

what would happen if I $ git diff topic merged in topic?C3 C2

C4

C1

master

topic

C5

how do I make topic $ git diff look like HEAD?C3 C2

topic

C4

C1

$ git diff topicmaster topic

C5

C3

C4

C2

diff --git a/test b/test index 304313d..bd8c6c9 100644 --- a/test +++ b/test @@ -1,3 +1,3 @@ version one -version two -version three +version four +version five

C1

$ git diff topicmaster topic

C5

C3

C4

C2

diff --git a/test b/test index 304313d..bd8c6c9 100644 --- a/test +++ b/test @@ -1,3 +1,3 @@ version one -version two -version three +version four +version five

C1

$ git diff HEAD topicmaster topic

C5

C3

C4

C2

diff --git a/test b/test index bd8c6c9..304313d 100644 --- a/test +++ b/test @@ -1,3 +1,3 @@ version one -version four -version five +version two +version three

C1

$ git diff HEAD topicmaster topic

C5

C3

C4

C2

diff --git a/test b/test index bd8c6c9..304313d 100644 --- a/test +++ b/test @@ -1,3 +1,3 @@ version one -version four -version five +version two +version three

C1

git diff HEAD

topic

git diff HEAD...topic

git diff HEAD...topic

$ git diff HEADmaster topic

topic

C5

C3

C4

C2

C1

$ git diff HEADmaster topic

topic

C5

C3

C4

C2

C1

$ git diff HEAD...topicmaster topic

C5

C3

C4

C2

C1

$ git diff HEAD...topicmaster topic

C5

C3

diff --git a/test b/test index 9bc69cf..304313d 100644 --- a/test +++ b/test @@ -1 +1,3 @@ version one +version two +version three

C4

C2

C1

$ git diff HEAD...topicmaster topic

C5

what would happen if I merged in topic?C3 C2

diff --git a/test b/test index 9bc69cf..304313d 100644 --- a/test +++ b/test @@ -1 +1,3 @@ version one +version two +version three

C4

C1

Data Munging

Rewriting History

Modifying the last commit

git commit --amend

Rebasing

master

topic

C5

C3

C4

C2

C1

topic

master

C6

C5

C3

C4

C2

C1

git merge master

master

topic

C5

C3

C4

C2

C1

git rebase master

master

topic

C5

C3

C4

C2

C1

git rebase master

master

topic

C5

C3

C4

C2

C1

git rebase master

master

topic

C5

C3

C4

C2

C1

git rebase master

master

topic

C5

C3

git diff c2 c3 > 2-3.patch

C4

C2

C1

git rebase master

master

topic

C5

C3

git diff c2 c3 > 2-3.patchdiff --git a/test b/test index 2eadcec..bd8c6c9 100644 --- a/test +++ b/test @@ -1,2 +1,3 @@ version one version four +version five

C4

C2

C1

git rebase master

master

topic

C5

C3

C4

C2

C1

2-3.patch

master

topic

C5

C3

C4

C2

C1

git diff c1 c2 > 1-2.patch 2-3.patch

master

topic

C5

C3

C4

C2

C1

git diff c1 c2 > 1-2.patch 1-2.patch 2-3.patch

master

topic

C5

C3

C4

C2

C1

1-2.patch 2-3.patch

git rebase master

master

topic

C5

C3

C4

C2

C1

1-2.patch 2-3.patch

git rebase master1-2.patchmaster topic

C5

C3

C4

C2

C1

2-3.patch

git rebase mastertopic

master

C2'

C5

C3

C4

C2

C1

2-3.patch

2-3.patchtopic

git rebase master

master

C2'

C5

C3

C4

C2

C1

topic

git rebase master

C3'

master

C2'

C5

C3

C4

C2

C1

topic

C3'

master

C2'

git rebase masterC5 C3

C4

C2

C1

topic

C3'

master

C2'

git rebase masterC5 C3

C4

C2

C1

topic

C3'

C2'

git rebase mastermaster

C5

C4

C1

Fun with Rebasing

rebase --onto

Transplanting Topic Branches

master

C1

C2

master

C1

C2

C3

server

master

C1

C2

C3

server

C8

C9

client

master

C1

C2

C3

C4

C10

server

C8

C9

client

master

C1

C2

C5

C6

C3

C4

C10

server

C8

C9

client

move your client branch work to your master branch

master

C1

C2

C5

C6

C3

C4

C10

server

C8

C9

client

master

C1

C2

C5

C6

C3

C4

C10

server

C8

C9

client

master

C1

C2

C5

C6

C3

C4

C10

server

C8

C9

git rebase master

client

master

C1

C2

C5

C6

C3

C4

C10

server

C8

C9

git rebase master

client

master

C1

C2

C5

C6

C3

C4

C10

server

C8

C9

git rebase master

client

master

C1

C2

C5

C6

C3

C4

C10

server

C8

C9

git rebase master

client

master

C1

C2

C5

C6

C3

C4

C10

server

C8

C9

git rebase server

client

master

C1

C2

C5

C6

C3

C4

C10

server

C8

C9

git rebase server

client

master

C1

C2

C5

C6

C3

C4

C10

server

C8

C9

git rebase server

client

master

C1

C2

C5

C6

C3

C4

C10

server

C8

C9

git rebase server

client

master

C1

C2

C5

C6

C3

C4

C10

server

C8

C9

client

git rebase --onto master server

master

C1

C2

C5

C6

C3

C4

C10

server

C8

C9

client

git rebase --onto master server

master

C1

C2

C5

C6

C3

C4

C10

server

C8

C9

client

git rebase --onto master server

master

C1

C2

C5

C6