61
GIT어떻게 동작하는가 13년 10월 17일 목요일

DEVIEW 2013 - Git은 어떻게 동작하는가

Embed Size (px)

Citation preview

Page 1: DEVIEW 2013 - Git은 어떻게 동작하는가

GIT은 어떻게 동작하는가

13년 10월 17일 목요일

Page 2: DEVIEW 2013 - Git은 어떻게 동작하는가

세션 내용 소개

1.����������� ������������������  저장소와����������� ������������������  커밋2.����������� ������������������  브랜치와����������� ������������������  머지3.����������� ������������������  Push����������� ������������������  &����������� ������������������  PULL����������� ������������������  4.����������� ������������������  JGit을����������� ������������������  이용한����������� ������������������  Pull����������� ������������������  Request의����������� ������������������  구현

13년 10월 17일 목요일

Page 3: DEVIEW 2013 - Git은 어떻게 동작하는가

주의

Git의����������� ������������������  사용법에����������� ������������������  대해서는이야기하지����������� ������������������  않습니다.

13년 10월 17일 목요일

Page 4: DEVIEW 2013 - Git은 어떻게 동작하는가

Working Directory (.)Working Directory (.)

a.txt “Hello”

b.txt “World”

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD

master

bad default revision

$ git init # 저장소를 만든다.$ echo Hello > a.txt$ echo World > b.txt

$ cat .git/HEADrefs: refs/heads/master

저장소와 커밋

13년 10월 17일 목요일

Page 5: DEVIEW 2013 - Git은 어떻게 동작하는가

Working Directory (.)Working Directory (.)

a.txt “Hello”

b.txt “World”

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD

master

blob e965

“Hello”

blob 216e

“World”

$ git add a.txt$ git add b.txt

bad default revision

Index (.git/index)Index (.git/index)

a.txt e965

b.txt 216e

.git/objects/21/6e97ce08229b8776d3feb731c6d23a2f669ac8

13년 10월 17일 목요일

Page 6: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD

master

Working Directory (.)Working Directory (.)

a.txt “Hello”

b.txt “World” blob e965

“Hello”

blob 216e

“World”

$ git commit -m ‘Add a.txt and b.txt’

bad default revision

Index (.git/index)Index (.git/index)

a.txt e965

b.txt 216e

13년 10월 17일 목요일

Page 7: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD masterWorking Directory (.)Working Directory (.)

a.txt “Hello”

b.txt “World”

blob e965

“Hello”

blob 216e

“World”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

$ git commit -m ‘Add a.txt and b.txt’

bad default revision

Index (.git/index)Index (.git/index)

a.txt e965

b.txt 216e

13년 10월 17일 목요일

Page 8: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD masterWorking Directory (.)Working Directory (.)

a.txt “Hello”

b.txt “World”

blob e965

“Hello”

blob 216e

“World”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

$ echo HELLO > a.txt

Index (.git/index)Index (.git/index)

a.txt e965

b.txt 216e

13년 10월 17일 목요일

Page 9: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD masterWorking Directory (.)Working Directory (.)

a.txt “HELLO”

b.txt “World”

blob e965

“Hello”

blob 216e

“World”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

$ echo HELLO > a.txt

Index (.git/index)Index (.git/index)

a.txt e965

b.txt 216e

13년 10월 17일 목요일

Page 10: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD masterWorking Directory (.)Working Directory (.)

a.txt “HELLO”

b.txt “World”

blob e965

“Hello”

blob 216e

“World”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

$ echo HELLO > a.txt$ git add a.txt

Index (.git/index)Index (.git/index)

a.txt e965

b.txt 216e

13년 10월 17일 목요일

Page 11: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD masterWorking Directory (.)Working Directory (.)

a.txt “HELLO”

b.txt “World”

$ echo HELLO > a.txt

blob e427

“HELLO”

$ git add a.txt

blob e965

“Hello”

blob 216e

“World”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

