SlideShare uma empresa Scribd logo
1 de 91
Git.
From the thorns to the stars.
Сергей Моренец
25 апреля 2013 г.
Agenda
• Versioning and revision systems overview
• Git under the microscope
• Examples
• Q & A
Glossary
• VCS
• SCM
• RCS
Requirements
• Storing content
• Tracking changes to the content
• Distributing the content and history with
collaborators
Lost in selection
Magic pill
SCCS
• First VCS available on any Unix system
• Developed in SNOBOL at Bell Labs in 1972
• Prepared for IBM Systems/370 computers running
OS/360
• Its file format is used in BitKeeper and other VCS
• Introduced repositories and locking mechanism
CVS
• Ancestor of the revision control systems
• First released in 1986 by Dick Grune
• Simple technology with small learning curve
• Useful for sharing and backing up the files
• Tortoise CVS is a de facto client for CVS on Windows
• Introduces merging
• Lifecycle ended in 2008
Apache Subversion
• Created in 2000
• Used to host Apache software products, also
Mono, SourceForge, Google Code
• Most adopted SCM
• Atomic commits
• Maintains versioning for directories, renames, and
file metadata
• Better support for branches and tagging
Centralized VCS
Distributed VCS
Distributed workflow
Git
• Distributed revision control and source code
management system
• Designed and developed by Linus Torvalds for
Linux kernel development
• Based on BitKeeper system
• The development began on April 2005
• Current version 1.8.2
Linus Torvalds
• Swedish-speaking Finnish American
• Chief architect and the project's coordinator of the
Linux kernel
• Names after Linus Pauling and Linus Van Pelt
• Second lieutenant of the Finnish Army
• Winner of Millennium Technology Prize in 2012
• Calls himself egotistical bastard
Git
The information manager
from hell
Git
Global information
TRACKER
Junio Hamano
• Graduated from Tokyo university
• Git coordinator since 2005
• Participated in the Linux development
• Currently Google developer
Design Principles
• Take CVS as an example of what not to do
• Support distributed workflow
• Scaling to thousand developers
• Strong consistency and integrity support
• Free
Features
• Rapid branches and merging
• Distributed development
• Compatibility and emulation
• Performance breakthrough
• Revisions hashing
• Garbage collector
• Packed data storage
Git Repository
• Database containing revisions and history of the
project
• Retains complete copy of entire project
• Maintains object store and index
• Object store contains data files, log files and audit
information
Git Repository
Git Object Types
• Blobs
• Trees
• Commits
• Tags
Blobs
• Each version of a file is represented as a blob.
• Blob internal structure is ignored by Git.
• A blob holds a file’s data but does not contain any
metadata about the file or even its name.
• git show command examines contents of the blob
Trees
• A tree object represents one level of directory
information.
• It records blob identifiers and path names for all the
files in one directory.
• It can also recursively reference other sub-trees
objects
• Can be examined by git show or git ls-tree
commands
Commits
• A commit object holds metadata for each change
including the author, commit date, and log
message.
• Each commit points to a tree object that
captures, the state of the repository at the time the
commit was performed.
• git tag stable-1 1b2e1d63ff
Tags
• A tag object assigns an arbitrary yet presumably
human readable name to a specific object, usually
a commit.
• Contains tag type, tag message, author and object
name.
• Can be examined by git cat-file command.
Git Repository
Git Object Model
• Object store is organized and implemented as a
content-addressable storage system.
• Each object has a unique name produced by
applying SHA1 to the contents of the object.
• SHA1 hash is a sufficient index or name for that
object in the object database.
• SHA1 values are 160-bit values that are represented
as a 40-digit hexadecimal number
• 9da581d910c9c4ac93557ca4859e767f5caf5169
Advantages
• Git can determine equality of the objects by
comparing names.
• The same content stored in two repositories will
always be stored under the same name.
• Corruptions errors can be detected by checking
that the object's name is still the SHA1 hash of its
contents.
Name Vs Content
• Git stores each version of file not differences
• Path name is separated from file contents
• Object store is based on hashed computation on
file contents, not name
System Index mechanism Data store
Database Indexed Sequential
Access Method
Data records
Unix FS Directories(/path) Blocks of data
Git .git/objects/hash Blob/tree objects
Git Directory
• Stores all Git's history, configuration and meta
information for your project
• There is only one git directory per project
• By default it’s '.git' in the root of your project
Git Directory
• Configuration:
- config
- description
- info/exclude
• Helps configuring local
repository
Git Directory
• Hooks:
-hooks
• Scripts that are run on
certain lifecycle events of
the repository
Git Directory
• Object Database:
-objects
• Default Git object database
• Contains all content or
pointers to local content.
• All objects are immutable
Git Directory
• References:
-refs
• Stores reference pointers for
branches, tags and heads.
• A reference is a pointer to
an object, usually of type
tag or commit.
• References changes as
the repository evolves
Working Directory
• Holds the current checkout of the files
• Files can be removed or replaced by Git as
branches are switching
• Working directory is temporary checkout place
Index
• The index is a temporary and dynamic binary file
that captures a version of the project’s overall
structure
• The project’s state could be represented by a
commit and a tree from any point in the project’s
history
• The index allows a separation between incremental
development steps and the committal of those
changes.
Index
• Staging area between your working directory and
your repository
• With commit data files from index are
committed, not from working directory
• Can be viewed by git status command.
Data flow
Git Usage
• Command-line tool(Git Bash)
• Git GUI
• IDE Plugin(JGit-based)
Git Bash
• Command-line tool
• UNIX-style utility
• Last straw
Git GUI
• MinGW – based
• Former WinGit
• No support
JGit
• Lightweight, pure Java library implementing the Git
• EGit - Eclipse team provider for Git
• NBGit - Git Support for NetBeans
Git Commands
• init
• checkout
• fetch
• pull
• reset
• merge
• log
Git Commands
• add
• commit
• push
• branch
• tag
First steps
• Clone repository
• Initialize repository
Clone Repository
• git clone git://git.kernel.org/pub/scm/git/git.git
• git clone http://www.kernel.org/pub/scm/git/git.git
Branching
• Branch is graph of commits
• Master branch is created by default
• HEAD is pointer to the current branch
• “git branch test” creates branch test.
• “git checkout master” switches to branch master.
• “git merge test” merges changes from test to
master.
• Merges are done automatically.
Conflicts
• If conflict cannot be resolved index and working
tree are left in the special state
• “git status” shows unmerged files with conflict
markers
• git add file.txt
• git commit
Roll Back
• Reset
• Checkout
• Revert
Reset
• git reset --hard HEAD
• git reset --hard ORIG_HEAD
Checkout
• git checkout HEAD MyClass.java
Revert
• Rollbacks the last commit(s) in the repository
• git revert HEAD
• git revert HEAD~1 –m 2
Git References
• All references are named with a slash-separated
path name starting with "refs“.
• -The branch "test" is short for "refs/heads/test".
• The tag "v1.0" is short for "refs/tags/v1.0".
• "origin/master" is short for
“refs/remotes/origin/master"
Git References
• The HEAD file is a symbolic reference to the branch
we are currently using
• git symbolic-ref HEAD
• ref: refs/heads/master
Advanced Git
Branching strategy
• master
• develop
Branching strategy
• origin/master contains
production-ready code
• origin/develop contains
development changes
Branching strategy
• Feature branches
• Release branches
• Hotfix branches
Feature Branches
• Feature branches (or topic branches) are used to
store new features
• Can be added to develop or
disregarded
• git checkout –b newfeature develop
Release Branches
• Release branches support preparation of a new
production release
Hotfix branches
• Hotfix branches are related to new production
release.
• Created in response to critical bugs in a production
environment.
• Separates developing of the
current version and hotfix.
Branching strategy
Rebasing
• git checkout -b mywork origin
• git commit
• git commit
Rebasing
Rebasing
• git merge origin
Rebasing
• git checkout mywork
• git rebase origin
Rebasing
Stashing
• git stash save “Stashing reason“
• …
• git stash apply
Treeishes
• 980e3ccdaac54a0d4de358f3fe5d718027d96aae
• 980e3ccdaac54a0d4
• 980e3cc
Treeishes
• 980e3ccdaac54a0d4de358f3fe5d718027d96aae
• origin/master
• refs/remotes/origin/master
• master
• refs/heads/master
• v1.0
• refs/tags/v1.0
Issues search
• git bisect start
• git bisect good v1.0
• git bisect bad master
• git bisect bad
• git show
• git bisect reset
Blamestorming
• git blame sha1_file.c
• 0fcfd160 (Linus Torvalds 2005-04-18 8) */
• 0fcfd160 (Linus Torvalds 2005-04-18 9) #include
"cache.h"
• 1f688557 (Junio C Hamano 2005-06-27 10) #include
"delta.h"
• a733cb60 (Linus Torvalds 2005-06-28 11) #include
"pack.h"
Git Hooks
• Scripts placed in $GIT_DIR/hooks directory to trigger
action at certain points
• pre-commit
• commit-msg
• post-commit
• post-checkout
• post-merge
Object Store
• All objects are stored as compressed contents by
their SHA-1 values.
• They contain the object type, size and contents in a
gzipped format.
• Loose objects and packed objects.
Loose Objects
• Compressed data stored in a single file on disk
• Every object written to a separate file
• SHA1 ab04d884140f7b0cf8bbf86d6883869f16a46f65
• GIT_DIR/objects/ab/04d884140f7b0cf8bbf86d68838
69f16a46f65
Packed Objects
• Packfile is a format which stores the part that has
changed in the second file
• Uses heuristic algorithm to define files to pack
• git gc packs the data
• git unpack-objects converts data into loose format
Ignoring files
• # Ignore any file named sample.txt.
• sample.txt
• # Ignore Eclipse files
• *.project
• # except my.project with manual setting.
• !my.project
• # Ignore objects and archives.
• *.[oa]
Scripting
• Ruby
• PHP
• Python
• Perl
Migration
• Script support
• CVS
• SVN
• Perforce
• Mercurial
• fast-support tool
Migration
• git-svn clone http://my-
project.googlecode.com/svn/trunk new-project
• ~/git.git/contrib/fast-import/git-p4 clone
//depot/project/main@all myproject
GitHub
GitHub
• Web-based hosting service
• Was launched in April 2008
• Git repository, paid for private projects and free for
open-source projects
• Run by Ruby on Rails & Erlang
• Provides feeds and followers
Growth
Period State
2009 100000 users and 50000
repositories
2011 1 million users
2012 2 million users and 4 million
repositories
2013 3 million users and 5 million
repositories
Octocat
• Introduced by Tom Preston-Werner, cofounder of
GitHub
• Composed of octopus and cat words
Octocat
Resources
• Version Control with Git, 2nd Edition, 2012
• Pro Git, 2009
Pros
• Painless branching
• Separation between local repository and upstream
• Simplifies work in the distributed teams
• Dramatic increase in performance
• Integration with major VCS
Cons
• Repository security risks
• Latest revision question
• Pessimistic locks
• Big learning curve
• Commit identifiers
• Not optimal for single developers
Q&A
• Сергей Моренец, morenets@mail.ru

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
 
