what the git? - sap inside track munich 2016

114
What the Git? Hendrik Neumann

Upload: hendrik-neumann

Post on 12-Jan-2017

310 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: What the git?  - SAP Inside Track Munich 2016

What the Git?

Hendrik Neumann

Page 2: What the git?  - SAP Inside Track Munich 2016

2

What the Git?

Answer in 5 steps:

1. Git and version control

2. Git internals

3. Git working

4. Git in the world of SAP

5. Git and ABAP

Agenda

Page 3: What the git?  - SAP Inside Track Munich 2016

Version Control

Page 4: What the git?  - SAP Inside Track Munich 2016

4

File revision hell…

Example1:

Example2:

Version Control Systems to the rescue

Page 5: What the git?  - SAP Inside Track Munich 2016

5

Version control is a system that records

changes to a file or set of files over time so that

you can recall specific versions later.

Definition

Quelle: ProGit, 2nd edition by Chacon & Straub

Page 6: What the git?  - SAP Inside Track Munich 2016

6

Local Computer

Local version control

Version Database

File Version 3

Version 2

Version 1

Checkout

Page 7: What the git?  - SAP Inside Track Munich 2016

7

Source Code Control System (SCCS)

• early 1970s by M. J. Rochkind

• repository with file locking: check out with/without lock

Revision Control System (RCS)

• early 1980s by Walter F. Tichy

• forward and reverse delta concepts for the efficient storage of

different file revision

Local version control

Page 8: What the git?  - SAP Inside Track Munich 2016

8

Centralized version control

Computer A Central VCS Server

Version Database File

Version 3

Version 2

Version 1

Computer B

File

Page 9: What the git?  - SAP Inside Track Munich 2016

9

Concurrent Version System (CVS)

• 1986 by Dick Grune

• CVS gave each developer write permission in his or her private

working copy

• automatic merge of changes by different developers unless the

same line was changed conflict

Subversion (SVN)

• 2001

• committed changes atomically and had significantly better support

for branches

Centralized version control

Page 10: What the git?  - SAP Inside Track Munich 2016

10

Distributed version control

Server Computer

Version Database

Version 3

Version 2

Version 1 Computer B

Version Database

Version 3

Version 2

Version 1

File

Computer A

Version Database

Version 3

Version 2

Version 1

File

Page 11: What the git?  - SAP Inside Track Munich 2016

11

BitKeeper and Mercurial

• no central repository

• provide each developer with his own

copy

Mercurial and Monotone

• use hash fingerprints to uniquely identify

a file’s content

Distributed version control

Page 12: What the git?  - SAP Inside Track Munich 2016

12

Linux kernel project

• 1991–2002: patches and archived files by email

• 2002: BitKeeper

• 2005: BitKeeper no longer usable free of charge

• April 2005: Linus Torvalds started Git

• Starting April 20 Linux kernel project uses Git (6,7 million lines of code!)

Git has evolved and matured to be

• easy to use

• incredibly fast

• efficient with large projects

• incredible branching system for non-linear development.

The history of Git

Page 13: What the git?  - SAP Inside Track Munich 2016

13

Git became self-hosted on April 7 with this commit:

Git‘s birth

commit e83c5163316f89bfbde7d9ab23ca2e25604af29 Author: Linus Torvalds <[email protected]> Date: Thu Apr 7 15:13:13 2005 -0700 Initial revision of "git", the information manager from hell

Page 14: What the git?  - SAP Inside Track Munich 2016

Git internals

Page 15: What the git?  - SAP Inside Track Munich 2016

15

Git repository

local repository consists of

three “trees” maintained by git

Working

Directory Staging Area

.git directory

(Repository)

Page 16: What the git?  - SAP Inside Track Munich 2016

16

Git repository

remote repositories don’t have

a working directory

Staging Area .git directory

(Repository)

Page 17: What the git?  - SAP Inside Track Munich 2016

17

Git repository

actual files – single checkout

of one version of the project

Working

Directory

Page 18: What the git?  - SAP Inside Track Munich 2016

18

Git repository

a file that stores the information

what will go into the next commit

Staging Area

Page 19: What the git?  - SAP Inside Track Munich 2016