Index (.git/index)Index (.git/index)

a.txt e965

b.txt 216e

13년 10월 17일 목요일

Page 12: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD masterWorking Directory (.)Working Directory (.)

a.txt “HELLO”

b.txt “World”

$ echo HELLO > a.txt

blob e427

“HELLO”

$ git add a.txt

blob e965

“Hello”

blob 216e

“World”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

Index (.git/index)Index (.git/index)

a.txt e427

b.txt 216e

13년 10월 17일 목요일

Page 13: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD masterWorking Directory (.)Working Directory (.)

a.txt “HELLO”

b.txt “World”

$ echo HELLO > a.txt

blob e427

“HELLO”

$ git commit -m ‘Update a.txt’

blob e965

“Hello”

blob 216e

“World”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

$ git add a.txt

Index (.git/index)Index (.git/index)

a.txt e427

b.txt 216e

13년 10월 17일 목요일

Page 14: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD masterWorking Directory (.)Working Directory (.)

a.txt “HELLO”

b.txt “World”

blob e427

“HELLO”

blob e965

“Hello”

blob 216e

“World”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

$ echo HELLO > a.txt

$ git commit -m ‘Update a.txt’$ git add a.txt

Index (.git/index)Index (.git/index)

a.txt e427

b.txt 216e

13년 10월 17일 목요일

Page 15: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD masterWorking Directory (.)Working Directory (.)

a.txt “HELLO”

b.txt “World”

blob e427

“HELLO”

blob e965

“Hello”

blob 216e

“World”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

$ rm b.txt

Index (.git/index)Index (.git/index)

a.txt e427

b.txt 216e

13년 10월 17일 목요일

Page 16: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD masterWorking Directory (.)Working Directory (.)

a.txt “HELLO”

Index (.git/index)Index (.git/index)

a.txt e427

b.txt 216e

blob e427

“HELLO”

blob e965

“Hello”

blob 216e

“World”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

$ rm b.txt$ git rm --cached b.txt

13년 10월 17일 목요일

Page 17: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD masterWorking Directory (.)Working Directory (.)

a.txt “HELLO”

$ rm b.txt

blob e427

“HELLO”

blob e965

“Hello”

blob 216e

“World”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

$ git rm --cached b.txt$ git commit -m ‘Delete b.txt’

Index (.git/index)Index (.git/index)

a.txt e427

13년 10월 17일 목요일

Page 18: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD masterWorking Directory (.)Working Directory (.)

a.txt “HELLO”

$ rm b.txt

blob e427

“HELLO”

blob e965

“Hello”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

$ git rm --cached b.txt$ git commit -m ‘Delete b.txt’

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txtIndex (.git/index)Index (.git/index)

a.txt e427

13년 10월 17일 목요일

Page 19: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD masterWorking Directory (.)Working Directory (.)

a.txt “HELLO”

$ rm b.txt$ git rm --cached b.txt$ git commit -m ‘Delete b.txt’

blob e427

“HELLO”

blob e965

“Hello”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txtIndex (.git/index)Index (.git/index)

a.txt e427

13년 10월 17일 목요일

Page 20: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD master

$ mv a.txt A.txt

blob e427

“HELLO”

blob e965

“Hello”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

Working Directory (.)Working Directory (.)

a.txt “HELLO”

Index (.git/index)Index (.git/index)

a.txt e427

13년 10월 17일 목요일

Page 21: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD master

$ mv a.txt A.txt

blob e427

“HELLO”

blob e965

“Hello”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

Working Directory (.)Working Directory (.)

A.txt “HELLO”

Index (.git/index)Index (.git/index)

a.txt e427

13년 10월 17일 목요일

Page 22: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD master

$ mv a.txt A.txt

blob e427

“HELLO”

blob e965

“Hello”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

Working Directory (.)Working Directory (.)

A.txt “HELLO”

$ git rm --cached a.txt

Index (.git/index)Index (.git/index)

a.txt e427