Geb Best Practices
Geb Best PracticesGeb Best Practices
Geb Best Practices
 
Grails 3.0 Preview
Grails 3.0 PreviewGrails 3.0 Preview
Grails 3.0 Preview
 
Javantura v4 - Support SpringBoot application development lifecycle using Ora...
Javantura v4 - Support SpringBoot application development lifecycle using Ora...Javantura v4 - Support SpringBoot application development lifecycle using Ora...
Javantura v4 - Support SpringBoot application development lifecycle using Ora...
 
Make It Cooler: Using Decentralized Version Control
Make It Cooler: Using Decentralized Version ControlMake It Cooler: Using Decentralized Version Control
Make It Cooler: Using Decentralized Version Control
 
Javantura v4 - CroDuke Indy and the Kingdom of Java Skills - Branko Mihaljevi...
Javantura v4 - CroDuke Indy and the Kingdom of Java Skills - Branko Mihaljevi...Javantura v4 - CroDuke Indy and the Kingdom of Java Skills - Branko Mihaljevi...
Javantura v4 - CroDuke Indy and the Kingdom of Java Skills - Branko Mihaljevi...
 
Java 9 Functionality and Tooling
Java 9 Functionality and ToolingJava 9 Functionality and Tooling
Java 9 Functionality and Tooling
 