19

Git repository

a.k.a. the INDEX

Staging Area

Page 20: What the git?  - SAP Inside Track Munich 2016

20

Git repository

metadata and object database

are stored in the directory

.git directory

(Repository)

Page 21: What the git?  - SAP Inside Track Munich 2016

21

Basic Git workflow

git init

Working

Directory Staging Area

.git directory

(Repository)

Page 22: What the git?  - SAP Inside Track Munich 2016

22

Working

Directory Staging Area

.git directory

(Repository)

checkout the project

Basic Git workflow

git clone

Page 23: What the git?  - SAP Inside Track Munich 2016

23

Working

Directory Staging Area

.git directory

(Repository)

stage fixes

Basic Git workflow

git add

Page 24: What the git?  - SAP Inside Track Munich 2016

24

Working

Directory Staging Area

.git directory

(Repository)

commit

Basic Git workflow

git commit

Page 25: What the git?  - SAP Inside Track Munich 2016

25

Working

Directory Staging Area

.git directory

(Repository)

Commit

Checkout the project

Stage Fixes

Basic Git workflow

Page 26: What the git?  - SAP Inside Track Munich 2016

26

Git demo

fresh initialized git repo

Live Demo

Page 27: What the git?  - SAP Inside Track Munich 2016

27

Git demo

fresh initialized git repo

Page 28: What the git?  - SAP Inside Track Munich 2016

28

Git demo

stage a file

Page 29: What the git?  - SAP Inside Track Munich 2016

29

Git demo

modify a stage a file

Page 30: What the git?  - SAP Inside Track Munich 2016

30

Git demo

commit modified file

Page 31: What the git?  - SAP Inside Track Munich 2016

31

Unmodified Modified Staged

Stage the file

Commit

Lifecycle of a file in Git

Untracked

Edit the file

Add the file

Remove the file

Page 32: What the git?  - SAP Inside Track Munich 2016

Working

Page 33: What the git?  - SAP Inside Track Munich 2016

33

Classical VCS

Storing data as changes to a base

version of each file

Version 1

File A ∆1

Checkins over time

Version 2 Version 3 Version 4 Version 5

∆2

∆1 ∆2 File B

File C ∆1 ∆2 ∆2

Page 34: What the git?  - SAP Inside Track Munich 2016

34

Git‘s way

Storing data as a snapshots of the

project over time.

Version 1

File A A1

Checkins over time

Version 2 Version 3 Version 4 Version 5

A2

B1 B2 File B

File C C1 C2 C3

A2 A1

B B

C2

Page 35: What the git?  - SAP Inside Track Munich 2016

35

Git‘s way

If a file did not change only a link

to the file is stored

Version 1

File A A1

Checkins over time

Version 2 Version 3 Version 4 Version 5

A2

B1 B2 File B

File C C1 C2 C3

A2 A1

B B

C2

Page 36: What the git?  - SAP Inside Track Munich 2016

36

• Everything in Git is check-summed before it is stored

• Checksum used for reference Integrity!

• All objects are stored compressed in the Git Object Database and

referenced by the SHA-1 value of its contents (plus a small header)

SHA-1 References

commit e83c5163316f89bfbde7d9ab23ca2e25604af29 Author: Linus Torvalds <[email protected]> Date: Thu Apr 7 15:13:13 2005 -0700 Initial revision of "git", the information manager from hell

Page 37: What the git?  - SAP Inside Track Munich 2016

37

• Everything in Git is check-summed before it is stored

• Checksum used for reference Integrity!

• All objects are stored compressed in the Git Object Database and

referenced by the SHA-1 value of its contents (plus a small header)

• SHA-1 hash: 40-character hexadecimal string: 24b9da6552252987aa493b52f8696cd6d3b00373

SHA-1 References

Page 38: What the git?  - SAP Inside Track Munich 2016

38

Git

Page 39: What the git?  - SAP Inside Track Munich 2016

39

git add README hello.abap LICENSE

git commit -m “Initial commit”

Git commit

• One commit with pointer to the tree and

the commit metadata

• One tree: commited content & which files

are stored in which blob

• Three blobs for the content of each file

