Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git VS Mercurial

Git VS Mercurial

Just a very brief overview of DCVS, namely Git and Mercurial

Ilja Hämäläinen

December 02, 2014

More Decks by Ilja Hämäläinen

Other Decks in Programming


  1. 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
  2. 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
  3. Commit Git: $ git add . $ git commit -m

    “Commit message” or $ git commit -am “Commit message” Mercurial: $ hg commit -m “Commit message”
  4. 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!
  5. Switch between revisions Git: $ git checkout $ git checkout

    e2b6c376c Mercurial: $ hg update $ hg update 957b22
  6. Pull and push Git: $ git pull origin master $

    git push origin master Mercurial: $ hg pull $ hg push
  7. 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
  8. On which branch I am? Git: $ git branch output:

    master * issue53 feature47 Mercurial: $ hg branch output: issue53 or: $ hg branches
  9. 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
  10. 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
  11. 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
  12. 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".
  13. 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.
  14. 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.
  15. Summary about branching Git Mercurial local branches + bookmarks only

    remote branches + - rebase + + fast-forward + -
  16. 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
  17. 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
  18. 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(-)
  19. 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
  20. 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 ...
  21. 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
  22. How many commits are ready to go? Git: git log

    origin/dev..dev Mercurial: hg outgoing hg out
  23. 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
  24. 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
  25. 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.
  26. 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
  27. 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
  28. 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.
  29. If you need to go to a local shop to

    buy a milk and eggs? Git ✓ Mercurial • Understandable • Simple • Unified, robust
  30. If you need to deliver parcels to several distributors? ✓

    Git Mercurial • Local/Remote branches • A lot of extensions • Big community
  31. “Never select a technology for just the sake of a

    technology, have a reason!” Someone in the Internet