Introduction to Git for developers
Introduction to Git for developersIntroduction to Git for developers
Introduction to Git for developers
 
Database Migrations with Gradle and Liquibase
Database Migrations with Gradle and LiquibaseDatabase Migrations with Gradle and Liquibase
Database Migrations with Gradle and Liquibase
 
Refactoring to Java 8 (QCon New York)
Refactoring to Java 8 (QCon New York)Refactoring to Java 8 (QCon New York)
Refactoring to Java 8 (QCon New York)
 
Javantura v4 - The power of cloud in professional services company - Ivan Krn...
Javantura v4 - The power of cloud in professional services company - Ivan Krn...Javantura v4 - The power of cloud in professional services company - Ivan Krn...
Javantura v4 - The power of cloud in professional services company - Ivan Krn...
 
Real World Java 9
Real World Java 9Real World Java 9
Real World Java 9
 
Development with JavaFX 9 in JDK 9.0.1
Development with JavaFX 9 in JDK 9.0.1Development with JavaFX 9 in JDK 9.0.1
Development with JavaFX 9 in JDK 9.0.1
 
Jenkins
JenkinsJenkins
Jenkins
 
Real World Java 9
Real World Java 9Real World Java 9
Real World Java 9
 
The do's and don'ts with java 9 (Devoxx 2017)
The do's and don'ts with java 9 (Devoxx 2017)The do's and don'ts with java 9 (Devoxx 2017)
The do's and don'ts with java 9 (Devoxx 2017)
 