13년 10월 17일 목요일

Page 23: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD master

$ mv a.txt A.txt

blob e427

“HELLO”

blob e965

“Hello”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

Working Directory (.)Working Directory (.)

A.txt “HELLO”

$ git rm --cached a.txt

Index (.git/index)Index (.git/index)

13년 10월 17일 목요일

Page 24: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD master

$ mv a.txt A.txt

blob e427

“HELLO”

blob e965

“Hello”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

Working Directory (.)Working Directory (.)

A.txt “HELLO”

Index (.git/index)Index (.git/index)

$ git rm --cached a.txt$ git add A.txt

13년 10월 17일 목요일

Page 25: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD master

$ mv a.txt A.txt

blob e427

“HELLO”

blob e965

“Hello”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

$ git rm --cached a.txt$ git add A.txt

Working Directory (.)Working Directory (.)

A.txt “HELLO”

Index (.git/index)Index (.git/index)

A.txt e427

13년 10월 17일 목요일

Page 26: DEVIEW 2013 - Git은 어떻게 동작하는가

blob e427

“HELLO”

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD master

$ git commit -m ‘Rename a.txt to A.txt’

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

blob e965

“Hello”

tree 9d1ctree 9d1ctree 9d1c

blob e965 a.txt

blob 216e b.txt

commit 73d3commit 73d3

tree 9d1c

...저자 등등......저자 등등...

“Add a.txt and b.txt”“Add a.txt and b.txt”

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

Working Directory (.)Working Directory (.)

A.txt “HELLO”

Index (.git/index)Index (.git/index)

A.txt e427

13년 10월 17일 목요일

Page 27: DEVIEW 2013 - Git은 어떻게 동작하는가

blob e427

“HELLO”

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD master

$ git commit -m ‘Rename a.txt to A.txt’

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

tree 8808tree 8808tree 8808

blob e427 A.txt

commit 2825commit 2825tree 8808

parent 8511

...저자 등등......저자 등등...“Rename a.txt to...”“Rename a.txt to...”

Working Directory (.)Working Directory (.)

A.txt “HELLO”

Index (.git/index)Index (.git/index)

A.txt e427

13년 10월 17일 목요일

Page 28: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD master

$ git commit -m ‘Rename a.txt to A.txt’

blob e427

“HELLO”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

tree 8808tree 8808tree 8808

blob e427 A.txt

commit 2825commit 2825tree 8808

parent 8511

...저자 등등......저자 등등...“Rename a.txt to...”“Rename a.txt to...”

Working Directory (.)Working Directory (.)

A.txt “HELLO”

Index (.git/index)Index (.git/index)

A.txt e427

13년 10월 17일 목요일

Page 29: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD master

$ mkdir src

blob e427

“HELLO”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

tree 8808tree 8808tree 8808

blob e427 A.txt

commit 2825commit 2825tree 8808

parent 8511

...저자 등등......저자 등등...“Rename a.txt to...”“Rename a.txt to...”

Working Directory (.)Working Directory (.)

A.txt “HELLO”

Index (.git/index)Index (.git/index)

A.txt e427

13년 10월 17일 목요일

Page 30: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD master

$ mkdir src

blob e427

“HELLO”

Working Directory (.)Working Directory (.)

src/

A.txt “HELLO”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

tree 8808tree 8808tree 8808

blob e427 A.txt

commit 2825commit 2825tree 8808

parent 8511

...저자 등등......저자 등등...“Rename a.txt to...”“Rename a.txt to...”

$ git mv A.txt src/A.txt

Index (.git/index)Index (.git/index)

A.txt e427

13년 10월 17일 목요일

Page 31: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

HEAD master

$ mkdir src

blob e427

“HELLO”

Working Directory (.)Working Directory (.)

src/

src/A.txt “HELLO”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

tree 8808tree 8808tree 8808

blob e427 A.txt

commit 2825commit 2825tree 8808

parent 8511