Page 40: What the git?  - SAP Inside Track Munich 2016

40

a commit and its tree

commit

tree: 92ec2

author: Hendrik

commiter: Hendrik «Initial commit»

tree

blob: 5b1d3 README

blob: 911e7 hello.abap

blob: cba0a LICENSE

blob

Hello Munich! This is

a README file for the

project….

blob

REPORT ‘Hello’.

WRITE ‘Hello sitMUC’.

blob

BPL Agreement

Beer Public License..

911e7

5b1d3

cba0a

92ec2 98ca9

Git commit

Page 41: What the git?  - SAP Inside Track Munich 2016

41

Git commit

commits and parents

911e7

5b1d3

cba0a

92ec2 98ca9

commit

tree: 92ec2

parent:

author: Hendrik

commiter: Hendrik Initial commit

Snapshot A

commit

tree: 184ca

parent: 98ca9

author: Hendrik

commiter: Hendrik Bug fix #4711

Snapshot B

commit

tree: 0de24

parent: 34ac2

author: Hendrik

commiter: Hendrik Feature request #007

Snapshot C

98ca9 34ac2 f30ab

Page 42: What the git?  - SAP Inside Track Munich 2016

42

Concept of branches

Page 43: What the git?  - SAP Inside Track Munich 2016

43

Git branch

a branch and its commit history

911e7

5b1d3

cba0a

92ec2 98ca9

98ca9

Snapchot A

34ac2

Snapchot B

f30ab

Snapchot C

v1.0 master

HEAD Tag

Pointer to a specific commit

Page 44: What the git?  - SAP Inside Track Munich 2016

44

Git branch

git branch testing

911e7

5b1d3

cba0a 98ca9 34ac2 f30ab

testing

master

master branch

created by git init

Page 45: What the git?  - SAP Inside Track Munich 2016

45

Git branch

HEAD points to working branch

911e7

5b1d3

cba0a 98ca9 34ac2 f30ab

testing

master

HEAD

Page 46: What the git?  - SAP Inside Track Munich 2016

46

Git branch

git checkout testing

911e7

5b1d3

cba0a

98ca9 34ac2 f30ab

testing

master

HEAD

Page 47: What the git?  - SAP Inside Track Munich 2016

47

Git branch

git commit –a –m ‘made a change’

911e7

5b1d3

cba0a

98ca9 34ac2 f30ab

testing

master

HEAD

87ab2

Page 48: What the git?  - SAP Inside Track Munich 2016

48

Git branch

git checkout master

911e7

5b1d3

cba0a

98ca9 34ac2 f30ab

testing

master

87ab2

HEAD

Page 49: What the git?  - SAP Inside Track Munich 2016

49

Git branch

git checkout master

911e7

5b1d3

cba0a

98ca9 34ac2 f30ab

testing

master

87ab2

HEAD Switching branches

changes files in your

working directory!

Page 50: What the git?  - SAP Inside Track Munich 2016

50

Git branch

911e7

5b1d3

cba0a

C0 C1 C2

testing

master

C3

HEAD

Human Readble keys

Page 51: What the git?  - SAP Inside Track Munich 2016

51

Git branch

commit on master new branch

911e7

5b1d3

cba0a

C0 C1 C2

testing

master

C3

HEAD

C4

Page 52: What the git?  - SAP Inside Track Munich 2016

52

Git branche

git checkout –b hotfix

911e7

5b1d3

cba0a

C0 C1 C2

testing

master

C3

C4 C5

hotfix

Page 53: What the git?  - SAP Inside Track Munich 2016

53

Git merge

git checkout master git merge hotfix

911e7

5b1d3

cba0a

C0 C1 C2

testing

master

C3

C4 C5

hotfix

Page 54: What the git?  - SAP Inside Track Munich 2016

54

Git merge

git branch –d hotfix

911e7

5b1d3

cba0a

C0 C1 C2

testing

C3

C4 C5

master

Page 55: What the git?  - SAP Inside Track Munich 2016

55

Got merge

git checkout master git merge testing

911e7

5b1d3

cba0a

C0 C1 C2

testing

C3

C4 C5

master