Continuous Deployment into the Unknown with Artifactory, Bintray, Docker and ...
Continuous Deployment into the Unknown with Artifactory, Bintray, Docker and ...Continuous Deployment into the Unknown with Artifactory, Bintray, Docker and ...
Continuous Deployment into the Unknown with Artifactory, Bintray, Docker and ...
 
Play 2 Java Framework with TDD
Play 2 Java Framework with TDDPlay 2 Java Framework with TDD
Play 2 Java Framework with TDD
 
Real World Java 9
Real World Java 9Real World Java 9
Real World Java 9
 
Javantura v4 - Angular2 - Ionic2 - from birth to stable versions - Hrvoje Pek...
Javantura v4 - Angular2 - Ionic2 - from birth to stable versions - Hrvoje Pek...Javantura v4 - Angular2 - Ionic2 - from birth to stable versions - Hrvoje Pek...
Javantura v4 - Angular2 - Ionic2 - from birth to stable versions - Hrvoje Pek...
 

Destaque

Destaque (15)

Junior,middle,senior?
Junior,middle,senior?Junior,middle,senior?
Junior,middle,senior?
 
Power IS hell - PowerShell for developers
Power IS hell - PowerShell for developersPower IS hell - PowerShell for developers
Power IS hell - PowerShell for developers
 
Effectiveness and code optimization in Java
Effectiveness and code optimization in JavaEffectiveness and code optimization in Java
Effectiveness and code optimization in Java
 
Getting ready to java 8
Getting ready to java 8Getting ready to java 8
Getting ready to java 8
 
JSF 2: Myth of panacea? Magic world of user interfaces
JSF 2: Myth of panacea? Magic world of user interfacesJSF 2: Myth of panacea? Magic world of user interfaces
JSF 2: Myth of panacea? Magic world of user interfaces
 
Java 8 in action.Jinq
Java 8 in action.JinqJava 8 in action.Jinq
Java 8 in action.Jinq
 
Spring Web flow. A little flow of happiness
Spring Web flow. A little flow of happinessSpring Web flow. A little flow of happiness
Spring Web flow. A little flow of happiness
 
Spring Boot. Boot up your development
Spring Boot. Boot up your developmentSpring Boot. Boot up your development
Spring Boot. Boot up your development
 
Spring Web Flow. A little flow of happiness.
Spring Web Flow. A little flow of happiness.Spring Web Flow. A little flow of happiness.
Spring Web Flow. A little flow of happiness.
 
Serialization and performance in Java
Serialization and performance in JavaSerialization and performance in Java
Serialization and performance in Java
 
Spring Boot. Boot up your development. JEEConf 2015
Spring Boot. Boot up your development. JEEConf 2015Spring Boot. Boot up your development. JEEConf 2015
Spring Boot. Boot up your development. JEEConf 2015
 
Spring.Boot up your development
Spring.Boot up your developmentSpring.Boot up your development
Spring.Boot up your development
 
Gradle
GradleGradle
Gradle
 
An Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersAn Introduction to Gradle for Java Developers
An Introduction to Gradle for Java Developers
 