...저자 등등......저자 등등...“Rename a.txt to...”“Rename a.txt to...”

$ git mv A.txt src/A.txt

Index (.git/index)Index (.git/index)

A.txt e427

13년 10월 17일 목요일

Page 32: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

master

$ mkdir src

Working Directory (.)Working Directory (.)

src/

src/A.txt “HELLO”

Index (.git/index)Index (.git/index)

src/A.txt e427

HEAD

blob e427

“HELLO”

tree 06d2tree 06d2tree 06d2

blob e427 a.txt

blob 216e b.txt

commit 8511commit 8511tree 06d2

parent 73d3

...저자 등등......저자 등등...“Update a.txt”“Update a.txt”

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

tree 8808tree 8808tree 8808

blob e427 A.txt

commit 2825commit 2825tree 8808

parent 8511

...저자 등등......저자 등등...“Rename a.txt to...”“Rename a.txt to...”

$ git mv A.txt src/A.txt$ git commit -m ‘Move A.txt into src’

13년 10월 17일 목요일

Page 33: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

master

$ mkdir src

Working Directory (.)Working Directory (.)

src/

src/A.txt “HELLO”

Index (.git/index)Index (.git/index)

src/A.txt e427

HEAD

blob e427

“HELLO”

$ git mv A.txt src/A.txt$ git commit -m ‘Move A.txt into src’

commit 3183commit 3183tree 2dc1

parent 2825

...저자 등등......저자 등등...“Move a.txt into src”“Move a.txt into src”

tree 2dc1tree 2dc1tree 2dc1

tree 8808 src/

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

tree 8808tree 8808tree 8808

blob e427 A.txt

commit 2825commit 2825tree 8808

parent 8511

...저자 등등......저자 등등...“Rename a.txt to...”“Rename a.txt to...”

13년 10월 17일 목요일

Page 34: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

master

$ mkdir src

Working Directory (.)Working Directory (.)

src/

src/A.txt “HELLO”

Index (.git/index)Index (.git/index)

src/A.txt e427

HEAD

blob e427

“HELLO”

$ git mv A.txt src/A.txt$ git commit -m ‘Move A.txt into src’

commit 3183commit 3183tree 2dc1

parent 2825

...저자 등등......저자 등등...“Move a.txt into src”“Move a.txt into src”

tree 2dc1tree 2dc1tree 2dc1

tree 8808 src/

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

tree 8808tree 8808tree 8808

blob e427 A.txt

commit 2825commit 2825tree 8808

parent 8511

...저자 등등......저자 등등...“Rename a.txt to...”“Rename a.txt to...”

13년 10월 17일 목요일

Page 35: DEVIEW 2013 - Git은 어떻게 동작하는가

Git Repository (non-bare)Object Database(.git/objects/)

Refs (.git/)

master

$ mkdir src

Working Directory (.)Working Directory (.)

src/

src/A.txt “HELLO”

Index (.git/index)Index (.git/index)

src/A.txt e427

HEAD

$ git mv A.txt src/A.txt$ git commit -m ‘Move A.txt into src’

src/

HELLO

tree 2dc1tree 2dc1tree 2dc1

tree 8808 src/

commit 8bc3commit 8bc3tree 4fa8

parent 8511

...저자 등등......저자 등등...“Delete b.txt”“Delete b.txt”

tree 4fa8tree 4fa8tree 4fa8

blob e427 a.txt

tree 8808tree 8808tree 8808

blob e427 A.txt

commit 2825commit 2825tree 8808

parent 8511

...저자 등등......저자 등등...“Rename a.txt to...”“Rename a.txt to...”

A.txt

a.txt

Rename a.txt...

Delete b.txt...

commit 3183commit 3183tree 2dc1

parent 2825

...저자 등등......저자 등등...“Move a.txt into src”“Move a.txt into src”

Move A.txt...

blob e427

“HELLO”

브랜치와 머지

13년 10월 17일 목요일