Page 56: What the git?  - SAP Inside Track Munich 2016

56

Git merge

Three snapshots used in a typical merge

911e7

5b1d3

cba0a

C0 C1 C2

testing

C3

C4 C5

master

Common

Ancestor Snapshot to

Merge Into

Snapshot to

Merg In

Page 57: What the git?  - SAP Inside Track Munich 2016

57

Git merge

A merge commit

911e7

5b1d3

cba0a

C0 C1 C2

testing

C3

C4 C5

master

C6

Page 58: What the git?  - SAP Inside Track Munich 2016

58

Git commit consists of 2 things:

1. pointer to the state of your code at some

moment in time

2. zero or more pointers to „parent“ commits

a Git commit is a node in a graph.

Git repo is one giant graph

Page 59: What the git?  - SAP Inside Track Munich 2016

59

• Everything in Git is check-summed before it is stored

• Checksum used for reference Integrity!

• All objects are stored compressed in the Git Object Database and

referenced by the SHA-1 value of its contents (plus a small header)

• SHA-1 hash: 40-character hexadecimal string: 24b9da6552252987aa493b52f8696cd6d3b00373

Creating a branch is nothing more than just

writing 40 characters to a file

SHA-1 References

Page 60: What the git?  - SAP Inside Track Munich 2016

60

development process

use branches for development

and merge them back to the

master branch upon completion

Page 61: What the git?  - SAP Inside Track Munich 2016

61

local / remote workflow

Quelle: https://www.git-tower.com/learn/git/ebook/en/command-line/remote-repositories/introduction

Page 62: What the git?  - SAP Inside Track Munich 2016

Git in the world of SAP

Page 63: What the git?  - SAP Inside Track Munich 2016

63

SAP HCP

Page 64: What the git?  - SAP Inside Track Munich 2016

64

SAP HCP

Page 65: What the git?  - SAP Inside Track Munich 2016

65

SAP WebIDE

Page 66: What the git?  - SAP Inside Track Munich 2016

66

SAP WebIDE

Page 67: What the git?  - SAP Inside Track Munich 2016

67

Services Git Services Best Practices

HCP Git docu

Page 68: What the git?  - SAP Inside Track Munich 2016

68

SAP at Github

Page 69: What the git?  - SAP Inside Track Munich 2016

ABAP and Git

Page 71: What the git?  - SAP Inside Track Munich 2016

71

abapGit

Live Demo

Page 73: What the git?  - SAP Inside Track Munich 2016

Thanks

Hendrik Neumann

[email protected]

Page 74: What the git?  - SAP Inside Track Munich 2016

Backup

Page 75: What the git?  - SAP Inside Track Munich 2016

git commands

Page 76: What the git?  - SAP Inside Track Munich 2016

76

git init

create a new repository

create a new git repository

Page 77: What the git?  - SAP Inside Track Munich 2016

77

master

create a new repository

“master” is the default name for a

starting branch after git init

Page 78: What the git?  - SAP Inside Track Munich 2016

78

git clone /path/to/repository

checkout a repository

create a working copy of a

local repository

Page 79: What the git?  - SAP Inside Track Munich 2016

79

git clone username@host:/path/to/repository

checkout a repository

for a remote repository

Page 80: What the git?  - SAP Inside Track Munich 2016

80

origin/master

create a new repository

“origin” is the default name Git

gives to the server you cloned from

Page 81: What the git?  - SAP Inside Track Munich 2016

81

git add <filename>

add & commit

propose changes – add to the

Index

Page 82: What the git?  - SAP Inside Track Munich 2016

82

git commit -m "msg"

add & commit

commits file to the HEAD – not

yet to the remote repo

Page 83: What the git?  - SAP Inside Track Munich 2016

83

git push origin master

pushing changes

send changes from local HEAD

to your remote repository

Page 84: What the git?  - SAP Inside Track Munich 2016

84

git push origin master

pushing changes

change master to whatever

branch you want to push your

changes to

Page 85: What the git?  - SAP Inside Track Munich 2016

85

git remote add origin <server>

pushing changes

connect local repository to a

remote server

Page 86: What the git?  - SAP Inside Track Munich 2016