JEEConf 2016. Effectiveness and code optimization in Java applications
JEEConf 2016. Effectiveness and code optimization in  Java applicationsJEEConf 2016. Effectiveness and code optimization in  Java applications
JEEConf 2016. Effectiveness and code optimization in Java applications
 

Semelhante a Git.From thorns to the stars

Semelhante a Git.From thorns to the stars (20)

Git
GitGit
Git
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Git for folk who like GUIs
Git for folk who like GUIsGit for folk who like GUIs
Git for folk who like GUIs
 
Introduction to Git for Network Engineers
Introduction to Git for Network EngineersIntroduction to Git for Network Engineers
Introduction to Git for Network Engineers
 
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
Embedded Systems: Lecture 10: Introduction to Git & GitHub (Part 1)
 
Source Control Using Git
Source Control Using Git Source Control Using Git
Source Control Using Git
 
Learn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levelsLearn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levels
 
Git
GitGit
Git
 
Git Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Git Is A State Of Mind - The path to becoming a Master of the mystic art of GitGit Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Git Is A State Of Mind - The path to becoming a Master of the mystic art of Git
 
Git Real
Git RealGit Real
Git Real
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
The Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHubThe Basics of Open Source Collaboration With Git and GitHub
The Basics of Open Source Collaboration With Git and GitHub
 
Data science Git management
Data science Git managementData science Git management
Data science Git management
 