Page 36: DEVIEW 2013 - Git은 어떻게 동작하는가

t5

b3

t4

t3

D

E

t2

t1

b2

b1

master HEAD

C

B

A13년 10월 17일 목요일

Page 37: DEVIEW 2013 - Git은 어떻게 동작하는가

t5

b3

t4

t3

D

E

t2

t1

b2

b1

master HEAD

C

B

A

$ git co -b branch-1

branch-1

13년 10월 17일 목요일

Page 38: DEVIEW 2013 - Git은 어떻게 동작하는가

t5

b3

t4

t3

D

E

t2

t1

b2

b1

masterHEAD

C

B

A

$ git co -b branch-1

branch-1

13년 10월 17일 목요일

Page 39: DEVIEW 2013 - Git은 어떻게 동작하는가

HEADbranch-1master

t5

b3

t4

t3

D

E

t2

t1

b2

b1

C

B

A

Fb2 t2

$ git commit

13년 10월 17일 목요일

Page 40: DEVIEW 2013 - Git은 어떻게 동작하는가

branch-1$ git commit

HEAD

mastert5

b3

t4

t3

D

E

t2

t1

b2

b1

C

B

A

Fb2 t2

13년 10월 17일 목요일

Page 41: DEVIEW 2013 - Git은 어떻게 동작하는가

branch-1$ git co master

HEAD

mastert5

b3

t4

t3

D

E

t2

t1

b2

b1

C

B

A

Fb2 t2

13년 10월 17일 목요일

Page 42: DEVIEW 2013 - Git은 어떻게 동작하는가

branch-1$ git co master

HEADmastert5

b3

t4

t3

D

E

t2

t1

b2

b1

C

B

A

Fb2 t2

13년 10월 17일 목요일

Page 43: DEVIEW 2013 - Git은 어떻게 동작하는가

$ git merge branch-1

HEADmaster

branch-1

t5

b3

t4

t3

D

E

t2

t1

b2

b1

C

B

A

Fb2 t2

상황1: 머지할 브랜치가 현재 브랜치의 모든 커밋을 포함함

13년 10월 17일 목요일

Page 44: DEVIEW 2013 - Git은 어떻게 동작하는가

master HEAD

$ git merge branch-1

branch-1

t5

b3

t4

t3

D

E

t2

t1

b2

b1

C

B

A

Fb2 t2

Fast-Forward

13년 10월 17일 목요일

Page 45: DEVIEW 2013 - Git은 어떻게 동작하는가

F

t5

b3

t4

t3

D

E

t2b2

master HEAD

C

B

b6 t6 G t7 b7

branch-1

$ git merge branch-1

상황2: 머지할 브랜치가 현재 브랜치의 모든 커밋을 포함하

지는 않음

13년 10월 17일 목요일

Page 46: DEVIEW 2013 - Git은 어떻게 동작하는가

F

t5

b3

t4

t3

D

E

t2b2

master HEAD

C

B

b6 t6 G t7 b7

branch-1

$ git merge branch-1

상황2: 머지할 브랜치가 현재 브랜치의 모든 커밋을 포함하

지는 않음

13년 10월 17일 목요일

Page 47: DEVIEW 2013 - Git은 어떻게 동작하는가

F

t5

b3

t4

t3

D

E

t2b2

C

B

b6 t6 G

Hb8 t8

t7 b7

branch-1

$ git merge branch-1

F와 G의 공통조상

E..F와 E..G를 머지

master HEAD

13년 10월 17일 목요일

Page 48: DEVIEW 2013 - Git은 어떻게 동작하는가

F

t5

b3

t4

t3

D

E

t2b2

master HEAD

C

B

b6 t6 G

Hb8 t8

t7 b7

branch-1

$ git merge branch-1

F와 G의 공통조상

E..F와 E..G를 머지

13년 10월 17일 목요일

Page 49: DEVIEW 2013 - Git은 어떻게 동작하는가

F

t5

