View source for mercurial

{{anchor href="top"}}
Hits :  **{{hits}}**


== Mercurial :: Mini How To ==

!!Working Progress ... still :)!!
!!(blue) Προσπαθώ να καταγράψω το ((http://mercurial.selenic.com/wiki/WhatsNew#A1.4_-_2009-11-16 Mercurial 1.4))!!

{{ToC from="h2" to="h3"}}

=== Mercurial ===

file:logomercurial.png

a fast, lightweight Source Control Management system designed for efficient handling of very large distributed projects.

Το λογισμικό mercurial είναι ένα πρόγραμμα για απομακρυσμένη διαχείριση κώδικα ανεξάρτητα με το λειτουργικό.

http://www.selenic.com/mercurial

Το βιβλίο του mercurial: http://hgbook.red-bean.com

Ενώ ένα πολύ ενδιαφέρον site for tips: ((http://hgtip.com/ hgtip))

Data Sheets: 
%%
http://www.ivy.fr/mercurial/ref/v1.0
http://edong.net/2008v1/docs/dongwoo-Hg-300dpi.png
%%

Παρουσίαση: ((http://video.google.com/videoplay?docid=-7724296011317502612 google))

Ένα υπέρ-αναλυτικό άρθρο για Version Control: http://www.infoq.com/articles/dvcs-guide

((#top))
-----------

=== Installation ===

Requirement:  Python 2.3.0 or later,  ((http://www.gnu.org/software/make/ Gnu Make))

(Σε μία διανομή ubuntu χρειάζεται απλά το : apt-get install python2.5-dev)

%%(code)
$ wget -c http://mercurial.selenic.com/release/mercurial-1.4.tar.gz
$ tar zxvf mercurial-1.4.tar.gz
$ cd mercurial-1.4
$ make all
$ make install
%%

Εναλλακτικά μπορούμε να κατεβάσουμε την τελευταία σταθερή έκδοση μέσω του mercurial
(εάν δλδ έχουμε παλαιότερη έκδοση) με τον εξής τρόπο:

%%
$ hg clone http://selenic.com/repo/hg-stable mercurial.hg
$ cd mercurial.hg
$ make all
$ make install
%%

Εάν θέλουμε να χρησιμοποιήσουμε την development έκδοση του mercurial τότε πρέπει να
κατεβάσουμε το εξής αντίγραφο: 

%%
$ hg clone http://selenic.com/repo/hg mercurial.hg
%%

((#top))
-----------

==== Extras ====

%%
# cp contrib/bash_completion /etc/bash_completion.d/hg
# cp contrib/vim/HGAnnotate.vim /usr/share/vim/vim72/syntax/
%%

((#top))
-----------

=== Simple Usage ===

Το ακόλουθο κομμάτι κώδικα αποτελεί ένα πολύ απλό παράδειγμα χρήσης του mercurial.
  1. Παράγουμε έναν κλώνο. Δλδ κατεβάζουμε ένα πλήρη αντίγραφο ενός project.
  2. Ενημερωνόμαστε για τυχόν αλλαγές στον κώδικα.
  3. Εάν υπάρχουν αλλαγές πραγματοποιούμε αναβάθμιση στο αντίγραφο που διατηρούμε.

%%(code)
$ hg clone http://hg.dovecot.org/dovecot/
$ cd dovecot
%%

Όποτε θέλουμε να ελέγξουμε για τυχόν αλλαγές στον κώδικο τότε απλά γράφουμε:

%%(code)
$ hg pull
pulling from http://hg.dovecot.org/dovecot/
searching for changes
no changes found
$ hg update
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
%%

==== log ====

%%
$ hg log | head -11
changeset:   7493:45b79d3e393e
tag:         tip
user:        Matt Mackall <mpm@selenic.com>
date:        Sat Dec 20 16:12:01 2008 -0600
summary:     Added signature for changeset 3773e510d433

changeset:   7492:e9d21bbfd4cc
user:        Matt Mackall <mpm@selenic.com>
date:        Sat Dec 20 16:12:00 2008 -0600
summary:     Added tag 1.1.1 for changeset 3773e510d433
%%

==== parents ====

%%
$ hg parents
changeset:   7493:45b79d3e393e
tag:         tip
user:        Matt Mackall <mpm@selenic.com>
date:        Sat Dec 20 16:12:01 2008 -0600
summary:     Added signature for changeset 3773e510d433
%%

==== Αναβάθμιση ====

%%
$ hg pull
$ hg update
%%

==== Status ====

%%
$ hg status 
%%

==== Δημιουργία αρχειοθήκης ====

Από τον κατάλογο που έχουμε μπορούμε να δημιουργήσουμε archive files.
Οι τύποι μου υποστήριζονται είναι οι εξής:

  * files, Απλά ένας κατάλογος με αρχεία
  * tar, ασυμπίεστο αρχείο αρχειοθήκης
  * tbz2, ((http://en.wikipedia.org/wiki/Bzip2 bzip2)) συμπιεσμένο αρχείο αρχειοθήκης
  * tgz, ((http://en.wikipedia.org/wiki/Gzip gzip) συμπιεσμένο αρχείο αρχειοθήκης
  * uzip, ασυμπίεστο αρχείο μορφής zip
  * zip, ((http://en.wikipedia.org/wiki/ZIP_(file_format) zip)) συμπιεσμένο αρχείο

Ένα παράδειγμα:

%%
$ hg archive -t tbz2 mercurial.tbz2

$ file mercurial.tbz2 
mercurial.tbz2: bzip2 compressed data, block size = 900k
%%


==== branch ====

%%
$ hg branche
default                     7493:45b79d3e393e

$ hg branches
default                     7493:45b79d3e393e
%%

==== heads ====

%%
$ hg heads
changeset:   7493:45b79d3e393e
tag:         tip
user:        Matt Mackall <mpm@selenic.com>
date:        Sat Dec 20 16:12:01 2008 -0600
summary:     Added signature for changeset 3773e510d433
%%

==== identify ====

%%
$ hg identify
45b79d3e393e tip
%%

==== paths ====

%%
$ hg paths
default = http://selenic.com/repo/hg-stable
%%

==== resolve ====

%%
$ hg resolve --all
%%

==== root ====

%%
$ hg root 
/home/ebal/mercurial.hg
%%

==== show config ====

%%
$ hg showconfig
bundle.mainreporoot=/home/ebal/dnl/sw/mercurial.hg
paths.default=http://selenic.com/repo/hg-stable
%%

==== tags ====

Τα tags είναι ένας ευκολότερος και καλύτερος τρόπος για να διαχειριζόμαστε τις εκδόσεις αντί των revision numbers.
Μπορούμε να δούμε τα tags με την εξής εντολή:

%%
$ hg tags | head 
tip                             7493:45b79d3e393e
1.1.1                           7491:3773e510d433
1.1                             7461:2a67430f92f1
1.0.2                           6514:d2375bbee6d4
1.0.1                           6457:d5cbbe2c49ce
1.0                             6386:bae2e9c838e9
0.9.5                           5472:23889160905a
0.9.4                           4723:fb4b6d5fe100
0.9.3                           3896:27230c29bfec
0.9.2                           3865:36a957364b1b
%%

Σε δικό μας παράδειγμα μπορούμε να ορίσουμε ένα tag ως εξής:

%%
$ hg tag -r 2 test
%%

==== tip ====

Το **Tip** είναι πάντα το τελευταίο changeset (είναι κάτι σαν tag για την τελευταία έκδοση)

%%
$ hg tip
changeset:   7493:45b79d3e393e
tag:         tip
user:        Matt Mackall <mpm@selenic.com>
date:        Sat Dec 20 16:12:01 2008 -0600
summary:     Added signature for changeset 3773e510d433
%%

==== verify ====

%%
$ hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
1117 files, 7494 changesets, 14713 total revisions
%%

==== version ====

%%
$ hg version
Mercurial Distributed SCM (version unknown)

Copyright (C) 2005-2008 Matt Mackall <mpm@selenic.com> and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
%%

((#top))
-----------

=== Changes ===

See History or Change:
%%(code)
hg log
%%

See Heads of Log
%%(code)
$ hg heads
%%

Version:
%%(code)
hg version
%%

Status:

%%(code)
hg status
%%

Root:
%%(code)
hg root
%%

((#top))
-----------

=== Summary ===

Εμφανίζει μία συνοπτική κατάσταση του καταλόγου εργασίας mercurial.

Ορίστε ένα παράδειγμα (από το dovecot 1.2):

%%
$ hg summary 
parent: 9484:fa8a438c64ce tip
 lib-index: MAIL_TRANSACTION_TYPE_MASK didn't contain the new _EXT_HDR_UPDATE32.
branch: HEAD
commit: (clean)
update: (current)
%%

((#top))
-----------

=== Web ===

Μία από τις καλύτερες δυνατότητες του mercurial είναι ότι μπορεί να μας "σερβίρει" το περιεχόμενο
ενός version source directory μέσω http. Είναι εξαιρετικά εύκολο:

%%
$ hg serve

127.0.0.1 - - [23/Dec/2008 21:55:52] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [23/Dec/2008 21:55:52] "GET /static/style-paper.css HTTP/1.1" 200 -
127.0.0.1 - - [23/Dec/2008 21:55:52] "GET /static/hglogo.png HTTP/1.1" 200 -
127.0.0.1 - - [23/Dec/2008 21:55:52] "GET /static/hgicon.png HTTP/1.1" 200 -
127.0.0.1 - - [23/Dec/2008 21:55:55] "GET /static/hgicon.png HTTP/1.1" 200 -
%%

Ο python http server ακούει by default στην http port=8000.

Οπότε μπορούμε απλά με την χρήση ενός web client/browser (π.χ. firefox) 
να ανοίξουμε την εξής διεύθυνση:

%%
http://localhost:8000
%%

((#top))
-----------

=== Mercurial Help ===

Παρακάτω είναι οι τρόποι να για δούμε την βοήθεια και την επεξήγηση των εντολών του mercurial project

%%(code)
$ hg

$ hg -v

$ hg --help

$ man hg
%%

και εάν θέλουμε βοήθεια για μία συγκεκριμένη εντολή:

%%(code)
$ hg help init

$ hg -v help init
%%

και εάν θέλουμε ακόμα περισσότερη βοήθεια :

%%(code)
$ hg --debug help
%%

((#top))
-----------

=== List of commands ===

Η παρακάτω λίστα εντολών αποτελεί απλά ένα **hg help**
από την stable έκδοση του mercurial 0.9.5.

** hg command**
$ hg help
Mercurial Distributed SCM

list of commands:

#|
|| annotate|show changeset information per file line ||
|| archive|create unversioned archive of a repository revision ||
|| backout|reverse effect of earlier changeset ||
|| bisect|subdivision search of changesets ||
|| branch|set or show the current branch name ||
|| branches|list repository named branches ||
|| bundle|create a changegroup file ||
|| cat|output the current or given revision of files ||
|| clone|make a copy of an existing repository ||
|| commit|commit the specified files or all outstanding changes ||
|| copy|mark files as copied for the next commit ||
|| diff|diff repository (or selected files) ||
|| export|dump the header and diffs for one or more changesets ||
|| grep|search for a pattern in specified files and revisions ||
|| heads|show current repository heads or show branch heads ||
|| help|show help for a given topic or a help overview ||
|| identify|identify the working copy or specified revision ||
|| import|import an ordered set of patches ||
|| incoming|show new changesets found in source ||
|| init|create a new repository in the given directory ||
|| locate|locate files matching specific patterns ||
|| log|show revision history of entire repository or files ||
|| manifest|output the current or given revision of the project manifest ||
|| merge|merge working directory with another revision ||
|| outgoing|show changesets not found in destination ||
|| parents|show the parents of the working dir or revision ||
|| paths|show definition of symbolic path names ||
|| pull|pull changes from the specified source ||
|| push|push changes to the specified destination ||
|| recover|roll back an interrupted transaction ||
|| remove|remove the specified files on the next commit ||
|| rename|rename files; equivalent of copy + remove ||
|| resolve|retry file merges from a merge or update ||
|| revert|restore individual files or dirs to an earlier state ||
|| rollback|roll back the last transaction ||
|| root|print the root (top) of the current working dir ||
|| serve|export the repository via HTTP ||
|| showconfig|show combined config settings from all hgrc files ||
|| status|show changed files in the working directory ||
|| tag|add one or more tags for the current or given revision ||
|| tags|list repository tags ||
|| tip|show the tip revision ||
|| unbundle|apply one or more changegroup files ||
|| update|update working directory ||
|| verify|verify the integrity of the repository ||
|| version|output version and copyright information ||
|#

additional help topics:

#|
|| dates|Date Formats ||
|| patterns|File Name Patterns ||
|| environment|Environment Variables ||
|| revisions|Specifying Single Revisions ||
|| multirevs|Specifying Multiple Revisions ||
|| diffs|Diff Formats ||
|#

((#top))
-----------

=== Mercurial in Action ===

==== Βασικές Λειτουργίες ====

Ο παρακάτω κώδικας αποτελεί ένα τυπικό παράδειγμα χρήσης του mercurial.
Γίνεται  επεξήγηση μέσω παραδείγματος των παρακάτω βασικών λειτουργιών:

  * init
  * add
  * commit
  * annotate
  * log
  * heads
  * status
  * manifest
  * rollback
  * revert
  * clone
  * pull
  * push
  * merge
  * update
  * version

Το παρακάτω παράδειγμα λειτουργίας παρουσιάζεται γραφικά στο κάτω μέρος της σελίδας αυτής.
Για λόγους ευχρηστίας έχω αριθμήσει τα βήματα.

((#top))
-----------

==== Παράδειγμα Κώδικα ====

file:hg01.jpg

%%(html)
############################################################
## Hg Init - Add - Commit - Rollback - Revert - Status - log
############################################################

$ hg version
Mercurial Distributed SCM (version 0.9.5)

Copyright (C) 2005-2007 Matt Mackall <mpm@selenic.com> and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cd /tmp
$ mkdir -pv 0
mkdir: created directory `0'
$ cd 0/
$ ls -a
.  ..
$ hg init
$ ls -a
.  ..  .hg
$ cat > hello.py <<EOF
> #! /usr/bin/python
> print "Hello World"
> EOF
$ chmod u+x hello.py 
$ ./hello.py 
Hello World
$ hg add
adding hello.py
$ hg status
A hello.py
$ hg commit -u ebal -m 'Initial Checkout'
$ hg log
changeset:   0:c972c6b85200
tag:         tip
user:        ebal
date:        Fri Dec 28 14:20:29 2007 +0200
summary:     Initial Checkout

$ echo "print 30+10" >> hello.py
$ ./hello.py
Hello World
40
$ hg log
changeset:   0:c972c6b85200
tag:         tip
user:        ebal
date:        Fri Dec 28 14:20:29 2007 +0200
summary:     Initial Checkout

$ hg st
M hello.py
$ hg commit -u ebal -m '30+10'

$ hg annotate hello.py
0: #!/usr/bin/python
0: print "Hello World"
1: print 30+10

$ hg log
changeset:   1:55b1aefad4c6
tag:         tip
user:        ebal
date:        Fri Dec 28 14:21:16 2007 +0200
summary:     30+10

changeset:   0:c972c6b85200
user:        ebal
date:        Fri Dec 28 14:20:29 2007 +0200
summary:     Initial Checkout

$ hg heads
changeset:   1:55b1aefad4c6
tag:         tip
user:        ebal
date:        Fri Dec 28 14:21:16 2007 +0200
summary:     30+10

$ hg manifest
hello.py

$ hg rollback
rolling back last transaction
$ hg log
changeset:   0:c972c6b85200
tag:         tip
user:        ebal
date:        Fri Dec 28 14:20:29 2007 +0200
summary:     Initial Checkout

$ hg st
M hello.py
$ hg revert hello.py
reverting hello.py

$ hg log
changeset:   0:c972c6b85200
tag:         tip
user:        ebal
date:        Fri Dec 28 14:20:29 2007 +0200
summary:     Initial Checkout

$ ./hello.py
Hello World

############################################################
## Hg Clone - Push - Pull - Merge - Update
############################################################

$ cd ..
$ hg clone 0 1
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

$ hg clone 0 2
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

$ cd 1/
$ echo "print 20+20" >> hello.py 
$ ./hello.py
Hello World
40
$ hg log
changeset:   0:c972c6b85200
tag:         tip
user:        ebal
date:        Fri Dec 28 14:20:29 2007 +0200
summary:     Initial Checkout

$ hg st
M hello.py
$ hg ci -u ebal -m '20+20'
$ hg log
changeset:   1:37024d736aae
tag:         tip
user:        ebal
date:        Fri Dec 28 14:22:38 2007 +0200
summary:     20+20

changeset:   0:c972c6b85200
user:        ebal
date:        Fri Dec 28 14:20:29 2007 +0200
summary:     Initial Checkout

$ hg push
pushing to /tmp/0
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files

$ cd ../2/
$ echo "print 30+30" >> hello.py 
$ ./hello.py 
Hello World
60
$ hg log
changeset:   0:c972c6b85200
tag:         tip
user:        ebal
date:        Fri Dec 28 14:20:29 2007 +0200
summary:     Initial Checkout

$ hg st
M hello.py
$ hg ci -u ebal -m '30+30'
$ hg log
changeset:   1:7ae88d5f15d1
tag:         tip
user:        ebal
date:        Fri Dec 28 14:23:02 2007 +0200
summary:     30+30

changeset:   0:c972c6b85200
user:        ebal
date:        Fri Dec 28 14:20:29 2007 +0200
summary:     Initial Checkout

$ hg pull
pulling from /tmp/hello
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
(run 'hg heads' to see heads, 'hg merge' to merge)

$ hg merge
merging hello.py
0 files updated, 1 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
$ hg ci -u ebal -m 'merge commit'
$ hg log
changeset:   3:262581d0c679
tag:         tip
parent:      2:37024d736aae
parent:      1:7ae88d5f15d1
user:        ebal
date:        Fri Dec 28 14:25:23 2007 +0200
summary:     merge commit

changeset:   2:37024d736aae
parent:      0:c972c6b85200
user:        ebal
date:        Fri Dec 28 14:22:38 2007 +0200
summary:     20+20

changeset:   1:7ae88d5f15d1
user:        ebal
date:        Fri Dec 28 14:23:02 2007 +0200
summary:     30+30

changeset:   0:c972c6b85200
user:        ebal
date:        Fri Dec 28 14:20:29 2007 +0200
summary:     Initial Checkout

$ hg st
? hello.py.tmp.
$ ./hello.py
Hello World
60
40
$ hg push
pushing to /tmp/0
searching for changes
adding changesets
adding manifests
adding file changes
added 2 changesets with 2 changes to 1 files

$ cd ../1/
$ hg pull
pulling from /tmp/0
searching for changes
adding changesets
adding manifests
adding file changes
added 2 changesets with 2 changes to 1 files
(run 'hg update' to get a working copy)
$ hg up
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ ./hello.py 
Hello World
60
40

%%

((#top))
-----------

==== Γραφική απεικόνηση βασικής λειτουργίας ====

file:hg02.png

((#top))
-----------


==== hgrc ====

%%
vim ~/.hgrc
%%

%%
[ui]
username = Evaggelos Balaskas <ebalaskas@ebalaskas.gr>
verbose = True

[extensions]
hgext.graphlog = 

[extensions]
hgext.extdiff =

[extdiff]
cmd.meld = meld
opts.meld =
%%