SlideShare una empresa de Scribd logo
1 de 49
Descargar para leer sin conexión
Git your Life for Fun and Profit!
Cyril Soldani
Geeks Anonymes, Interface, ULg

19th June 2013

1 / 49
Outline

1

Why Version Control?

2

Centralized: Subversion

3

Decentralized: Git

4

Q&A

2 / 49
Outline

1

Why Version Control?
The Versioning Problem
Collaborating with Others (or Self)
Advantages

2

Centralized: Subversion

3

Decentralized: Git

4

Q&A

3 / 49
Finding the Last Version
Real-life example:
Hey, can you send me the source of that article?
Sure, . . . hum, well, . . .
article.tar.bz2
article_final.tar.bz2
article_final2.tar.bz2
article_really_final.tar.bz2
article_last.tar.bz2
article-20081023.tar.bz2

There it is!
No this one is more recent.
Wait, this one even more so.
That should be it.
Wait, was this the last one?
:’(

Poor man’s versioning
Always use dates in archive file names. You can add a short
comment too.
e.g. article-20081023-camera_ready.tar.bz2

4 / 49
Collaborating on a Document
Only one person manages the document
To: pour-doc-owner@ulg.ac.be
On page 1, third paragraph, it misses an s
to kill. At the bottom of page 1, replace
’fucking stupid’ by ’not optimal’. ...

What an exiting hour in perspective!

Each one changes its copy
Here is the corrected document, can you (manually) merge it with
the versions you received from the other 10 participants?

One shared copy
Hey, just saved the doc with my changes on the DropBox ;-)
How nice, you just overwrote my last 4 hours of work! :’(
5 / 49
Collaborating with Oneself

A simple way to shoot oneself in the foot:
1. Take a snapshot archive of current stable version (with date).
2. Begin implementing your crazy experimental idea.
3. Fix some bugs in old code, revealed during testing.
4. Your idea was crap, discard experimental version.
5. Start back from stable version archive.
6. You lost your bug fixes, which also applied to stable version.
One need a way to convey changes (such as bug fixes) across
multiple, different versions.

6 / 49
The Collaboration Problem

From the SVN Book
7 / 49
Locking

From the SVN Book
8 / 49
Why Use Version Control?

Backup and restore
Synchronization
between members of a team;
between multiple versions.

Selective undo
Sandboxing
Track changes
Documentation

9 / 49
Outline

1

Why Version Control?

2

Centralized: Subversion
Centralized Model
Subversion in Practice

3

Decentralized: Git

4

Q&A

10 / 49
Centralized Version Control Model
One central repository, on
a server. Stores the files
and their history.
Many clients, i.e. users
connecting to the repo
Each client has one or more
working copies, i.e. a local
copy of the files, where
changes are made
A revision identifies a point
in time of the repo, it is
denoted by a number.
From the SVN Book

HEAD denotes last revision.

11 / 49
Solution to the Collaboration Problem

From the SVN Book
12 / 49
Solution to the Collaboration Problem (cnt’d)

From the SVN Book
13 / 49
Subversion
Subversion is a popular centralized versioning system
It is free open-source software
It is cross-platform (Linux, FreeBSD, Mac OS X, Windows)
Its functionality is exposed through two commands:
svn allows to manipulate working copies
svnadmin manages repositories
There are also GUIs (e.g. Tortoise SVN) and support for IDEs

Obtaining help
svn help [COMMAND]
List available commands, or describe a command.

14 / 49
Updating your working copy
Obtain a working copy for the first time
This action is called checkout :
svn checkout REPOSITORY_URL DEST_DIR
This creates the local copy folder with additional .svn folders
holding (part of) the history, and subversion settings.

Updating an existing working copy
svn update
Incorporates changes in the repository into the working copy.
Always update your working copy prior to making changes, as
subversion will refuse new changes to out-of-date files.

15 / 49
Making changes
To edit a file, simply open it in your favorite editor (VIM, of
course), and make your changes
To delete, copy or rename a file, use svn

Tree changes
svn add FOO adds FOO to the repo
svn delete FOO removes FOO from the repo
svn copy FOO BAR copies FOO to BAR
svn move FOO BAR moves FOO to BAR
svn mkdir FOO creates and adds folder FOO
Changes on the working copy do not impact the repository
directly

16 / 49
Review your changes
Before sending your changes to the repository, check exactly
what you have changed:
Allows to detect errors
Helps making good log messages

Inspecting the working copy
svn status list the files that have changed since last
update
svn diff FOO shows what has changed in file FOO since
last update
Fix eventual problems, either by modifying a file again, or by
reverting to the version from last update

Reverting changes
svn revert FOO
Restores FOO to whatever it was after last update.
17 / 49
Resolve any conflict
Update your working copy. If some files have changed both in
the repository and in your working copy, there is a conflict
It is your responsibility to fix conflicts, by inspecting the
diverging changes and:
choose your own version, or
choose repository version, or
choose previous version, or
mix both versions

You can fix conflicts interactively during update, or postpone
them for later treatment.

Resolving a postponed conflict
svn resolve --accept STATE FOO
Choose how to resolve the conflict, see svn help resolve

18 / 49
Publish your changes to the repository
Publish your changes to others
This action is called commit:
svn commit
When committing, you give a message indicating what the change
is about, which is consigned in the log file.
Subversion will refuse to commit if you have pending conflicts
If there are new conflicts (the repository could have been
modified since last update), you will need to resolve them
Once the commit is complete, your changes are recorded in
the repository, the revision number is incremented and your
changes become visible to others

19 / 49
Summary

1. Checkout or update your working copy (checkout, update)
2. Make changes (edit, add, copy, delete, . . . )
3. Review your changes (status, diff)
4. Fix your mistakes (edit, revert)
5. Resolve conflicts (update, resolve)
6. Publish your changes (commit)

20 / 49
Examining history
Showing the log
svn log [FOO]
Shows log (relevant to FOO).

Showing differences
svn diff -rA:B FOO
Shows what changed in FOO between revision A and revision B.

Obtain an old version of a file
svn cat -rA FOO > FOO.old
Recover the content of FOO at revision A into FOO.old.

Time traveling
svn update -rA
Make the working copy what the repository was at revision A.
21 / 49
Starting a New Project
Creating the repository
On the server:
svnadmin create REPO
The repository is the subversion database. It cannot be modified
directly (only through working copies).

Importing a project into a repository
svn import DIR REPO_URL

Recommended repository layout
trunk main line of development
branches contains alternative versions
tags contains precise releases
This is only a convention, these folders are not treated specially by
subversion.
22 / 49
Multiple parallel branches

Figure from the SVN Book

23 / 49
Branching
In subversion, a branch is simply a copy:

Branching
svn copy REPO/calc/trunk 
REPO/calc/branches/my-calc-branch
You work on a branch as you would on any other folder
File histories branch too

From the SVN Book
24 / 49
Merging
Merging is synchronizing two branches
When developing a branch, you’ll want to synch with trunk
from time to time

Merging from an ancestor branch
svn merge ˆ/calc/trunk

(when in branch)

When merging, you can encounter conflicts, to be resolved as
before
If you want to integrate a branch back to trunk, you can
merge it back

Merging from a child branch
svn merge --reintegrate 
ˆ/calc/branch/my-calc-branch
When in trunk
25 / 49
What else?

Keyword substitutions (e.g. $Id: . . . $)
Properties (e.g. files to ignore)
Tags
Combining files from multiple repositories
Advanced branch and merge
Repository administration
Server configuration
...

26 / 49
References

Subversion http://subversion.tigris.org/
The SVN Book http://svnbook.red-bean.com/
This presentation is mostly derived from this freely
available book
Tortoise SVN http://tortoisesvn.net/

27 / 49
Outline

1

Why Version Control?

2

Centralized: Subversion

3

Decentralized: Git
Decentralized Model
Git in Practice
Geekiness

4

Q&A

28 / 49
Decentralized Version Control Model

From the Git Book
29 / 49
Decentralized Version Control Pros and Cons
Pros
Every working copy is a full backup of the data
You can work off-line
You can work with several repositories within the same project
You can rewrite (local) history:
You can do microcommits
(You can hide your mistakes and look smarter than you are)

Allows private work, eases experimental jump in
Often faster
Cons
More complex
Less control on project evolution
Less sharing?
30 / 49
Git
Git is an increasingly popular distributed versioning system
It is free open-source software
It is cross-platform (although better support for Linux)
It is very efficient :-)
It is very powerful ;-)
It can be very complex :’(
It has GUIs and IDEs plugins (although less than subversion)
There is no global revision numbers, hashes instead
Hashes may be abbreviated, and revisions may be given
relatively to HEAD (e.g. HEADˆ, HEAD˜4)

Obtaining help
git help [COMMAND]
List available commands, or describe a command.
31 / 49
The Three States

From the Git Book
32 / 49
Updating your working copy
Obtain a working copy for the first time
This action is called clone :
git clone REPOSITORY_URL DEST_DIR
This creates a working copy of the remote repository with a
complete copy of the repository itself in .git.

Updating an existing working copy
git pull [REPO]
Incorporates changes from a remote repo into the current branch.
As before, always update your working copy prior to making
changes.

33 / 49
Making changes

To edit a file, simply open it in your editor, and make your
changes. Then stage your changes with git add.
To delete, copy or rename a file, use git

Tree changes
git add FOO adds FOO to the index
git rm FOO removes FOO
git mv FOO BAR moves FOO to BAR
These changes only impacted the working directory and index
so far, the repository is still untouched.

34 / 49
Review your changes
Before committing changes to the repository, check exactly
what you have changed:
Allows to detect errors
Helps making good log messages

Inspecting the working copy
git status list changes in the working directory and index
git diff FOO shows what has changed in file FOO
compared to index version
git diff --cached FOO shows what has changed in file
FOO compared to repository version
Fix eventual problems, either by modifying a file again, or by
reseting to the version from the repository (or index)

Forgetting changes
git reset FOO
Restores FOO to a previous state.
35 / 49
Publish your changes to the repository

Publish your changes to your own repo
This action is called commit:
git commit
When committing, you give a message indicating what the change
is about, which is consigned in the log file.

Publish your changes to others
git pull [REPO]
Integrates changes from remote repo (this may lead to conflicts).
git push [REPO]
Upload your changes to remote repository.

36 / 49
Resolve any conflict

When you do a git pull (or push), you may get conflicts if
the same files were modified on both your repository and the
remote one.
Conflicting files will contain both versions, with markers
You have to edit the files to merge the changes and remove
the markers
You can then add and commit the result of the merge
If you were trying to pull or push, you can now try again

37 / 49
Summary

1. Checkout or update your working copy and repo (clone, pull)
2. Make changes (edit, add, cp, rm, . . . )
3. Review your changes (status, diff)
4. Fix your mistakes (edit, reset)
5. Stage changes (add)
6. Commit changes (commit)
7. Resolve conflicts (pull, edit, add, commit)
8. Publish your changes (push)

38 / 49
Examining history
Showing the log
git log [FOO]
Shows log (relevant to FOO).

Showing differences
git diff [REV1] [REV2] [FOO]
Shows what changed in FOO between revisions REV1 and REV2.

Obtain an old version of a file
List file hashes in a commit with
git git ls-tree COMMIT_HASH
Then recover file with
git git cat-file blob FOO_HASH > FOO.old

Time traveling
git checkout COMMIT_HASH
39 / 49
Starting a New Project
Creating the repository
In the project directory:
git init
You then need to add and commit files to import them.

Creating and populating a public repository
On the server:
mkdir project.git; cd project.git
git --bare init
On the initial client:
git remote add origin URL
git push origin master
master is the main branch, the equivalent of trunk in SVN
origin is a conventional name for the main remote repository
there is no need for branches or tags folders, git has built-in
support for them
40 / 49
Branching
Creating a new branch
git checkout -b NEW-BRANCH
Creates a new branch and immediately switch to it

Switch to another branch
git checkout BRANCH
Will change the working copy and index to match the given
branch. New changes will now go into that branch.

Checking branches
git show-branch
Will show the different branches and a summary of their last
changes

41 / 49
Merging

Merging from a branch
git merge BRANCH
Reflect changes from given branch into the current branch. This
may lead to conflicts, which you can then fix and commit.

Cherry-picking
Cherry-picking is selective merging.
git cherry-pick COMMIT_HASH
Merges only the single commit identified by its hash.

42 / 49
Other Random Topics
Tags
With git, you can tag a release with
git tag TAG_NAME
This gives a symbolic name to the corresponding hash. You must
push tags explicitly with
git push --tags [REPO]

Undoing things
To cancel changes introduced by a commit, use:
git revert COMMIT_HASH
This will undo the changes in the working copy, you can then
commit the new version.

43 / 49
Other Random Topics (cnt’d)
Ignoring files
Just create a .gitignore file. On each line, the name of a file to
be ignored by git. Those can contain wildcards.
You can have a .gitignore in a subdirectory.

Customizing git
She comes in colors:
git config --global
git config --global
git config --global
git config --global
Setting user info:
git config --global
git config --global

color.status auto
color.branch auto
color.interactive auto
color.diff auto
user.name ’Your Name’
user.email ’you@your.domain’
44 / 49
References

git http://git-scm.com/
The git book http://git-scm.com/book
Freely available book
The git book (fr) http://alx.github.io/gitbook/
Old, incomplete French version

45 / 49
Rewriting history
Have you ever dreamed of rewriting history? Yes, you can!
You can merge microcommits, or mutually cancelling ones,
into a more coherent set of commits, for a nicer log.
Don’t do it just to show off (never did, . . . well, maybe once or
twice)
Never do it if you pushed to a remote repository (or you’ll
seriously mess everything up)

Rewriting history
To reorder/merge/modify/. . . last 10 commits:
git rebase -i HEAD˜10

46 / 49
Giting Your Life
You can also store binary files in a version control system (of
course, merge becomes tougher)
I store my whole /home/soldani directory under git
Fun and useful
I ignore sensitive and cache files
I use multiple repositories to improve performance (git is not
designed for huge and numerous binary files)

mgit
#!/bin/sh
while read dir; do
echo "======== $dir"
cd "$dir"
git $*
done < ~/.mgit
47 / 49
Outline

1

Why Version Control?

2

Centralized: Subversion

3

Decentralized: Git

4

Q&A

48 / 49
Questions and (Possibly) Answers

?
49 / 49

Más contenido relacionado

La actualidad más candente (12)

How to use CVS applied to SOLab
How to use CVS applied to SOLabHow to use CVS applied to SOLab
How to use CVS applied to SOLab
 
Getting Started With Subversion
Getting Started With SubversionGetting Started With Subversion
Getting Started With Subversion
 
Install guide
Install guideInstall guide
Install guide
 
Subversion Overview
Subversion OverviewSubversion Overview
Subversion Overview
 
Introduction to Subversion
Introduction to SubversionIntroduction to Subversion
Introduction to Subversion
 
SVN Usage & Best Practices
SVN Usage & Best PracticesSVN Usage & Best Practices
SVN Usage & Best Practices
 
Subversion Best Practices
Subversion Best PracticesSubversion Best Practices
Subversion Best Practices
 
T-Shell (TCSH)
T-Shell (TCSH)T-Shell (TCSH)
T-Shell (TCSH)
 
Linux week7
Linux week7Linux week7
Linux week7
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Part 4 - Managing your svn repository using jas forge
Part 4  - Managing your svn repository using jas forgePart 4  - Managing your svn repository using jas forge
Part 4 - Managing your svn repository using jas forge
 
Version control
Version controlVersion control
Version control
 

Destacado (7)

Le Cloud ULg-CHU
Le Cloud ULg-CHULe Cloud ULg-CHU
Le Cloud ULg-CHU
 
Open Source Community Management
Open Source Community ManagementOpen Source Community Management
Open Source Community Management
 
When Biology Meets Computer Science
When Biology Meets Computer ScienceWhen Biology Meets Computer Science
When Biology Meets Computer Science
 
Grails, une application web Java en toute simplicité
Grails, une application web Java en toute simplicitéGrails, une application web Java en toute simplicité
Grails, une application web Java en toute simplicité
 
Cappuccino - ou comment créer une application web en 5 minutes
Cappuccino - ou comment créer une application web en 5 minutes Cappuccino - ou comment créer une application web en 5 minutes
Cappuccino - ou comment créer une application web en 5 minutes
 
Mieux programmer grâce aux design patterns
Mieux programmer grâce aux design patternsMieux programmer grâce aux design patterns
Mieux programmer grâce aux design patterns
 
Angular js
Angular jsAngular js
Angular js
 

Similar a Git your life for fun & profit

Subversion
SubversionSubversion
Subversion
rchakra
 
Practical SVN for PHP Developers
Practical SVN for PHP DevelopersPractical SVN for PHP Developers
Practical SVN for PHP Developers
Lorna Mitchell
 
Digital Fabrication Studio 0.3 Information
Digital Fabrication Studio 0.3 InformationDigital Fabrication Studio 0.3 Information
Digital Fabrication Studio 0.3 Information
Massimo Menichinelli
 

Similar a Git your life for fun & profit (20)

Git your life for fun & profit
Git your life for fun & profitGit your life for fun & profit
Git your life for fun & profit
 
SVN Information
SVN Information  SVN Information
SVN Information
 
SVN Tool Information : Best Practices
SVN Tool Information  : Best PracticesSVN Tool Information  : Best Practices
SVN Tool Information : Best Practices
 
Subversion
SubversionSubversion
Subversion
 
Svn workflow
Svn workflowSvn workflow
Svn workflow
 
Subversion on .Unix
Subversion on .UnixSubversion on .Unix
Subversion on .Unix
 
Version Control Training - First Lego League
Version Control Training - First Lego LeagueVersion Control Training - First Lego League
Version Control Training - First Lego League
 
Subversion
SubversionSubversion
Subversion
 
Practical SVN for PHP Developers
Practical SVN for PHP DevelopersPractical SVN for PHP Developers
Practical SVN for PHP Developers
 
Understanding GIT and Version Control
Understanding GIT and Version ControlUnderstanding GIT and Version Control
Understanding GIT and Version Control
 
CS_Note_Introduction to Git Workflow.pdf
CS_Note_Introduction to Git Workflow.pdfCS_Note_Introduction to Git Workflow.pdf
CS_Note_Introduction to Git Workflow.pdf
 
Burlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion PresentationBurlington, VT PHP Users Group Subversion Presentation
Burlington, VT PHP Users Group Subversion Presentation
 
Digital Fabrication Studio.02 _Information @ Aalto Media Factory
Digital Fabrication Studio.02 _Information @ Aalto Media FactoryDigital Fabrication Studio.02 _Information @ Aalto Media Factory
Digital Fabrication Studio.02 _Information @ Aalto Media Factory
 
Subversion User Guide
Subversion User GuideSubversion User Guide
Subversion User Guide
 
Digital Fabrication Studio 0.3 Information
Digital Fabrication Studio 0.3 InformationDigital Fabrication Studio 0.3 Information
Digital Fabrication Studio 0.3 Information
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Subversion
SubversionSubversion
Subversion
 
ClearCase Basics
ClearCase BasicsClearCase Basics
ClearCase Basics
 
Totalsvn Usage And Administration By Gopi
Totalsvn Usage And Administration By GopiTotalsvn Usage And Administration By Gopi
Totalsvn Usage And Administration By Gopi
 
Version control
Version controlVersion control
Version control
 

Más de Geeks Anonymes

Más de Geeks Anonymes (20)

Programmer sous Unreal Engine
Programmer sous Unreal EngineProgrammer sous Unreal Engine
Programmer sous Unreal Engine
 
Implémentation efficace et durable de processus métiers complexes
Implémentation efficace et durable de processus métiers complexesImplémentation efficace et durable de processus métiers complexes
Implémentation efficace et durable de processus métiers complexes
 
Managing Open Source Licenses (Geeks Anonymes)
Managing Open Source Licenses (Geeks Anonymes)Managing Open Source Licenses (Geeks Anonymes)
Managing Open Source Licenses (Geeks Anonymes)
 
Reprendre le contrôle de ses données
Reprendre le contrôle de ses donnéesReprendre le contrôle de ses données
Reprendre le contrôle de ses données
 
Geeks Anonymes - Le langage Go
Geeks Anonymes - Le langage GoGeeks Anonymes - Le langage Go
Geeks Anonymes - Le langage Go
 
Le rôle du testeur et le Blackbox testing
Le rôle du testeur et le Blackbox testingLe rôle du testeur et le Blackbox testing
Le rôle du testeur et le Blackbox testing
 
Kubernetes
KubernetesKubernetes
Kubernetes
 
Vulnérabilités au cœur des applications Web, menaces et contre-mesures
 Vulnérabilités au cœur des applications Web, menaces et contre-mesures Vulnérabilités au cœur des applications Web, menaces et contre-mesures
Vulnérabilités au cœur des applications Web, menaces et contre-mesures
 
191121 philippe teuwen cryptographie et attaques materielles
191121 philippe teuwen cryptographie et attaques materielles191121 philippe teuwen cryptographie et attaques materielles
191121 philippe teuwen cryptographie et attaques materielles
 
"Surfez couverts !" - Conseils de Cyber securité
"Surfez couverts !" - Conseils de Cyber securité "Surfez couverts !" - Conseils de Cyber securité
"Surfez couverts !" - Conseils de Cyber securité
 
Introduction au développement mobile - développer une application iOS et Andr...
Introduction au développement mobile - développer une application iOS et Andr...Introduction au développement mobile - développer une application iOS et Andr...
Introduction au développement mobile - développer une application iOS et Andr...
 
Le langage rust
Le langage rustLe langage rust
Le langage rust
 
Test your code
Test your codeTest your code
Test your code
 
Intelligence artificielle et propriété intellectuelle
Intelligence artificielle et propriété intellectuelleIntelligence artificielle et propriété intellectuelle
Intelligence artificielle et propriété intellectuelle
 
Pour une histoire plophonique du jeu video
Pour une histoire plophonique du jeu videoPour une histoire plophonique du jeu video
Pour une histoire plophonique du jeu video
 
Become Rick and famous, thanks to Open Source
Become Rick and famous, thanks to Open SourceBecome Rick and famous, thanks to Open Source
Become Rick and famous, thanks to Open Source
 
Reconnaissance vocale et création artistique
Reconnaissance vocale et création artistiqueReconnaissance vocale et création artistique
Reconnaissance vocale et création artistique
 
Natural Language Processing
Natural Language ProcessingNatural Language Processing
Natural Language Processing
 
Sécurité, GDPR : vos données ont de la valeur
Sécurité, GDPR : vos données ont de la valeur Sécurité, GDPR : vos données ont de la valeur
Sécurité, GDPR : vos données ont de la valeur
 
Modern sql
Modern sqlModern sql
Modern sql
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 

Git your life for fun & profit

  • 1. Git your Life for Fun and Profit! Cyril Soldani Geeks Anonymes, Interface, ULg 19th June 2013 1 / 49
  • 2. Outline 1 Why Version Control? 2 Centralized: Subversion 3 Decentralized: Git 4 Q&A 2 / 49
  • 3. Outline 1 Why Version Control? The Versioning Problem Collaborating with Others (or Self) Advantages 2 Centralized: Subversion 3 Decentralized: Git 4 Q&A 3 / 49
  • 4. Finding the Last Version Real-life example: Hey, can you send me the source of that article? Sure, . . . hum, well, . . . article.tar.bz2 article_final.tar.bz2 article_final2.tar.bz2 article_really_final.tar.bz2 article_last.tar.bz2 article-20081023.tar.bz2 There it is! No this one is more recent. Wait, this one even more so. That should be it. Wait, was this the last one? :’( Poor man’s versioning Always use dates in archive file names. You can add a short comment too. e.g. article-20081023-camera_ready.tar.bz2 4 / 49
  • 5. Collaborating on a Document Only one person manages the document To: pour-doc-owner@ulg.ac.be On page 1, third paragraph, it misses an s to kill. At the bottom of page 1, replace ’fucking stupid’ by ’not optimal’. ... What an exiting hour in perspective! Each one changes its copy Here is the corrected document, can you (manually) merge it with the versions you received from the other 10 participants? One shared copy Hey, just saved the doc with my changes on the DropBox ;-) How nice, you just overwrote my last 4 hours of work! :’( 5 / 49
  • 6. Collaborating with Oneself A simple way to shoot oneself in the foot: 1. Take a snapshot archive of current stable version (with date). 2. Begin implementing your crazy experimental idea. 3. Fix some bugs in old code, revealed during testing. 4. Your idea was crap, discard experimental version. 5. Start back from stable version archive. 6. You lost your bug fixes, which also applied to stable version. One need a way to convey changes (such as bug fixes) across multiple, different versions. 6 / 49
  • 7. The Collaboration Problem From the SVN Book 7 / 49
  • 8. Locking From the SVN Book 8 / 49
  • 9. Why Use Version Control? Backup and restore Synchronization between members of a team; between multiple versions. Selective undo Sandboxing Track changes Documentation 9 / 49
  • 10. Outline 1 Why Version Control? 2 Centralized: Subversion Centralized Model Subversion in Practice 3 Decentralized: Git 4 Q&A 10 / 49
  • 11. Centralized Version Control Model One central repository, on a server. Stores the files and their history. Many clients, i.e. users connecting to the repo Each client has one or more working copies, i.e. a local copy of the files, where changes are made A revision identifies a point in time of the repo, it is denoted by a number. From the SVN Book HEAD denotes last revision. 11 / 49
  • 12. Solution to the Collaboration Problem From the SVN Book 12 / 49
  • 13. Solution to the Collaboration Problem (cnt’d) From the SVN Book 13 / 49
  • 14. Subversion Subversion is a popular centralized versioning system It is free open-source software It is cross-platform (Linux, FreeBSD, Mac OS X, Windows) Its functionality is exposed through two commands: svn allows to manipulate working copies svnadmin manages repositories There are also GUIs (e.g. Tortoise SVN) and support for IDEs Obtaining help svn help [COMMAND] List available commands, or describe a command. 14 / 49
  • 15. Updating your working copy Obtain a working copy for the first time This action is called checkout : svn checkout REPOSITORY_URL DEST_DIR This creates the local copy folder with additional .svn folders holding (part of) the history, and subversion settings. Updating an existing working copy svn update Incorporates changes in the repository into the working copy. Always update your working copy prior to making changes, as subversion will refuse new changes to out-of-date files. 15 / 49
  • 16. Making changes To edit a file, simply open it in your favorite editor (VIM, of course), and make your changes To delete, copy or rename a file, use svn Tree changes svn add FOO adds FOO to the repo svn delete FOO removes FOO from the repo svn copy FOO BAR copies FOO to BAR svn move FOO BAR moves FOO to BAR svn mkdir FOO creates and adds folder FOO Changes on the working copy do not impact the repository directly 16 / 49
  • 17. Review your changes Before sending your changes to the repository, check exactly what you have changed: Allows to detect errors Helps making good log messages Inspecting the working copy svn status list the files that have changed since last update svn diff FOO shows what has changed in file FOO since last update Fix eventual problems, either by modifying a file again, or by reverting to the version from last update Reverting changes svn revert FOO Restores FOO to whatever it was after last update. 17 / 49
  • 18. Resolve any conflict Update your working copy. If some files have changed both in the repository and in your working copy, there is a conflict It is your responsibility to fix conflicts, by inspecting the diverging changes and: choose your own version, or choose repository version, or choose previous version, or mix both versions You can fix conflicts interactively during update, or postpone them for later treatment. Resolving a postponed conflict svn resolve --accept STATE FOO Choose how to resolve the conflict, see svn help resolve 18 / 49
  • 19. Publish your changes to the repository Publish your changes to others This action is called commit: svn commit When committing, you give a message indicating what the change is about, which is consigned in the log file. Subversion will refuse to commit if you have pending conflicts If there are new conflicts (the repository could have been modified since last update), you will need to resolve them Once the commit is complete, your changes are recorded in the repository, the revision number is incremented and your changes become visible to others 19 / 49
  • 20. Summary 1. Checkout or update your working copy (checkout, update) 2. Make changes (edit, add, copy, delete, . . . ) 3. Review your changes (status, diff) 4. Fix your mistakes (edit, revert) 5. Resolve conflicts (update, resolve) 6. Publish your changes (commit) 20 / 49
  • 21. Examining history Showing the log svn log [FOO] Shows log (relevant to FOO). Showing differences svn diff -rA:B FOO Shows what changed in FOO between revision A and revision B. Obtain an old version of a file svn cat -rA FOO > FOO.old Recover the content of FOO at revision A into FOO.old. Time traveling svn update -rA Make the working copy what the repository was at revision A. 21 / 49
  • 22. Starting a New Project Creating the repository On the server: svnadmin create REPO The repository is the subversion database. It cannot be modified directly (only through working copies). Importing a project into a repository svn import DIR REPO_URL Recommended repository layout trunk main line of development branches contains alternative versions tags contains precise releases This is only a convention, these folders are not treated specially by subversion. 22 / 49
  • 23. Multiple parallel branches Figure from the SVN Book 23 / 49
  • 24. Branching In subversion, a branch is simply a copy: Branching svn copy REPO/calc/trunk REPO/calc/branches/my-calc-branch You work on a branch as you would on any other folder File histories branch too From the SVN Book 24 / 49
  • 25. Merging Merging is synchronizing two branches When developing a branch, you’ll want to synch with trunk from time to time Merging from an ancestor branch svn merge ˆ/calc/trunk (when in branch) When merging, you can encounter conflicts, to be resolved as before If you want to integrate a branch back to trunk, you can merge it back Merging from a child branch svn merge --reintegrate ˆ/calc/branch/my-calc-branch When in trunk 25 / 49
  • 26. What else? Keyword substitutions (e.g. $Id: . . . $) Properties (e.g. files to ignore) Tags Combining files from multiple repositories Advanced branch and merge Repository administration Server configuration ... 26 / 49
  • 27. References Subversion http://subversion.tigris.org/ The SVN Book http://svnbook.red-bean.com/ This presentation is mostly derived from this freely available book Tortoise SVN http://tortoisesvn.net/ 27 / 49
  • 28. Outline 1 Why Version Control? 2 Centralized: Subversion 3 Decentralized: Git Decentralized Model Git in Practice Geekiness 4 Q&A 28 / 49
  • 29. Decentralized Version Control Model From the Git Book 29 / 49
  • 30. Decentralized Version Control Pros and Cons Pros Every working copy is a full backup of the data You can work off-line You can work with several repositories within the same project You can rewrite (local) history: You can do microcommits (You can hide your mistakes and look smarter than you are) Allows private work, eases experimental jump in Often faster Cons More complex Less control on project evolution Less sharing? 30 / 49
  • 31. Git Git is an increasingly popular distributed versioning system It is free open-source software It is cross-platform (although better support for Linux) It is very efficient :-) It is very powerful ;-) It can be very complex :’( It has GUIs and IDEs plugins (although less than subversion) There is no global revision numbers, hashes instead Hashes may be abbreviated, and revisions may be given relatively to HEAD (e.g. HEADˆ, HEAD˜4) Obtaining help git help [COMMAND] List available commands, or describe a command. 31 / 49
  • 32. The Three States From the Git Book 32 / 49
  • 33. Updating your working copy Obtain a working copy for the first time This action is called clone : git clone REPOSITORY_URL DEST_DIR This creates a working copy of the remote repository with a complete copy of the repository itself in .git. Updating an existing working copy git pull [REPO] Incorporates changes from a remote repo into the current branch. As before, always update your working copy prior to making changes. 33 / 49
  • 34. Making changes To edit a file, simply open it in your editor, and make your changes. Then stage your changes with git add. To delete, copy or rename a file, use git Tree changes git add FOO adds FOO to the index git rm FOO removes FOO git mv FOO BAR moves FOO to BAR These changes only impacted the working directory and index so far, the repository is still untouched. 34 / 49
  • 35. Review your changes Before committing changes to the repository, check exactly what you have changed: Allows to detect errors Helps making good log messages Inspecting the working copy git status list changes in the working directory and index git diff FOO shows what has changed in file FOO compared to index version git diff --cached FOO shows what has changed in file FOO compared to repository version Fix eventual problems, either by modifying a file again, or by reseting to the version from the repository (or index) Forgetting changes git reset FOO Restores FOO to a previous state. 35 / 49
  • 36. Publish your changes to the repository Publish your changes to your own repo This action is called commit: git commit When committing, you give a message indicating what the change is about, which is consigned in the log file. Publish your changes to others git pull [REPO] Integrates changes from remote repo (this may lead to conflicts). git push [REPO] Upload your changes to remote repository. 36 / 49
  • 37. Resolve any conflict When you do a git pull (or push), you may get conflicts if the same files were modified on both your repository and the remote one. Conflicting files will contain both versions, with markers You have to edit the files to merge the changes and remove the markers You can then add and commit the result of the merge If you were trying to pull or push, you can now try again 37 / 49
  • 38. Summary 1. Checkout or update your working copy and repo (clone, pull) 2. Make changes (edit, add, cp, rm, . . . ) 3. Review your changes (status, diff) 4. Fix your mistakes (edit, reset) 5. Stage changes (add) 6. Commit changes (commit) 7. Resolve conflicts (pull, edit, add, commit) 8. Publish your changes (push) 38 / 49
  • 39. Examining history Showing the log git log [FOO] Shows log (relevant to FOO). Showing differences git diff [REV1] [REV2] [FOO] Shows what changed in FOO between revisions REV1 and REV2. Obtain an old version of a file List file hashes in a commit with git git ls-tree COMMIT_HASH Then recover file with git git cat-file blob FOO_HASH > FOO.old Time traveling git checkout COMMIT_HASH 39 / 49
  • 40. Starting a New Project Creating the repository In the project directory: git init You then need to add and commit files to import them. Creating and populating a public repository On the server: mkdir project.git; cd project.git git --bare init On the initial client: git remote add origin URL git push origin master master is the main branch, the equivalent of trunk in SVN origin is a conventional name for the main remote repository there is no need for branches or tags folders, git has built-in support for them 40 / 49
  • 41. Branching Creating a new branch git checkout -b NEW-BRANCH Creates a new branch and immediately switch to it Switch to another branch git checkout BRANCH Will change the working copy and index to match the given branch. New changes will now go into that branch. Checking branches git show-branch Will show the different branches and a summary of their last changes 41 / 49
  • 42. Merging Merging from a branch git merge BRANCH Reflect changes from given branch into the current branch. This may lead to conflicts, which you can then fix and commit. Cherry-picking Cherry-picking is selective merging. git cherry-pick COMMIT_HASH Merges only the single commit identified by its hash. 42 / 49
  • 43. Other Random Topics Tags With git, you can tag a release with git tag TAG_NAME This gives a symbolic name to the corresponding hash. You must push tags explicitly with git push --tags [REPO] Undoing things To cancel changes introduced by a commit, use: git revert COMMIT_HASH This will undo the changes in the working copy, you can then commit the new version. 43 / 49
  • 44. Other Random Topics (cnt’d) Ignoring files Just create a .gitignore file. On each line, the name of a file to be ignored by git. Those can contain wildcards. You can have a .gitignore in a subdirectory. Customizing git She comes in colors: git config --global git config --global git config --global git config --global Setting user info: git config --global git config --global color.status auto color.branch auto color.interactive auto color.diff auto user.name ’Your Name’ user.email ’you@your.domain’ 44 / 49
  • 45. References git http://git-scm.com/ The git book http://git-scm.com/book Freely available book The git book (fr) http://alx.github.io/gitbook/ Old, incomplete French version 45 / 49
  • 46. Rewriting history Have you ever dreamed of rewriting history? Yes, you can! You can merge microcommits, or mutually cancelling ones, into a more coherent set of commits, for a nicer log. Don’t do it just to show off (never did, . . . well, maybe once or twice) Never do it if you pushed to a remote repository (or you’ll seriously mess everything up) Rewriting history To reorder/merge/modify/. . . last 10 commits: git rebase -i HEAD˜10 46 / 49
  • 47. Giting Your Life You can also store binary files in a version control system (of course, merge becomes tougher) I store my whole /home/soldani directory under git Fun and useful I ignore sensitive and cache files I use multiple repositories to improve performance (git is not designed for huge and numerous binary files) mgit #!/bin/sh while read dir; do echo "======== $dir" cd "$dir" git $* done < ~/.mgit 47 / 49
  • 48. Outline 1 Why Version Control? 2 Centralized: Subversion 3 Decentralized: Git 4 Q&A 48 / 49
  • 49. Questions and (Possibly) Answers ? 49 / 49