86

branching

branches are used to develop

features isolated from each other

Page 87: What the git?  - SAP Inside Track Munich 2016

87

branching

the master branch is the

"default" branch

Page 88: What the git?  - SAP Inside Track Munich 2016

88

branching

use branches for development

and merge them back to the

master branch upon completion

Page 89: What the git?  - SAP Inside Track Munich 2016

89

git checkout -b feature_x

branching

create a new branch named

"feature_x" and switch to it

Page 90: What the git?  - SAP Inside Track Munich 2016

90

git checkout -b master

branching

switch back to master

Page 91: What the git?  - SAP Inside Track Munich 2016

91

git checkout –d feature_x

branching

delete branch "feature_x"

Page 92: What the git?  - SAP Inside Track Munich 2016

92

git push origin <branch>

branching

push the branch to your remote

repository – make it available for

others

Page 93: What the git?  - SAP Inside Track Munich 2016

93

update & merge

use branches for development

and merge them back to the

master branch upon completion

Page 94: What the git?  - SAP Inside Track Munich 2016

94

git fetch origin

update & merge

fetches any new work that has

been pushed to server (no merge!)

Page 95: What the git?  - SAP Inside Track Munich 2016

95

git pull

update & merge

update local repository to the

newest commit – fetch and merge

changes

Page 96: What the git?  - SAP Inside Track Munich 2016

96

git merge <branch>

update & merge

merge another branch into your

active branch (e.g. master) and

create a new commit (if there are

no conflicts)

Page 97: What the git?  - SAP Inside Track Munich 2016

97

git add <filename>

update & merge

resolve merge conflicts on file level

and add / commit it again

Page 98: What the git?  - SAP Inside Track Munich 2016

98

git diff <source_branch> <target_branch>

update & merge

show differences between

branches / create patches

Page 99: What the git?  - SAP Inside Track Munich 2016

99

update & merge

use branches for development

and merge them back to the

master branch upon completion

Page 100: What the git?  - SAP Inside Track Munich 2016

100

git tag

tagging

lists tags in alphabetical order

Page 101: What the git?  - SAP Inside Track Munich 2016

101

git tag 1.0.0 1b2e1d63ff

tagging

create new “1.0.0” tag for a

commit – referenced by its id

Page 102: What the git?  - SAP Inside Track Munich 2016

102

git log

log

repo history – parameters can

change the log output

Page 103: What the git?  - SAP Inside Track Munich 2016

103

git log --author=bob

log

see only the commits of a certain

author, e.g. Bob

Page 104: What the git?  - SAP Inside Track Munich 2016

104

git log --pretty=oneline

log

compressed log where each

commit is one line

Page 105: What the git?  - SAP Inside Track Munich 2016

105

git log --graph --oneline --decorate –all

log

ASCII art tree of all the branches,

decorated with the names of tags

and branches

Page 106: What the git?  - SAP Inside Track Munich 2016

106

git checkout --<filename>

replace local changes

replace local changes in working

tree with last content in HEAD

Page 107: What the git?  - SAP Inside Track Munich 2016

107

git fetch origin

update & merge

fetches any new work that has

been pushed to server (no merge!)

Page 108: What the git?  - SAP Inside Track Munich 2016

108

git fetch origin git reset --hard origin/master

replace local changes

drop all your local changes and

commits, fetch the latest history

from the server and point local

master branch at it

Page 109: What the git?  - SAP Inside Track Munich 2016
Page 110: What the git?  - SAP Inside Track Munich 2016

110

checksums in the .git directory

Page 111: What the git?  - SAP Inside Track Munich 2016

111

git log

Page 112: What the git?  - SAP Inside Track Munich 2016

112

the .git directory

Page 113: What the git?  - SAP Inside Track Munich 2016

113

Working

Directory Index

(Staging Area)

HEAD (.git directory)

commit

checkout the project

stage fixes

pushing changes

send changes to remote repo

Remote

Repository

push

Page 114: What the git?  - SAP Inside Track Munich 2016

114

Working

Directory Staging Area .git directory

commit

pull

stage fixes

pulling changes

get changes from remote repo

Remote

Repository

push