Git vs. Mercurial
-
Upload
marian-marinov -
Category
Technology
-
view
2.344 -
download
0
description
Transcript of Git vs. Mercurial
Git vs. MercurialGit vs. Mercurial
Marian MarinovMarian MarinovSystem Architect at Siteground.comSystem Architect at Siteground.com
1. Evolution of revision control systems1. Evolution of revision control systems * RCS -> CVS -> SVN * RCS -> CVS -> SVN * Single repository for the history* Single repository for the history * Working copy of a file* Working copy of a file * Only one developer can commit at a time* Only one developer can commit at a time * Complicated merges* Complicated merges
RCS/CVS/SVN ARE YOUR RCS/CVS/SVN ARE YOUR
ENEMYENEMY
2. Distributed version control systems(DVCS)2. Distributed version control systems(DVCS) * Locally accessible history* Locally accessible history * Every developer can commit at will* Every developer can commit at will * Every client can become a server (no single * Every client can become a server (no single server required)server required) * Seamless merges* Seamless merges
3. Basic repository models3. Basic repository models * Shared repository* Shared repository
* Distributed repository* Distributed repository
* Access polices* Access polices
Top repositoryTop repository
clone 1clone 1
clone 4clone 4clone 2clone 2
clone 3clone 3
RepositoryRepository
RepositoryRepository
RepositoryRepository
RepositoryRepository
RepositoryRepository
RepositoryRepository
RepositoryRepository
Centralized WorkflowCentralized Workflowsharedshared
repositoryrepository
developerdeveloper
developerdeveloper
developerdeveloper
Integration-Manager Workflow
Project'sProject'srepositoryrepository
IntegrationIntegrationmanagermanager
DeveloperDeveloperpublicpublic
DeveloperDeveloperprivateprivate
DeveloperDeveloperpublicpublic
DeveloperDeveloperprivateprivate
DeveloperDeveloperpublicpublic
DeveloperDeveloperprivateprivate
Dictator Workflow
kernel.org
Sub treeSub treemaintainermaintainer
Sub treeSub treemaintainermaintainer
Sub treeSub treemaintainermaintainer
developerdeveloper developerdeveloperdeveloperdeveloper
developerdeveloper
developerdeveloper
developerdeveloper
Dictator Workflow
kernel.org
Sub treeSub treemaintainermaintainer
Sub treeSub treemaintainermaintainer
Sub treeSub treemaintainermaintainer
developerdeveloper developerdeveloperdeveloperdeveloper
developerdeveloper
developerdeveloper
developerdeveloper
4. Basic work 4. Basic work * init* init
* add* add* commit* commit* mv / rename* mv / rename* rm vs. remove* rm vs. remove* log* log* diff* diff* grep* grep* clone* clone* push* push* pull* pull* branch & checkout * branch & checkout * blame vs. annotate* blame vs. annotate
Basic performance infoBasic performance info
[root@Beast git]# time git init[root@Beast git]# time git initInitialized empty Git repository in .git/Initialized empty Git repository in .git/
real 0m0.129sreal 0m0.129suser 0m0.000suser 0m0.000ssys 0m0.000ssys 0m0.000s
[root@Beast hg]# time hg init[root@Beast hg]# time hg init
real 0m0.204sreal 0m0.204suser 0m0.020suser 0m0.020ssys 0m0.010ssys 0m0.010s[root@Beast hg]#[root@Beast hg]#
initinit
addadd[root@Beast git]# time git add file0[root@Beast git]# time git add file0
real 0m0.016sreal 0m0.016suser 0m0.000suser 0m0.000ssys 0m0.000ssys 0m0.000s [root@Beast hg]# time hg add file0[root@Beast hg]# time hg add file0
real 0m0.098sreal 0m0.098suser 0m0.030suser 0m0.030ssys 0m0.010ssys 0m0.010s
statusstatus[root@Beast git]# time git status[root@Beast git]# time git status# On branch master# On branch master### Initial commit# Initial commit### Untracked files:# Untracked files:# (use "git add <file>..." to include in what will be # (use "git add <file>..." to include in what will be committed)committed)### file0# file0nothing added to commit but untracked files present nothing added to commit but untracked files present (use "git add" to track)(use "git add" to track)
real 0m0.034sreal 0m0.034suser 0m0.000suser 0m0.000ssys 0m0.000ssys 0m0.000s
statusstatus
[root@Beast hg]# time hg status[root@Beast hg]# time hg status? file0? file0
real 0m0.028sreal 0m0.028suser 0m0.010suser 0m0.010ssys 0m0.010ssys 0m0.010s
commitcommit
[root@Beast git]# time git commit -m [root@Beast git]# time git commit -m 'added file0' file0'added file0' file0Created initial commit 43bb00d: added file0Created initial commit 43bb00d: added file0 1 files changed, 1 insertions(+), 0 1 files changed, 1 insertions(+), 0 deletions(-)deletions(-) create mode 100644 file0create mode 100644 file0
real 0m0.047sreal 0m0.047suser 0m0.000suser 0m0.000ssys 0m0.000ssys 0m0.000s
commitcommit
[root@Beast hg]# time hg commit -m [root@Beast hg]# time hg commit -m 'added file0' file0'added file0' file0No username found, using No username found, using '[email protected]' instead'[email protected]' instead
real 0m0.218sreal 0m0.218suser 0m0.030suser 0m0.030ssys 0m0.000ssys 0m0.000s
statusstatus
[root@Beast hg]# hg status[root@Beast hg]# hg status [root@Beast git]# git status[root@Beast git]# git status# On branch master# On branch masternothing to commit (working directory clean)nothing to commit (working directory clean)
movemove
movemove[root@Beast git]# git mv file0 file1[root@Beast git]# git mv file0 file1[root@Beast git]# git status[root@Beast git]# git status# On branch master# On branch master# Changes to be committed:# Changes to be committed:# (use "git reset HEAD <file>..." to # (use "git reset HEAD <file>..." to unstage)unstage)### renamed: file0 -> file1# renamed: file0 -> file1##[root@Beast git]# git commit -m 'renamed [root@Beast git]# git commit -m 'renamed file0' file1file0' file1Created commit 077d7a3: renamed file0Created commit 077d7a3: renamed file0 1 files changed, 1 insertions(+), 0 1 files changed, 1 insertions(+), 0 deletions(-)deletions(-) create mode 100644 file1create mode 100644 file1
movemove
[root@Beast git]# git status[root@Beast git]# git status# On branch master# On branch master# Changes to be committed:# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)# (use "git reset HEAD <file>..." to unstage)### deleted: file0# deleted: file0##[root@Beast git]# git commit -m 'removed [root@Beast git]# git commit -m 'removed file0' file0file0' file0Created commit dfa8fb4: removed file0Created commit dfa8fb4: removed file0 1 files changed, 0 insertions(+), 1 deletions(-)1 files changed, 0 insertions(+), 1 deletions(-) delete mode 100644 file0delete mode 100644 file0
movemove
[root@Beast hg]# hg rename file0 file1[root@Beast hg]# hg rename file0 file1[root@Beast hg]# hg status[root@Beast hg]# hg statusA file1A file1R file0R file0[root@Beast hg]# hg commit -m 'renamed [root@Beast hg]# hg commit -m 'renamed file0 to file1' file1file0 to file1' file1[root@Beast hg]# hg status[root@Beast hg]# hg statusR file0R file0[root@Beast hg]# hg commit -m 'removed [root@Beast hg]# hg commit -m 'removed file0' file0file0' file0[root@Beast hg]# hg status[root@Beast hg]# hg status
rmrm
rmrm
[root@Beast hg]# hg remove new1[root@Beast hg]# hg remove new1[root@Beast hg]# hg status[root@Beast hg]# hg statusR new1R new1[root@Beast hg]# hg commit -m [root@Beast hg]# hg commit -m 'removed new1' new1'removed new1' new1[root@Beast hg]# hg status[root@Beast hg]# hg status[root@Beast hg]#[root@Beast hg]#
[root@Beast git]# git rm file1[root@Beast git]# git rm file1rm 'file1'rm 'file1'[root@Beast git]# git status[root@Beast git]# git status# On branch master# On branch master# Changes to be committed:# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)# (use "git reset HEAD <file>..." to unstage)### deleted: file1# deleted: file1##[root@Beast git]# git commit -m 'rm file1' file1[root@Beast git]# git commit -m 'rm file1' file1Created commit d47d595: removed file1Created commit d47d595: removed file1 1 files changed, 0 insertions(+), 1 deletions(-)1 files changed, 0 insertions(+), 1 deletions(-) delete mode 100644 file1delete mode 100644 file1[root@Beast git]# git status[root@Beast git]# git status# On branch master# On branch masternothing to commit (working directory clean)nothing to commit (working directory clean)
LOGLOG
the hg waythe hg way$ hg l ogchangeset : 4: 2278160e78d4t ag: t i puser : Br yan O' Sul l i van <bos@ser pent i ne. com>dat e: Sat Aug 16 22: 16: 53 2008 +0200summar y: Tr i m comment s.changeset : 3: 0272e0d5a517user : Br yan O' Sul l i van <bos@ser pent i ne. com>dat e: Sat Aug 16 22: 08: 02 2008 +0200summar y: Get make t o gener at e t he f i nal bi nar y f r om a . o f i l e.changeset : 2: fef857204a0cuser : Br yan O' Sul l i van <bos@ser pent i ne. com>dat e: Sat Aug 16 22: 05: 04 2008 +0200summar y: I nt r oduce a t ypo i nt o hel l o. c.changeset : 1: 82e55d328c8cuser : mpm@sel eni c. comdat e: Fr i Aug 26 01: 21: 28 2005 - 0700summar y: Cr eat e a makef i l echangeset : 0: 0a04b987be5auser : mpm@sel eni c. comdat e: Fr i Aug 26 01: 20: 50 2005 - 0700summar y: Cr eat e a st andar d "hel l o, wor l d" pr ogr am
the hg waythe hg way
$ hg log -r 3changeset: 3:0272e0d5a517user: Bryan O'Sullivan <[email protected]>date: Sat Aug 16 22:08:02 2008 +0200summary: Get make to generate the final binary from a .o file.
$ hg log -r 0272e0d5a517changeset: 3:0272e0d5a517user: Bryan O'Sullivan <[email protected]>date: Sat Aug 16 22:08:02 2008 +0200summary: Get make to generate the final binary from a .o file.
$ hg log -r 1 -r 4$ hg log -r 2:4$ hg log -v -p -r 2
the git way$ gi t l ogcommi t ca82a6df f 817ec66f 44342007202690a93763949Aut hor : Scot t Chacon <schacon@gee- mai l . com>Dat e: Mon Mar 17 21: 52: 11 2008 - 0700
changed t he ver si on number
commi t 085bb3bcb608e1e8451d4b2432f 8ecbe6306e7e7Aut hor : Scot t Chacon <schacon@gee- mai l . com>Dat e: Sat Mar 15 16: 40: 33 2008 - 0700
r emoved unnecessar y t est code
commi t a11bef06a3f 659402f e7563abf 99ad00de2209e6Aut hor : Scot t Chacon <schacon@gee- mai l . com>Dat e: Sat Mar 15 10: 31: 28 2008 - 0700
f i r st commi t
the git waythe git way
$ gi t l og master~2$ gi t l og master~2. . master~4$ gi t l og master 1̂ 1̂ == gi t l og master~2$ gi t l og master 2̂$ gi t l og - p $ gi t l og –si nce=2. weeks$ gi t l og - - col or
diffdiff
[ root@Beast gi t]# cat f i l e1l i ne1[root@Beast gi t]# echo ' l i ne2' >> f i l e1[root@Beast gi t]# gi t di f fdi f f - - gi t a/ f i l e1 b/ f i l e1i ndex a29bdeb. . c0d0fb4 100644- - - a/ f i l e1+++ b/ f i l e1@@ - 1 +1, 2 @@ l i ne1+l i ne2
[ root@Beast hg]# cat f i l e1l i ne1[root@Beast hg]# echo ' l i ne2' >> f i l e1[root@Beast hg]# hg di f fdi f f - r d2cfa0a39fb6 f i l e1- - - a/ f i l e1 Sun Apr 25 05: 32: 01 2010 +0300+++ b/ f i l e1 Sun Apr 25 05: 32: 19 2010 +0300@@ - 1, 1 +1, 2 @@ l i ne1+l i ne2
grepgrep
* search only the project* search only the project * search trough the working copy* search trough the working copy
[ root@Beast hg]# hg grep l i ne[root@Beast hg]# hg grep l i nef i l e1: 6: l i ne1f i l e1: 6: l i ne1 [ root@Beast gi t]# gi t grep l i ne[root@Beast gi t]# gi t grep l i nef i l e1: l i ne1f i l e1: l i ne1f i l e1: l i ne2f i l e1: l i ne2
$ gi t cl one di r$ gi t cl one gi t: / / host/ di r$ gi t cl one http(s) : / / host/ di r$ gi t cl one rsync: / / [user@]host/ di r$ gi t cl one ssh: / / [user@host] / di r
ssh onl y: gi t cl one [user@]host: di r
$ hg cl one ht t p: / / host / di r$ hg cl one ssh: / / [ user @] host / di r
pullpull
Pulling changesPulling changes
Git pullGit pull* combined fetch + merge * combined fetch + merge
HG pullHG pull* only fetch * only fetch * -U for fetch + merge* -U for fetch + merge
pushpush
Pushing changes
$ gi t push [ori gi n] [master]$ gi t push [ori gi n] [master]
$ hg push [desti nati on]$ hg push [desti nati on]
branchingbranching
branchingbranching
GITGITHEAD – poi nts to the most recent HEAD – poi nts to the most recent commi t i n the current branchcommi t i n the current branchmaster – a speci al named branchmaster – a speci al named branch
MercurialMercurialt i p – poi nts to the most recent t i p – poi nts to the most recent commi tcommi tHead – i s the t i p or the t i ps of Head – i s the t i p or the t i ps of mergi ng branchesmergi ng branches
branchingbranching
GITGIT$ gi t branch branch_name$ gi t branch branch_name$ gi t checkout branch_name$ gi t checkout branch_name
MercurialMercurial$ hg branch branch_name$ hg branch branch_name$ hg update branch_name$ hg update branch_name
tags vs. branchestags vs. branches
* Tags i n mercuri al are synonyms to * Tags i n mercuri al are synonyms to a changeseta changeset* Tags i n mercuri al are versi on * Tags i n mercuri al are versi on control l ed control l ed * Tags i n gi t are onl y a syml i nk to * Tags i n gi t are onl y a syml i nk to a commi ta commi t* Tags i n gi t are onl y l ocal* Tags i n gi t are onl y l ocal
* Branches i n both are used for * Branches i n both are used for conti nues devel opmentconti nues devel opment
Няма значение за какво става въпрос...Той е виновен!
Blame / annotate$ hg annotate - u - d - c - l mysql$ hg annotate - u - d - c - l mysqlf l ori an 07b950dc7279 Tue Mar 02 . . . : 1: #! / bi n/ shf l ori an 07b950dc7279 Tue Mar 02 . . . : 1: #! / bi n/ shbeekhof 67234f 982ab7 Thu J ul 05 . . . : 2: #beekhof 67234f 982ab7 Thu J ul 05 . . . : 2: #f l ori an 01a181a4165c Fri Apr 02 . . . : 3: #f l ori an 01a181a4165c Fri Apr 02 . . . : 3: #beekhof 67234f 982ab7 Thu J ul 05 . . . : 4: # MySQLbeekhof 67234f 982ab7 Thu J ul 05 . . . : 4: # MySQLbeekhof 67234f 982ab7 Thu J ul 05 . . . : 5: #beekhof 67234f 982ab7 Thu J ul 05 . . . : 5: #beekhof 67234f 982ab7 Thu J ul 05 . . . : 6: # Descri pti on: beekhof 67234f 982ab7 Thu J ul 05 . . . : 6: # Descri pti on: Manages a MySQL Manages a MySQL beekhof 67234f 982ab7 Thu J ul 05 . . . : 8: #beekhof 67234f 982ab7 Thu J ul 05 . . . : 8: #f l ori an 380982a15dc8 Fri Apr 23 . . . : 8: # Authors: Al an f l ori an 380982a15dc8 Fri Apr 23 . . . : 8: # Authors: Al an Robertson: Robertson: f l ori an 380982a15dc8 Fri Apr 23 . . . : 9: # J akub f l ori an 380982a15dc8 Fri Apr 23 . . . : 9: # J akub J anczak: J anczak: f l ori an 380982a15dc8 Fri Apr 23 . . . : 10: # Andrew f l ori an 380982a15dc8 Fri Apr 23 . . . : 10: # Andrew Beekhof : Beekhof : f l ori an 380982a15dc8 Fri Apr 23 . . . : 11: # f l ori an 380982a15dc8 Fri Apr 23 . . . : 11: #
Sebasti an Rei tenbach: Sebasti an Rei tenbach:
$ gi t bl ame hawk. pl$ gi t bl ame hawk. pl0̂e22116 ( root 2008- 07- 09 . . . 1) #! / usr/ bi n/ perl - T0̂e22116 ( root 2008- 07- 09 . . . 1) #! / usr/ bi n/ perl - T
a5062333 (val 2009- 06- 10 . . . 2)a5062333 (val 2009- 06- 10 . . . 2)0̂e22116 ( root 2008- 07- 09 . . . 3) use stri ct;0̂e22116 ( root 2008- 07- 09 . . . 3) use stri ct;0̂e22116 ( root 2008- 07- 09 . . . 4) use warni ngs;0̂e22116 ( root 2008- 07- 09 . . . 4) use warni ngs;
37f b4989 (val 2009- 06- 01 . . . 5)37f b4989 (val 2009- 06- 01 . . . 5)a5062333 (val 2009- 06- 10 . . . 6) use DBD: : mysql ;a5062333 (val 2009- 06- 10 . . . 6) use DBD: : mysql ;a5062333 (val 2009- 06- 10 . . . 7) use POSI X qw(setsi d) , a5062333 (val 2009- 06- 10 . . . 7) use POSI X qw(setsi d) , qw(WNOHANG);qw(WNOHANG);. . . . . . . . . .. . . . . . . . . .a5062333 (val 2009- 06- 10 . . . 12) i mport parse_conf i g;a5062333 (val 2009- 06- 10 . . . 12) i mport parse_conf i g;6ad3f f60 (val 2009- 06- 19 . . . 13) i mport post_a_note;6ad3f f60 (val 2009- 06- 19 . . . 13) i mport post_a_note;0̂e22116 ( root 2008- 07- 09 . . . 14)0̂e22116 ( root 2008- 07- 09 . . . 14)0̂e22116 ( root 2008- 07- 09 . . . 15) # system vari abl es0̂e22116 ( root 2008- 07- 09 . . . 15) # system vari abl es0̂e22116 ( root 2008- 07- 09 . . . 16) $ENV{PATH} = ' ' ; 0̂e22116 ( root 2008- 07- 09 . . . 16) $ENV{PATH} = ' ' ;
7868b7e1 (val 2010- 04- 23 . . . 17) my $VERSI ON = ' 2. 1. 0' ; 7868b7e1 (val 2010- 04- 23 . . . 17) my $VERSI ON = ' 2. 1. 0' ; 0̂e22116 ( root 2008- 07- 09 . . . 18)0̂e22116 ( root 2008- 07- 09 . . . 18)0̂e22116 ( root 2008- 07- 09 . . . 19) # def i ni ng faul t hashes0̂e22116 ( root 2008- 07- 09 . . . 19) # def i ni ng faul t hashes
$ gi t bl ame - L 16, 18 hawk. pl$ gi t bl ame - L 16, 18 hawk. pl$ gi t bl ame - L / use stri ct/ , / use DBD/ hawk. pl$ gi t bl ame - L / use stri ct/ , / use DBD/ hawk. pl
booksbooks
books
MercurialMercurial * * http://hgbook.red-bean.com/read/http://hgbook.red-bean.com/read/
GitGit * http://book.git-scm.com/* http://book.git-scm.com/ * http://progit.org/book/* http://progit.org/book/
Marian MarinovMarian MarinovSystem Architect at Siteground.comSystem Architect at Siteground.com
E-mail: E-mail: [email protected]@yuhu.bizJabber: [email protected]: [email protected]
Thank you!Thank you!