Managing Changes to the Database Across the Project Life Cycle (presented by ...
Managing Changes to the Database Across the Project Life Cycle (presented by ...Managing Changes to the Database Across the Project Life Cycle (presented by ...
Managing Changes to the Database Across the Project Life Cycle (presented by ...
 
Managing changes to eZPublish Database
Managing changes to eZPublish DatabaseManaging changes to eZPublish Database
Managing changes to eZPublish Database
 
Que nos espera a los ALM Dudes para el 2013?
Que nos espera a los ALM Dudes para el 2013?Que nos espera a los ALM Dudes para el 2013?
Que nos espera a los ALM Dudes para el 2013?
 
GIT INTRODUCTION
GIT INTRODUCTIONGIT INTRODUCTION
GIT INTRODUCTION
 
Mini git tutorial
Mini git tutorialMini git tutorial
Mini git tutorial
 
git and github-1.pptx
git and github-1.pptxgit and github-1.pptx
git and github-1.pptx
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Último (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Git.From thorns to the stars

  • 1. Git. From the thorns to the stars. Сергей Моренец 25 апреля 2013 г.
  • 2. Agenda • Versioning and revision systems overview • Git under the microscope • Examples • Q & A
  • 4. Requirements • Storing content • Tracking changes to the content • Distributing the content and history with collaborators
  • 7. SCCS • First VCS available on any Unix system • Developed in SNOBOL at Bell Labs in 1972 • Prepared for IBM Systems/370 computers running OS/360 • Its file format is used in BitKeeper and other VCS • Introduced repositories and locking mechanism
  • 8. CVS • Ancestor of the revision control systems • First released in 1986 by Dick Grune • Simple technology with small learning curve • Useful for sharing and backing up the files • Tortoise CVS is a de facto client for CVS on Windows • Introduces merging • Lifecycle ended in 2008
  • 9. Apache Subversion • Created in 2000 • Used to host Apache software products, also Mono, SourceForge, Google Code • Most adopted SCM • Atomic commits • Maintains versioning for directories, renames, and file metadata • Better support for branches and tagging
  • 13.
  • 14. Git • Distributed revision control and source code management system • Designed and developed by Linus Torvalds for Linux kernel development • Based on BitKeeper system • The development began on April 2005 • Current version 1.8.2
  • 15. Linus Torvalds • Swedish-speaking Finnish American • Chief architect and the project's coordinator of the Linux kernel • Names after Linus Pauling and Linus Van Pelt • Second lieutenant of the Finnish Army • Winner of Millennium Technology Prize in 2012 • Calls himself egotistical bastard
  • 18. Junio Hamano • Graduated from Tokyo university • Git coordinator since 2005 • Participated in the Linux development • Currently Google developer
  • 19. Design Principles • Take CVS as an example of what not to do • Support distributed workflow • Scaling to thousand developers • Strong consistency and integrity support • Free
  • 20. Features • Rapid branches and merging • Distributed development • Compatibility and emulation • Performance breakthrough • Revisions hashing • Garbage collector • Packed data storage
  • 21. Git Repository • Database containing revisions and history of the project • Retains complete copy of entire project • Maintains object store and index • Object store contains data files, log files and audit information
  • 23. Git Object Types • Blobs • Trees • Commits • Tags
  • 24. Blobs • Each version of a file is represented as a blob. • Blob internal structure is ignored by Git. • A blob holds a file’s data but does not contain any metadata about the file or even its name. • git show command examines contents of the blob
  • 25. Trees • A tree object represents one level of directory information. • It records blob identifiers and path names for all the files in one directory. • It can also recursively reference other sub-trees objects • Can be examined by git show or git ls-tree commands
  • 26. Commits • A commit object holds metadata for each change including the author, commit date, and log message. • Each commit points to a tree object that captures, the state of the repository at the time the commit was performed. • git tag stable-1 1b2e1d63ff
  • 27. Tags • A tag object assigns an arbitrary yet presumably human readable name to a specific object, usually a commit. • Contains tag type, tag message, author and object name. • Can be examined by git cat-file command.
  • 29. Git Object Model • Object store is organized and implemented as a content-addressable storage system. • Each object has a unique name produced by applying SHA1 to the contents of the object. • SHA1 hash is a sufficient index or name for that object in the object database. • SHA1 values are 160-bit values that are represented as a 40-digit hexadecimal number • 9da581d910c9c4ac93557ca4859e767f5caf5169
  • 30. Advantages • Git can determine equality of the objects by comparing names. • The same content stored in two repositories will always be stored under the same name. • Corruptions errors can be detected by checking that the object's name is still the SHA1 hash of its contents.
  • 31. Name Vs Content • Git stores each version of file not differences • Path name is separated from file contents • Object store is based on hashed computation on file contents, not name System Index mechanism Data store Database Indexed Sequential Access Method Data records Unix FS Directories(/path) Blocks of data Git .git/objects/hash Blob/tree objects
  • 32. Git Directory • Stores all Git's history, configuration and meta information for your project • There is only one git directory per project • By default it’s '.git' in the root of your project
  • 33. Git Directory • Configuration: - config - description - info/exclude • Helps configuring local repository
  • 34. Git Directory • Hooks: -hooks • Scripts that are run on certain lifecycle events of the repository
  • 35. Git Directory • Object Database: -objects • Default Git object database • Contains all content or pointers to local content. • All objects are immutable
  • 36. Git Directory • References: -refs • Stores reference pointers for branches, tags and heads. • A reference is a pointer to an object, usually of type tag or commit. • References changes as the repository evolves
  • 37. Working Directory • Holds the current checkout of the files • Files can be removed or replaced by Git as branches are switching • Working directory is temporary checkout place
  • 38. Index • The index is a temporary and dynamic binary file that captures a version of the project’s overall structure • The project’s state could be represented by a commit and a tree from any point in the project’s history • The index allows a separation between incremental development steps and the committal of those changes.
  • 39. Index • Staging area between your working directory and your repository • With commit data files from index are committed, not from working directory • Can be viewed by git status command.
  • 41. Git Usage • Command-line tool(Git Bash) • Git GUI • IDE Plugin(JGit-based)
  • 42. Git Bash • Command-line tool • UNIX-style utility • Last straw
  • 43. Git GUI • MinGW – based • Former WinGit • No support
  • 44. JGit • Lightweight, pure Java library implementing the Git • EGit - Eclipse team provider for Git • NBGit - Git Support for NetBeans
  • 45. Git Commands • init • checkout • fetch • pull • reset • merge • log
  • 46. Git Commands • add • commit • push • branch • tag
  • 47. First steps • Clone repository • Initialize repository
  • 48. Clone Repository • git clone git://git.kernel.org/pub/scm/git/git.git • git clone http://www.kernel.org/pub/scm/git/git.git
  • 49. Branching • Branch is graph of commits • Master branch is created by default • HEAD is pointer to the current branch • “git branch test” creates branch test. • “git checkout master” switches to branch master. • “git merge test” merges changes from test to master. • Merges are done automatically.
  • 50. Conflicts • If conflict cannot be resolved index and working tree are left in the special state • “git status” shows unmerged files with conflict markers • git add file.txt • git commit
  • 51. Roll Back • Reset • Checkout • Revert
  • 52. Reset • git reset --hard HEAD • git reset --hard ORIG_HEAD
  • 53. Checkout • git checkout HEAD MyClass.java
  • 54. Revert • Rollbacks the last commit(s) in the repository • git revert HEAD • git revert HEAD~1 –m 2
  • 55. Git References • All references are named with a slash-separated path name starting with "refs“. • -The branch "test" is short for "refs/heads/test". • The tag "v1.0" is short for "refs/tags/v1.0". • "origin/master" is short for “refs/remotes/origin/master"
  • 56. Git References • The HEAD file is a symbolic reference to the branch we are currently using • git symbolic-ref HEAD • ref: refs/heads/master
  • 59. Branching strategy • origin/master contains production-ready code • origin/develop contains development changes
  • 60. Branching strategy • Feature branches • Release branches • Hotfix branches
  • 61. Feature Branches • Feature branches (or topic branches) are used to store new features • Can be added to develop or disregarded • git checkout –b newfeature develop
  • 62. Release Branches • Release branches support preparation of a new production release
  • 63. Hotfix branches • Hotfix branches are related to new production release. • Created in response to critical bugs in a production environment. • Separates developing of the current version and hotfix.
  • 65. Rebasing • git checkout -b mywork origin • git commit • git commit
  • 68. Rebasing • git checkout mywork • git rebase origin
  • 70. Stashing • git stash save “Stashing reason“ • … • git stash apply
  • 72. Treeishes • 980e3ccdaac54a0d4de358f3fe5d718027d96aae • origin/master • refs/remotes/origin/master • master • refs/heads/master • v1.0 • refs/tags/v1.0
  • 73. Issues search • git bisect start • git bisect good v1.0 • git bisect bad master • git bisect bad • git show • git bisect reset
  • 74. Blamestorming • git blame sha1_file.c • 0fcfd160 (Linus Torvalds 2005-04-18 8) */ • 0fcfd160 (Linus Torvalds 2005-04-18 9) #include "cache.h" • 1f688557 (Junio C Hamano 2005-06-27 10) #include "delta.h" • a733cb60 (Linus Torvalds 2005-06-28 11) #include "pack.h"
  • 75. Git Hooks • Scripts placed in $GIT_DIR/hooks directory to trigger action at certain points • pre-commit • commit-msg • post-commit • post-checkout • post-merge
  • 76. Object Store • All objects are stored as compressed contents by their SHA-1 values. • They contain the object type, size and contents in a gzipped format. • Loose objects and packed objects.
  • 77. Loose Objects • Compressed data stored in a single file on disk • Every object written to a separate file • SHA1 ab04d884140f7b0cf8bbf86d6883869f16a46f65 • GIT_DIR/objects/ab/04d884140f7b0cf8bbf86d68838 69f16a46f65
  • 78. Packed Objects • Packfile is a format which stores the part that has changed in the second file • Uses heuristic algorithm to define files to pack • git gc packs the data • git unpack-objects converts data into loose format
  • 79. Ignoring files • # Ignore any file named sample.txt. • sample.txt • # Ignore Eclipse files • *.project • # except my.project with manual setting. • !my.project • # Ignore objects and archives. • *.[oa]
  • 81. Migration • Script support • CVS • SVN • Perforce • Mercurial • fast-support tool
  • 82. Migration • git-svn clone http://my- project.googlecode.com/svn/trunk new-project • ~/git.git/contrib/fast-import/git-p4 clone //depot/project/main@all myproject
  • 84. GitHub • Web-based hosting service • Was launched in April 2008 • Git repository, paid for private projects and free for open-source projects • Run by Ruby on Rails & Erlang • Provides feeds and followers
  • 85. Growth Period State 2009 100000 users and 50000 repositories 2011 1 million users 2012 2 million users and 4 million repositories 2013 3 million users and 5 million repositories
  • 86. Octocat • Introduced by Tom Preston-Werner, cofounder of GitHub • Composed of octopus and cat words
  • 88. Resources • Version Control with Git, 2nd Edition, 2012 • Pro Git, 2009
  • 89. Pros • Painless branching • Separation between local repository and upstream • Simplifies work in the distributed teams • Dramatic increase in performance • Integration with major VCS
  • 90. Cons • Repository security risks • Latest revision question • Pessimistic locks • Big learning curve • Commit identifiers • Not optimal for single developers