Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Mercurial training

860 visualizaciones

Publicado el

This is small slide which i summarize the common usage of Mercurial

Publicado en: Tecnología
  • Inicia sesión para ver los comentarios

Mercurial training

  1. 1. MERCURIAL TRAINING 6/4/2012 HCM city
  2. 2. Agenda • Install the Mercurial on a SUSE machine • Behind the Mercurial • Basic commands in the Mercurial • Mq extension tool for patching • Common Issues • The Mercurial vs other SCM Eng. TrungHuynh™
  3. 3. INSTALL on SuSE • Find the version of SUSE – cat /etc/SuSE-release • Find the path of repo of the Mercurial for that SuSE version – – openSUSE_11.4/devel:tools:scm.repo • Use the zypper tool to add the repo’s path zypper ar • Use the zypper/yast tool to install the Mercurial zypper install mercurial Check the installation: hg debuginstall Eng. TrungHuynh™
  4. 4. Basic Concepts • Topology – Mercurial is completely decentralized system, and thus has no concept of central repository – In Mercurial, the user can define the topology by themselves for sharing the changes Eng. TrungHuynh™
  5. 5. Basic Concepts • Repository and working directory – Mercurial repositories contain a working coupled with a store – For example: /home/repository/ directory is as below figure • In working directory, the state of files will be refer to a specific revision of repository • In .hg/store/data/ folder, it contains in formation about changes of each file Eng. TrungHuynh™ Main.c Main.h .hg Rev 0 Rev 1 Rev 2 Rev 3parent parent parent Working directory repository
  6. 6. Basic Concepts • Revision is local version index for the project • Changeset is unique version index for global • In above figure, we have a repository with two heads and two branches • Head is the revision has no child revision. And the biggest revsion head is the tip Eng. TrungHuynh™ 0 1 2 3 4 5 6(tip) Working dirhead head Branch Achangeset: 1:d7fd576b6c9b | user: trunghuynh | date: Fri Jun 08 17:28:32 2012 +0700 | files: revision
  7. 7. Common Commands hg help <command> • Hg init -> initialize a repository, of course it is a directory • Hg add -> inform the Mercurial that you want it keep track your files • Hg clone -> clone the project from a Mercurial repository – Especial, we can clone with the specific branch: hg clone <main-repo> <new-repo> -r <head of specific branc> • Hg pull -> get the changes from our peers into our repository – Notice that pull command just update our backlog information of our repository • Hg update -> will update the changes after pulling, in fact it is merging the current working revision with the change from pulling • Hg commit -> like saving edited word file. It will create a changeset • Hg push -> pushing our changes for others pulling – The backlog information of main repo will automatically update when the child repos push their changes • Hg branch ->check the current branch or set branch – Notice that branch name is permanently recorded as part of the changeset’s metadata – Branch name is used as the tip revision when we want checkout a branch • Hg log ->show the information about the repository • Hg tip ->show information of the “tip” revision. The “tip” revision is the head with largest revision Eng. TrungHuynh™
  8. 8. Common Commands • Hg merge -> merge the working directory with other revision • Hg diff -> show what is changed since the last committing • Hg revert -> revert the specific file into the unmodified state • Hg incoming ->see what will be updated when we do a pull action • Hg rollback  uncommit… • Hg annotate <filename> • Hg strip <revision number> ->delete a specific revision Eng. TrungHuynh™
  9. 9. Hg commit Eng. TrungHuynh™ 0:qe7 1:de5 2:ye2 3:af9 @ Alice’s Repo main.c model.h model.c Working directory socket.c 3:a3e changed When we commit a new changeset will be created
  10. 10. hg push/pull Eng. TrungHuynh™ Main Repos 0:qe7 1:de5 0:qe7 1:de5 2:af9 Bob’s Repo 0:qe7 1:de5 2:ye2 Alice’s Repo 2:af9 2:af9 hg pull <Bob’s repo> @ @ @ @ Mark parent revision of working directory A revision of repo
  11. 11. hg merge/update Eng. TrungHuynh™ Alice’s Repo 0:qe7 1:de5 2:ye2 3:af9 @ The “hg update” command will change our current working revision that we are working on. The “hg merge” command will merge a specific revision to the current working revision. In this case, the change from af9 changeset will merge into the revsion 2. After successful merging, we has to commit to create a new changeset/revision which contains both change from revision 3 and 2 4:kq6
  12. 12. Advance Using Mercurial • Merge conflict: – The conflict happens when two changesets have modified the same file’s section with different way. In this case, the Mercurial need a help from user. Eng. TrungHuynh™ Main() { printf(“hello Mercurial world”); printf(“Merge is fun and easy”); } Main() { printf(“hello Mercurial world”); printf(“Merge is difficult”); } Changeset 4 Changeset 7
  13. 13. Common Issues • To resolve that conflicts we need to open that file and edit to what we want. After that we use “hg resolve <filename> to correct the confliction. • To support merging, we can use a graphical tool such as kdiff3 as the best tool. Eng. TrungHuynh™
  14. 14. Common Issues • abort: outstanding uncommitted changes – The cause is merging with uncommitted changes. – There open happens when we pull while there are some uncommitted change – Have two solutions are: • Always commit changes before pulling • Extract the uncommit changes into the file and pulling. After that imports the uncommit change file • abort: push creates new remote heads on branch 'default'! – When we push some things that will create new heads in remote repo. Mercurial thinks that is an impolite action. The best way is when pulling and merge before pushing • “abort: crosses branches (use 'hg merge' or 'hg update -C')” – Update the working revision in the different branch Eng. TrungHuynh™
  15. 15. MQ tool • MQ is the extension tool of Mercurial that manages your patches – Modify the .hgrc to enable MQ [extensions] = Eng. TrungHuynh™
  16. 16. MQ tool what is patch file? diff --git a/ b/ --- a/ +++ b/ @@ -14,6 +14,7 @@ %define is_ais_msg %(test "@AIS_MSG_ENABLED@" = "yes" && echo 1 || echo 0) %define is_ais_smf %(test "@AIS_SMF_ENABLED@" = "yes" && echo 1 || echo 0) %define is_tipc_trans %(test "@TIPC_TRANSPORT_ENABLED@" = "yes" && echo 1 || echo 0) +%define is_ais_pm %(test "@AIS_PM_ENABLED@" = "yes" && echo 1 || echo 0) %define _pkglibdir %{_libdir}/%{name} %define _pkgsysconfdir %{_sysconfdir}/%{name} @@ -541,6 +542,46 @@ %endif +%if %is_ais_pm Eng. TrungHuynh™ Diff header Hunk
  17. 17. MQ tool • Create a patch repository – Hg qinit • This command will create a “patches” directory in “.hg” directory and also create a patch queue • In patches folder contains our patches and more two files that are a series file and a status file • The series file contains all of patches name that MQ knows • The status file contains status of all patches that are applied currently • Hg qseries command lists every patch that MQ knows about in a repository • Hg qapplied command lists every patch that MQ has applied in a repository Eng. TrungHuynh™
  18. 18. MQ tool • Hg qnew –m “message for patch” <patch name> – Create a new patch with a patch name • Hg qrefresh – Save new change to the top applied patch Note: hg revert will let you come back the last refresh state. Eng. TrungHuynh™
  19. 19. MQ tool • Hg qpop – Pop out the top patch from the queue • Hg qpush – Push a patch into the queue • Hg qdelete <> – Delete a patch from a queue. The file is still preserve in patch repository • Hg qfinish ?? Eng. TrungHuynh™
  20. 20. Mercurial vs Others Eng. TrungHuynh™ From