b3

t4

t3

D

E

t2b2

C

B

b6 t6 G t7 b7

branch-1 master HEAD

prune

13년 10월 17일 목요일

Page 50: DEVIEW 2013 - Git은 어떻게 동작하는가

F

t5

b3

t4

t3

D

E

t2b2

master

C

B

b6 t6 G t7 b7

F’b8 t8

$ git rebase master

branch-1HEAD

13년 10월 17일 목요일

Page 51: DEVIEW 2013 - Git은 어떻게 동작하는가

F

t5

b3

t4

t3

D

E

t2b2

master

C

B

b6 t6 G t7 b7

branch-1

F’b8 t8

$ git rebase master

HEAD

13년 10월 17일 목요일

Page 52: DEVIEW 2013 - Git은 어떻게 동작하는가

F

t5

b3

t4

t3

D

E

t2b2

master

C

B

b6 t6 G t7 b7

branch-1

F’b8 t8

HEAD

$ git reflog expire --all --expire=0$ git prune

13년 10월 17일 목요일

Page 53: DEVIEW 2013 - Git은 어떻게 동작하는가

$ git reflog expire --all --expire=0

F

b3

D

E

b2

b1

master

C

B

b6 G b7

branch-1

F’b8HEAD

$ git prune

A

13년 10월 17일 목요일

Page 54: DEVIEW 2013 - Git은 어떻게 동작하는가

b3

D

E

b2

b1

master

C

B

G b7

branch-1

F’b8HEAD

A

$ git reflog expire --all --expire=0$ git prune

13년 10월 17일 목요일

Page 55: DEVIEW 2013 - Git은 어떻게 동작하는가

b3

D

E

b2

b1

master

C

B

G b7

branch-1

F’b8HEAD

A

$ git push origin master:master

b3

D

E

b2

b1

master

C

B

G b7

A

PUSH & PULL

ref를보낸다.

가져온 ref가“완전하도록”필요한

모든 object를보낸다.

13년 10월 17일 목요일

Page 56: DEVIEW 2013 - Git은 어떻게 동작하는가

master

$ git pull origin branch-2:master

Local RemoteFETCH_HEAD

D

E

C

B

G

A

H

F

D

E

master

C

B

G

A

branch-2

H

F

ref를가져온다

가져온 ref가“완전하도록”필요한 모든 object를 가져온다.

13년 10월 17일 목요일

Page 57: DEVIEW 2013 - Git은 어떻게 동작하는가

master

$ git pull origin branch-2:master

Local Remote

FETCH_HEAD

D

E

C

B

G

A

H

F

I

D

E

master

C

B

G

A

branch-2

H

F

13년 10월 17일 목요일

Page 58: DEVIEW 2013 - Git은 어떻게 동작하는가

$ git pull origin branch-2:master

Local Remote

FETCH_HEAD

master

D

E

C

B

G

A

H

F

I

D

E

master

C

B

G

A

branch-2

H

F

13년 10월 17일 목요일

Page 59: DEVIEW 2013 - Git은 어떻게 동작하는가

$ git pull origin branch-2:master

Local Remote

D

E

master

C

B

G

A

branch-2

H’

F

FETCH_HEAD

H’

master

D

E

C

B

G

A

H

F

I

push -f

13년 10월 17일 목요일

Page 60: DEVIEW 2013 - Git은 어떻게 동작하는가

$ git pull origin branch-2:master

Local Remote

D

E

master

C

B

G

A

branch-2

H’

F

J

FETCH_HEAD

H’

master

D

E

C

B

G

A

H

F

I

push -f

13년 10월 17일 목요일

Page 61: DEVIEW 2013 - Git은 어떻게 동작하는가

$ git pull origin branch-2:master

Local Remote

D

E

master

C

B

G

A

branch-2

H’

F

J

FETCH_HEAD

H’

master

D

E

C

B

G

A

H

F

I

push -f

13년 10월 17일 목요일