Share
Embed
Git VS Mercurial
Just a very brief overview of DCVS, namely Git and Mercurial
Ilja Hämäläinen
December 02, 2014
Transcript
63 slides
-
Disclaimer 1: I don’t intend to force you to migrate
to any other DCVS system -
Disclaimer 2: This is my own opinion. Current presentation is
not based on any other article. -
Main features of an CVS 1. Changing history a. Rollout
b. Code review c. Logical bombs 2. Merge code from several developers a. Merging 3. Backup -
CVS vs DCVS CVS DCVS Commit/revision copy of a file
node in the changeset tree Branch copy of a folder link to another node Update/Checkout network call applying changesets locally Merging painful the part of its core -
Commit Git: $ git add . $ git commit -m
“Commit message” or $ git commit -am “Commit message” Mercurial: $ hg commit -m “Commit message” -
Amend to a previous commit Git: $ git commit --amend
Mercurial: $ hg commit --amend Note, it works only if you have not pushed you code yet! -
Switch between revisions Git: $ git checkout $ git checkout
e2b6c376c Mercurial: $ hg update $ hg update 957b22 -
Pull and push Git: $ git pull origin master $
git push origin master Mercurial: $ hg pull $ hg push -
Several repositories in Git • But Git allows you to
work with several repos • You have always to specify where exactly you want to pull/push: ◦ $ git push origin master ◦ $ git pull oleg-repo master -
Create new branch Git (local): $ git checkout -b issue53
Mercurial: $ hg branch issue53 -
On which branch I am? Git: $ git branch output:
master * issue53 feature47 Mercurial: $ hg branch output: issue53 or: $ hg branches -
Switch between branches Git: $ git checkout master output: Switched
to branch 'master' Your branch is up-to-date with 'origin/master'. Mercurial: $ hg update default output: 0 files updated, 0 files merged, 0 files removed, 0 files unresolved -
The list of remote branches (Git) The list of all
the remote branches: $ git branch -r output: origin/HEAD -> origin/master origin/master origin/refactor-services-with-standard-interfaces -
The list of local branches in Git Without parameters it
lists only local branches: $ git branch output: master * refactor-services-with-standard-interfaces but -a parameter prints all the branches: $ git branch -a -
Clone remote branch in Git $ git checkout -b feature-add-logging
origin/feature-add-logging -
Fast Forward in Git When you try to merge one
commit with a commit that can be reached by following the first commit’s history, Git simplifies things by moving the pointer forward because there is no divergent work to merge together — this is called a "fast forward". -
Bookmarks in Mercurial “Bookmark - is local reference to commits
that can be automatically updated when new commits are made.” Bookmarks in Hg is like local branches in Git. The main difference is you can push local branch in Git, but bookmark in Hg always remains local. -
Rebase Merging brings two lines of development together while preserving
the ancestry of each commit history. In contrast, rebasing unifies the lines of development by re-writing changes from the source branch so that they appear as children of the destination branch – effectively pretending that those commits were written on top of the destination branch all along. -
Summary about branching Git Mercurial local branches + bookmarks only
remote branches + - rebase + + fast-forward + - -
Hooks both Git and Mercurial: language agnostic, but the most
popular is Python and shell -
Bisect - debugging with CVS Find by binary search the
change that introduced a bug -
Bisect in Git $ git bisect $ git bisect bad
$ git bisect good v1.0 Bisecting: 6 revisions left to test after this [ecb6e1bc347ccecc5f9350d878ce677feb13d3b2] error handling on repo ... $ git bisect good Bisecting: 3 revisions left to test after this [b047b02ea83310a70fd603dc8cd7a6cd13d15c04] secure this thing $ git bisect bad Bisecting: 1 revisions left to test after this [f71ce38690acf49c1f3c9bea38e09d82a5ce6014] drop exceptions table $ git bisect reset -
Bisect in Mercurial $ hg bisect --bad $ hg update
-r -100 89 files updated, 0 files merged, 30 files removed, 0 files unresolved $ hg bisect --good Testing changeset 11964:79bd860b8eb7 (81 changesets remaining, ~6 tests) 36 files updated, 0 files merged, 22 files removed, 0 files unresolved $ hg bisect --good Testing changeset 11985:81edef14922e (41 changesets remaining, ~5 tests) 23 files updated, 0 files merged, 26 files removed, 0 files unresolved … $ hg bisect --bad The first bad revision is: changeset: 11981:518b90d66fad … $ hg bisect --reset -
Stash Hides uncommitted changes and saves it locally. Git: $
git shash Mercurial: $ hg shelve -
Web server: Mercurial There a lot of choices, but the
simplest is: $ hg serve -
Git: pull-request $ git request-pull origin/master myfork The following changes
since commit 1edee6b1d61823a2de3b09c160d7080b8d1b3a40: John Smith (1): added a new function are available in the git repository at: git://githost/simplegit.git featureA Jessica Smith (2): add limit to log function change log output to 30 from 25 lib/simplegit.rb | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) -
Git: send patches by email (1) $ git format-patch -M
origin/master 0001-add-limit-to-log-function.patch 0002-changed-log-output-to-30-from-25.patch -
Git: send patches by email (2) $ cat 0001-add-limit-to-log-function.patch From
330090432754092d704da8e76ca5c05c198e71a8 Mon Sep 17 00:00:00 2001 From: Jessica Smith <[email protected]> Date: Sun, 6 Apr 2008 10:17:23 -0700 Subject: [PATCH 1/2] add limit to log function Limit log functionality to the first 20 --- lib/simplegit.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/lib/simplegit.rb b/lib/simplegit.rb index 76f47bc..f9815f1 100644 --- a/lib/simplegit.rb +++ b/lib/simplegit.rb ... -
Git: send patches by email (3) $ git send-email *.patch
0001-added-limit-to-log-function.patch 0002-changed-log-output-to-30-from-25.patch Who should the emails appear to be from? [Jessica Smith <jessica@example. com>] Emails will be sent from: Jessica Smith <[email protected]> Who should the emails be sent to? [email protected] Message-ID to be used as In-Reply-To for the first email? y -
How many commits are ready to go? Git: git log
origin/dev..dev Mercurial: hg outgoing hg out -
Diff between revisions Git: git diff ecba4662..6bfc611a git diff ecba4662..HEAD
Mercurial: hg diff -r 10 -r 20 hg diff -r 10 -
Hostings Git Mercurial Gitorious ✔ GitLab ✔ GitHub ✔ Codeplex
✔ ✔ Codeplane ✔ Codebase ✔ ✔ Google Code ✔ ✔ BitBucket ✔ ✔ SourceForge ✔ ✔ Kenai ✔ java.net ✔ ✔ Assembla ✔ ✔ Kiln ✔ ✔ http://www.wikivs.com/wiki/Git_vs_Mercurial -
Let’s compare* Git Mercurial remote branches + - local branches
+ + pull/push to several branches + - send patches by email + - GUI tools for all the platform - + fast forward + - * this is the most common differences that an user might face during everyday practise -
but... All these differences are related to the branch management
and dealing with patches. That means, Git better works with a sources, where you don’t trust to a collaborators. Reach tools allows you to manage repositories with a different roles of developers. -
The conclusion is... The Git is the best for Open
source projects The Mercurial is ideal for small teams with the same roles and access rights -
Global VS remote/local branches • Global branches allows you to
keep track of your colleagues work • Global branches allows you to observe whole project, to see all the features • You don’t have to clone each branch every time • You don’t have to specify the branch name in pull/push operation • Clean history • Easy to learn • Low chance for a mistake -
Two sides of a coin Git: flexible ⇔ difficult to
learn, more parameters Mercurial: only basic functionality ⇔ simple The main difference is the branch model and multi- repository work in Git. Other functionality (about 90%) is almost the same. -
If you need to go to a local shop to
buy a milk and eggs? Git ✓ Mercurial • Understandable • Simple • Unified, robust -
If you need to deliver parcels to several distributors? ✓
Git Mercurial • Local/Remote branches • A lot of extensions • Big community -
“Never select a technology for just the sake of a
technology, have a reason!” Someone in the Internet