What the git? - SAP Inside Track Munich 2016

Preview:

Citation preview

What the Git?

Hendrik Neumann

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

Version Control

4

File revision hell…

Example1:

Example2:

Version Control Systems to the rescue

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

6

Local Computer

Local version control

Version Database

File Version 3

Version 2

Version 1

Checkout

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

8

Centralized version control

Computer A Central VCS Server

Version Database File

Version 3

Version 2

Version 1

Computer B

File

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

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

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

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

13

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

Git‘s birth

commit e83c5163316f89bfbde7d9ab23ca2e25604af29 Author: Linus Torvalds <torvalds@ppc970.osdl.org> Date: Thu Apr 7 15:13:13 2005 -0700 Initial revision of "git", the information manager from hell

Git internals

15

Git repository

local repository consists of

three “trees” maintained by git

Working

Directory Staging Area

.git directory

(Repository)

16

Git repository

remote repositories don’t have

a working directory

Staging Area .git directory

(Repository)

17

Git repository

actual files – single checkout

of one version of the project

Working

Directory

18

Git repository

a file that stores the information

what will go into the next commit

Staging Area

19

Git repository

a.k.a. the INDEX

Staging Area

20

Git repository

metadata and object database

are stored in the directory

.git directory

(Repository)

21

Basic Git workflow

git init

Working

Directory Staging Area

.git directory

(Repository)

22

Working

Directory Staging Area

.git directory

(Repository)

checkout the project

Basic Git workflow

git clone

23

Working

Directory Staging Area

.git directory

(Repository)

stage fixes

Basic Git workflow

git add

24

Working

Directory Staging Area

.git directory

(Repository)

commit

Basic Git workflow

git commit

25

Working

Directory Staging Area

.git directory

(Repository)

Commit

Checkout the project

Stage Fixes

Basic Git workflow

26

Git demo

fresh initialized git repo

Live Demo

27

Git demo

fresh initialized git repo

28

Git demo

stage a file

29

Git demo

modify a stage a file

30

Git demo

commit modified file

31

Unmodified Modified Staged

Stage the file

Commit

Lifecycle of a file in Git

Untracked

Edit the file

Add the file

Remove the file

Working

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

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

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

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 <torvalds@ppc970.osdl.org> Date: Thu Apr 7 15:13:13 2005 -0700 Initial revision of "git", the information manager from hell

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

38

Git

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

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

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

42

Concept of branches

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

44

Git branch

git branch testing

911e7

5b1d3

cba0a 98ca9 34ac2 f30ab

testing

master

master branch

created by git init

45

Git branch

HEAD points to working branch

911e7

5b1d3

cba0a 98ca9 34ac2 f30ab

testing

master

HEAD

46

Git branch

git checkout testing

911e7

5b1d3

cba0a

98ca9 34ac2 f30ab

testing

master

HEAD

47

Git branch

git commit –a –m ‘made a change’

911e7

5b1d3

cba0a

98ca9 34ac2 f30ab

testing

master

HEAD

87ab2

48

Git branch

git checkout master

911e7

5b1d3

cba0a

98ca9 34ac2 f30ab

testing

master

87ab2

HEAD

49

Git branch

git checkout master

911e7

5b1d3

cba0a

98ca9 34ac2 f30ab

testing

master

87ab2

HEAD Switching branches

changes files in your

working directory!

50

Git branch

911e7

5b1d3

cba0a

C0 C1 C2

testing

master

C3

HEAD

Human Readble keys

51

Git branch

commit on master new branch

911e7

5b1d3

cba0a

C0 C1 C2

testing

master

C3

HEAD

C4

52

Git branche

git checkout –b hotfix

911e7

5b1d3

cba0a

C0 C1 C2

testing

master

C3

C4 C5

hotfix

53

Git merge

git checkout master git merge hotfix

911e7

5b1d3

cba0a

C0 C1 C2

testing

master

C3

C4 C5

hotfix

54

Git merge

git branch –d hotfix

911e7

5b1d3

cba0a

C0 C1 C2

testing

C3

C4 C5

master

55

Got merge

git checkout master git merge testing

911e7

5b1d3

cba0a

C0 C1 C2

testing

C3

C4 C5

master

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

57

Git merge

A merge commit

911e7

5b1d3

cba0a

C0 C1 C2

testing

C3

C4 C5

master

C6

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

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

60

development process

use branches for development

and merge them back to the

master branch upon completion

61

local / remote workflow

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

Git in the world of SAP

63

SAP HCP

64

SAP HCP

65

SAP WebIDE

66

SAP WebIDE

67

Services Git Services Best Practices

HCP Git docu

68

SAP at Github

ABAP and Git

71

abapGit

Live Demo

Thanks

Hendrik Neumann

h.neumann@reply.de

Backup

git commands

76

git init

create a new repository

create a new git repository

77

master

create a new repository

“master” is the default name for a

starting branch after git init

78

git clone /path/to/repository

checkout a repository

create a working copy of a

local repository

79

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

checkout a repository

for a remote repository

80

origin/master

create a new repository

“origin” is the default name Git

gives to the server you cloned from

81

git add <filename>

add & commit

propose changes – add to the

Index

82

git commit -m "msg"

add & commit

commits file to the HEAD – not

yet to the remote repo

83

git push origin master

pushing changes

send changes from local HEAD

to your remote repository

84

git push origin master

pushing changes

change master to whatever

branch you want to push your

changes to

85

git remote add origin <server>

pushing changes

connect local repository to a

remote server

86

branching

branches are used to develop

features isolated from each other

87

branching

the master branch is the

"default" branch

88

branching

use branches for development

and merge them back to the

master branch upon completion

89

git checkout -b feature_x

branching

create a new branch named

"feature_x" and switch to it

90

git checkout -b master

branching

switch back to master

91

git checkout –d feature_x

branching

delete branch "feature_x"

92

git push origin <branch>

branching

push the branch to your remote

repository – make it available for

others

93

update & merge

use branches for development

and merge them back to the

master branch upon completion

94

git fetch origin

update & merge

fetches any new work that has

been pushed to server (no merge!)

95

git pull

update & merge

update local repository to the

newest commit – fetch and merge

changes

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)

97

git add <filename>

update & merge

resolve merge conflicts on file level

and add / commit it again

98

git diff <source_branch> <target_branch>

update & merge

show differences between

branches / create patches

99

update & merge

use branches for development

and merge them back to the

master branch upon completion

100

git tag

tagging

lists tags in alphabetical order

101

git tag 1.0.0 1b2e1d63ff

tagging

create new “1.0.0” tag for a

commit – referenced by its id

102

git log

log

repo history – parameters can

change the log output

103

git log --author=bob

log

see only the commits of a certain

author, e.g. Bob

104

git log --pretty=oneline

log

compressed log where each

commit is one line

105

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

log

ASCII art tree of all the branches,

decorated with the names of tags

and branches

106

git checkout --<filename>

replace local changes

replace local changes in working

tree with last content in HEAD

107

git fetch origin

update & merge

fetches any new work that has

been pushed to server (no merge!)

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

110

checksums in the .git directory

111

git log

112

the .git directory

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

114

Working

Directory Staging Area .git directory

commit

pull

stage fixes

pulling changes

get changes from remote repo

Remote

Repository

push

Recommended