Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

What the git? - SAP Inside Track Munich 2016

950 views

Published on

Introduction into Git Version Management System
Git graph functionality
Git in the SAP World
abapGit - Open Source ABAP Git solution

Published in: Technology
  • Be the first to comment

What the git? - SAP Inside Track Munich 2016

  1. 1. What the Git? Hendrik Neumann
  2. 2. 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
  3. 3. Version Control
  4. 4. 4 File revision hell… Example1: Example2:  Version Control Systems to the rescue
  5. 5. 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. 6. 6 Local Computer Local version control Version Database File Version 3 Version 2 Version 1 Checkout
  7. 7. 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. 8. 8 Centralized version control Computer A Central VCS Server Version Database File Version 3 Version 2 Version 1 Computer B File
  9. 9. 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. 10. 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. 11. 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. 12. 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. 13. 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
  14. 14. Git internals
  15. 15. 15 Git repository local repository consists of three “trees” maintained by git Working Directory Staging Area .git directory (Repository)
  16. 16. 16 Git repository remote repositories don’t have a working directory Staging Area .git directory (Repository)
  17. 17. 17 Git repository actual files – single checkout of one version of the project Working Directory
  18. 18. 18 Git repository a file that stores the information what will go into the next commit Staging Area
  19. 19. 19 Git repository a.k.a. the INDEX Staging Area
  20. 20. 20 Git repository metadata and object database are stored in the directory .git directory (Repository)
  21. 21. 21 Basic Git workflow git init Working Directory Staging Area .git directory (Repository)
  22. 22. 22 Working Directory Staging Area .git directory (Repository) checkout the project Basic Git workflow git clone
  23. 23. 23 Working Directory Staging Area .git directory (Repository) stage fixes Basic Git workflow git add
  24. 24. 24 Working Directory Staging Area .git directory (Repository) commit Basic Git workflow git commit
  25. 25. 25 Working Directory Staging Area .git directory (Repository) Commit Checkout the project Stage Fixes Basic Git workflow
  26. 26. 26 Git demo fresh initialized git repo Live Demo
  27. 27. 27 Git demo fresh initialized git repo
  28. 28. 28 Git demo stage a file
  29. 29. 29 Git demo modify a stage a file
  30. 30. 30 Git demo commit modified file
  31. 31. 31 Unmodified Modified Staged Stage the file Commit Lifecycle of a file in Git Untracked Edit the file Add the file Remove the file
  32. 32. Working
  33. 33. 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 ∆2File B File C ∆1 ∆2 ∆2
  34. 34. 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 B2File B File C C1 C2 C3 A2A1 B B C2
  35. 35. 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 B2File B File C C1 C2 C3 A2A1 B B C2
  36. 36. 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. 37. 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. 38. 38 Git
  39. 39. 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. 40. 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 92ec298ca9 Git commit
  41. 41. 41 Git commit commits and parents 911e7 5b1d3 cba0a 92ec298ca9 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. 42. 42 Concept of branches
  43. 43. 43 Git branch a branch and its commit history 911e7 5b1d3 cba0a 92ec298ca9 98ca9 Snapchot A 34ac2 Snapchot B f30ab Snapchot C v1.0 master HEAD Tag Pointer to a specific commit
  44. 44. 44 Git branch git branch testing 911e7 5b1d3 cba0a 98ca9 34ac2 f30ab testing master master branch created by git init
  45. 45. 45 Git branch HEAD points to working branch 911e7 5b1d3 cba0a 98ca9 34ac2 f30ab testing master HEAD
  46. 46. 46 Git branch git checkout testing 911e7 5b1d3 cba0a 98ca9 34ac2 f30ab testing master HEAD
  47. 47. 47 Git branch git commit –a –m ‘made a change’ 911e7 5b1d3 cba0a 98ca9 34ac2 f30ab testing master HEAD 87ab2
  48. 48. 48 Git branch git checkout master 911e7 5b1d3 cba0a 98ca9 34ac2 f30ab testing master 87ab2 HEAD
  49. 49. 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. 50. 50 Git branch 911e7 5b1d3 cba0a C0 C1 C2 testing master C3 HEAD Human Readble keys
  51. 51. 51 Git branch commit on master  new branch 911e7 5b1d3 cba0a C0 C1 C2 testing master C3 HEAD C4
  52. 52. 52 Git branche git checkout –b hotfix 911e7 5b1d3 cba0a C0 C1 C2 testing master C3 C4 C5 hotfix
  53. 53. 53 Git merge git checkout master git merge hotfix 911e7 5b1d3 cba0a C0 C1 C2 testing master C3 C4 C5 hotfix
  54. 54. 54 Git merge git branch –d hotfix 911e7 5b1d3 cba0a C0 C1 C2 testing C3 C4 C5 master
  55. 55. 55 Got merge git checkout master git merge testing 911e7 5b1d3 cba0a C0 C1 C2 testing C3 C4 C5 master
  56. 56. 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. 57. 57 Git merge A merge commit 911e7 5b1d3 cba0a C0 C1 C2 testing C3 C4 C5 master C6
  58. 58. 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. 59. 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. 60. 60 development process use branches for development and merge them back to the master branch upon completion
  61. 61. 61 local / remote workflow Quelle: https://www.git-tower.com/learn/git/ebook/en/command-line/remote-repositories/introduction
  62. 62. Git in the world of SAP
  63. 63. 63 SAP HCP
  64. 64. 64 SAP HCP
  65. 65. 65 SAP WebIDE
  66. 66. 66 SAP WebIDE
  67. 67. 67  Services  Git Services  Best Practices HCP Git docu
  68. 68. 68 SAP at Github
  69. 69. ABAP and Git
  70. 70. 70 ABAP and Git http://www.abapgit.org https://github.com/larshp
  71. 71. 71 abapGit Live Demo
  72. 72. 72 More food for thought: https://git-scm.com/ https://progit.org/
  73. 73. Thanks Hendrik Neumann h.neumann@reply.de
  74. 74. Backup
  75. 75. git commands
  76. 76. 76 git init create a new repository create a new git repository
  77. 77. 77 master create a new repository “master” is the default name for a starting branch after git init
  78. 78. 78 git clone /path/to/repository checkout a repository create a working copy of a local repository
  79. 79. 79 git clone username@host:/path/to/repository checkout a repository for a remote repository
  80. 80. 80 origin/master create a new repository “origin” is the default name Git gives to the server you cloned from
  81. 81. 81 git add <filename> add & commit propose changes – add to the Index
  82. 82. 82 git commit -m "msg" add & commit commits file to the HEAD – not yet to the remote repo
  83. 83. 83 git push origin master pushing changes send changes from local HEAD to your remote repository
  84. 84. 84 git push origin master pushing changes change master to whatever branch you want to push your changes to
  85. 85. 85 git remote add origin <server> pushing changes connect local repository to a remote server
  86. 86. 86 branching branches are used to develop features isolated from each other
  87. 87. 87 branching the master branch is the "default" branch
  88. 88. 88 branching use branches for development and merge them back to the master branch upon completion
  89. 89. 89 git checkout -b feature_x branching create a new branch named "feature_x" and switch to it
  90. 90. 90 git checkout -b master branching switch back to master
  91. 91. 91 git checkout –d feature_x branching delete branch "feature_x"
  92. 92. 92 git push origin <branch> branching push the branch to your remote repository – make it available for others
  93. 93. 93 update & merge use branches for development and merge them back to the master branch upon completion
  94. 94. 94 git fetch origin update & merge fetches any new work that has been pushed to server (no merge!)
  95. 95. 95 git pull update & merge update local repository to the newest commit – fetch and merge changes
  96. 96. 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. 97. 97 git add <filename> update & merge resolve merge conflicts on file level and add / commit it again
  98. 98. 98 git diff <source_branch> <target_branch> update & merge show differences between branches / create patches
  99. 99. 99 update & merge use branches for development and merge them back to the master branch upon completion
  100. 100. 100 git tag tagging lists tags in alphabetical order
  101. 101. 101 git tag 1.0.0 1b2e1d63ff tagging create new “1.0.0” tag for a commit – referenced by its id
  102. 102. 102 git log log repo history – parameters can change the log output
  103. 103. 103 git log --author=bob log see only the commits of a certain author, e.g. Bob
  104. 104. 104 git log --pretty=oneline log compressed log where each commit is one line
  105. 105. 105 git log --graph --oneline --decorate –all log ASCII art tree of all the branches, decorated with the names of tags and branches
  106. 106. 106 git checkout --<filename> replace local changes replace local changes in working tree with last content in HEAD
  107. 107. 107 git fetch origin update & merge fetches any new work that has been pushed to server (no merge!)
  108. 108. 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
  109. 109. 110 checksums in the .git directory
  110. 110. 111 git log
  111. 111. 112 the .git directory
  112. 112. 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
  113. 113. 114 Working Directory Staging Area .git directory commit pull stage fixes pulling changes get changes from remote repo Remote Repository push

×