versionControl/handOut.rst
changeset 156 8f4806a1a64d
parent 155 3efb70d2a02f
equal deleted inserted replaced
155:3efb70d2a02f 156:8f4806a1a64d
   451 ::
   451 ::
   452 
   452 
   453     $ hg log    
   453     $ hg log    
   454 
   454 
   455 We can see the history of all the commits that we have made in our
   455 We can see the history of all the commits that we have made in our
   456 project. As you can see, the logs have started getting longer (and
   456 project. This gives us a brief description of all the changes made, by
   457 hence have been dropped from the output) and may even be getting out
   457 showing us the summary line of all the commits. What if we want to get more
   458 of our screens. Also, we are not very interested in all the commits in
   458 details? 
   459 the project. We usually want to see the last few commits. 
   459 
       
   460 We can pass an additional argument, ``-v`` or ``--verbose``,  to ``hg log``
       
   461 to get the whole commit message, instead of just the summary. 
       
   462 
       
   463 ::
       
   464 
       
   465     $ hg log -v
       
   466 
       
   467 As you can see, the logs have started getting longer (and hence have been
       
   468 dropped from the output) and getting out of our screen. Also, we are not
       
   469 always, interested to see the whole history of the project. It would often
       
   470 suffice to see the last few commits. 
       
   471 
       
   472 To limit the output of ``hg log``, we could use the ``-l`` or ``--limit``
       
   473 argument 
       
   474 ::
       
   475 
       
   476     $ hg log -v -l3
       
   477 
       
   478 This will give us log of only the last three commits and not the whole
       
   479 history of the project. 
   460 
   480 
   461 Revision Numbering
   481 Revision Numbering
   462 ------------------
   482 ------------------
   463 
   483 
   464 Let us now see how to get logs of specific commits and a range of
   484 Often, the level of detail provided by the commit messages is also not
   465 commits. Have a look at the logs that the previous ``log`` command has
   485 enough. We would want to see what *exactly* changed with a commit, probably
       
   486 as a ``diff``. We could do that using **revision numbers**.
       
   487 
       
   488 Have a look at the logs that the previous ``log`` command has
   466 printed and look at the ``changeset`` line. It shows a number followed
   489 printed and look at the ``changeset`` line. It shows a number followed
   467 by a semi-colon and some long hexa-decimal string. The number is
   490 by a semi-colon and some long hexa-decimal string. The number is
   468 called the **revision number**. It is an identifier for the commit,
   491 called the **revision number**. It is an identifier for the commit,
   469 and can be along with various commands to specify the revision number,
   492 and can be along with various commands to specify the revision number,
   470 if required. 
   493 if required. 
   471 
   494 
   472 Let us now check the logs of the very first commit of the project.
   495 Let's say we wish to see the changes between revision 1 and revision 2. We
       
   496 shall use the ``diff`` command to do this. 
       
   497 ::
       
   498 
       
   499     $ hg diff -r1 -r2
       
   500 
       
   501 The diff command takes two revision numbers as arguments and gives the
       
   502 changes made from revision in the first argument to revision in the second
       
   503 argument. 
       
   504 ::
       
   505 
       
   506     $ hg diff -r0 -r2
       
   507 
       
   508 The above command will show all the changes made after revision 0 up to
       
   509 revision 2. 
       
   510 
       
   511 The revision number can also be passed as an argument to many other commands.
       
   512 For instance, we can check the logs of the very first commit, by saying 
   473 ::
   513 ::
   474 
   514 
   475     $ hg log -r0
   515     $ hg log -r0
   476     changeset:   0:cbf6e2a375b4
   516     changeset:   0:cbf6e2a375b4
   477     tag:         tip
   517     tag:         tip
   478     user:        punchagan@shrike.aero.iitb.ac.in
   518     user:        punchagan@shrike.aero.iitb.ac.in
   479     date:        Fri Jan 28 14:04:07 2011 +0530
   519     date:        Fri Jan 28 14:04:07 2011 +0530
   480     summary:     Initial Commit
   520     summary:     Initial Commit
   481 
   521 
   482 Now, if we wish to get the logs of the latest commit only, how do we
       
   483 do it? We could specify the exact revision number of the commit (2) or
       
   484 just use -1 to start counting in the reverse chronological order. 
       
   485 ::
       
   486 
       
   487     $ hg log -r-1
       
   488     changeset:   2:98f7f4a1bb4d
       
   489     tag:         tip
       
   490     user:        Puneeth Chaganti <punchagan@fossee.in>
       
   491     date:        Fri Jan 28 16:24:42 2011 +0530
       
   492     summary:     Replace all occurrences of & with and
       
   493 
       
   494 You could also specify a range of commits whose logs you would like to
   522 You could also specify a range of commits whose logs you would like to
   495 see. Say, we would like to see the last two commits, 
   523 see. Say, we would like to see the last two commits, 
   496 ::
   524 ::
   497 
   525 
   498     $ hg log -r-1:-2
   526     $ hg log -r0:2
   499 
       
   500 This is equivalent to using the following     
       
   501 ::
       
   502 
       
   503         $ hg log -r2:1
       
   504 
   527 
   505 You could also see the changes made to a particular file, in the
   528 You could also see the changes made to a particular file, in the
   506 specified range of the commits. Say, we wish to see the changes made
   529 specified range of the commits. Say, we wish to see the changes made
   507 to the ``chapter2.txt`` file in the last two commits. 
   530 to the ``chapter2.txt`` file in the last two commits. 
   508 ::
   531 ::
   509 
   532 
   510     $ hg log -r-1:-2 chapter2.txt
   533     $ hg log -r0:2 chapter2.txt
   511     changeset:   1:3163b8db10bb
   534     changeset:   1:3163b8db10bb
   512     user:        Puneeth Chaganti <punchagan@fossee.in>
   535     user:        Puneeth Chaganti <punchagan@fossee.in>
   513     date:        Fri Jan 28 16:21:29 2011 +0530
   536     date:        Fri Jan 28 16:21:29 2011 +0530
   514     summary:     Add author info to all the chapters
   537     summary:     Add author info to all the chapters
   515 
   538 
   516 Notice that it shows only the logs of revision 1, since no changes
   539 Notice that it shows only the logs of revision 1, since no changes
   517 were made to the specified file in the second commit. 
   540 were made to the specified file in the second commit. 
   518 
       
   519 You can do all of this with the ``diff`` command to see the exact
       
   520 changes made to the files, instead of seeing the ``log`` message. This
       
   521 will be a part of your exercises. 
       
   522 
   541 
   523 Collaborating with Mercurial
   542 Collaborating with Mercurial
   524 ============================
   543 ============================
   525 
   544 
   526 When motivating the use of version control systems, we spoke a lot about
   545 When motivating the use of version control systems, we spoke a lot about