 So I am going to move on to the next, I will come back for questions. So the first question is why do we have to do all this commit business, why cannot not be automatic? So as I said at the right at the beginning, Hg is only a tool, it provides you certain functionality, it is up to you to use the tool effectively or not. So it is up to you to make sensible commits. The reason you make commits is there are several reasons, so every time you make a commit, that state of the entire repository is saved, so I can go back to that point. So every time you think that this state is worthwhile remembering to commit it or it is an important change, you commit that change. Now you may say what is all this, I have to unnecessarily add a file, I have to commit a file, but remember it is only two commands, you add, you commit, okay. Now the advantage is to this is it makes it very easy to go back in time, so it is just a little bit of discipline and it is not a lot of work and once you start getting used to it, it will become automatic. So do not think too much about it being a pain, oh I have to keep doing this commit business, it is not at all that difficult. And soon you will see the benefits of why you need this. Now supposing you have a set of files, I will skip this slide, I will come back to this in the next slide. First thing is I now make a change, everything is fine. Now let me change, okay I have just added one more line, change the previous line. Now if I do status what should I get? I should get modified, only test.sh is modified, obviously I did not touch hello.sh. I now want to see what has changed, right. I can do hg diff, this gives me what is called a diff of the text file, it is telling me that the file called test.sh is modified, the original time was this, the new modified time is this, these are what are called context lines, it tells me in which location these changes are there and it actually shows me this line is gone and these two new lines have been added. Am I making sense? So the diff actually tells you what is the changes to what lines and it is very clear to see this. Now I can choose to commit this or if I do not want it I can go back and say hg revert test.sh. Now what does it do? It has created a new file called hg test.sh.orig of which it does not know anything about, which is your newly modified file. So what did I do? I did hg revert test.sh and then I did hg status, it is now saying test.sh is the same thing. So let us see. So this is the original version that I had added but test.sh.orig is an untracked file that contains my new modification. So if I do not care about it I can simply say rm test.sh.orig. So basically the diff command shows me all the changes since the last commit. Revert will undo all changes you have made to all files compared to the last commit. It will restore your files back to the original state at the last commit. So if you say I was just playing around with these files I want to forget about it. Just do revert. If you do revert minus, minus all it will revert all changes that you made. If you give it specific file names those file names alone will be reverted and for every file that was changed it will save the equivalent file name.orig also. So that in case you want to unrevert your revert you go back and read the origin files and copy paste it back. Is this fine? Okay. Now we have done all this commit business. What is the use if I cannot go back in time? So the first thing that you can do is I want to now see what is the difference between revision 1 and revision 2. So if I do HG log there is revision 1 which was adding test.sh, revision 2 which is better hello message. I now want to see the difference between version 2 and version 1. To do that I do HG so I can say minus r 1. So I typically diff will always tell you what is the difference from the current version to a previous version that I specified. So if I just do HG diff now what will it give me without any arguments the difference between the current and the latest is nothing so it will give me empty. Is this clear? But if I say no give me the revision difference between 1 and current it tells me I have made this change hello world I made H capital and added a full stop. Is this clear? Now supposing I want to see the difference between some two specific versions I can say minus r 2 minus r 1. So as an example I will create another version HG status modified HG commit HG status HG log now I have four versions I have the original version I have version 1 when I added test.sh I have version 2 with a better hello message and I have version 3 with new edit to hello.sh correct. I have four versions I want to now say give me the difference between current version and original version. So I can say HG diff minus r 0 hello.sh give me the difference for this file. So it says that from 0 to now these are all the changes I have added have a nice day and cleaned up the error message and removed one new line between this line and this all these changes it records now I say I do not want till version 0 I want till the penultimate version which is I think 2 notice that it only shows me the difference between that version and the rate. But now if I want to say no give me the difference between 2 and 0 that also it will take. So basically it is easy for me to figure out what changed in every file or a specific file so I can also do it for all the files if I do not specify any file it will list for me every file. So the first listing here is hello the second listing here is sh test.sh so I will repeat this the whole point of doing commits is that every commit is saved the entire repository state is known at that point of time. So if I want to see the differences I know I can use hgdiff but if I specify a specific version number that version number can be passed as an argument and then if I do hgdiff minus r1 minus r2 it will tell me the difference between 1 and 2 there is another way by which this can be specified which is hglog minus r number colon another number so you can use that syntax as well. So now you can start to see the advantages of using version control. So what I will do now is I will illustrate to you a bunch of additional features from the command line itself. So let me add some junk.sh or why do that I have these 2 files status is clean supposing I want to display just the first the last log message. I can say hglog minus l1 it will only show my last log message. If I want to say give me the last 2 minus l2 will give me 3 and 2. So now this is the state of my repository now let us say I remove the file if I do hg status now it should tell me something is wrong it is basically telling me this file is missing. So if you go back to the status line this file is missing how do I get back that file it is gone. Fortunately we have version control I can say hg revert it is back I change the file I removed it I am saying revert and the status is restored it still says now everything is fine is this clear. So I can basically get back a file if I deleted it how do I say move this file so let us find out I do hg help 5 to less I can use rename I think there is an alias for it to mv. So hg help rename notice that the alias for rename is mv which means instead of rename I can say mv also am I making sense. So now I want to I do not want to call test.sh test.sh I want to move it to what should I call it any suggestions from the audience new test.sh okay. So I want to call this hg rename or I will say hg mv I am lazy test.sh to what is the destination okay hg status what is it saying it is saying test.sh has been removed and new test.sh has been added it does that automatically. Now if I want to make to save this snapshot what should I do commit so I do hg commit so now we have change set number 4 which renames test.sh to new test.sh is this clear so now if I want to see the difference everything is logged if I want to go back there is another command which I will come to in a short while which will let you update your entire repository to that version I can see all the files at that point of time. So now let us see status everything is fine I now want to create another file and I want to remove it say I do not like this test.sh new test I do not want it is waste I want to throw it away. So I want to say hg rm now it is removed it simply says new test has been removed now again what should I do to make this to fix this commit. So now I have my entire project history up to this point of time now how do I go back if I want to now get what are the versions we have I have 4 5 4 3 let us say I want to go back to version 2. So there is this command called hg update let us look at its help. So the aliases for update are hg up up up check out or c o what this does is it allows you to update the repositories working directory to the specified change set. So it is important that there is little more to this than just a revision number there are things called branches in mercurial which we have not yet covered so we will look at that later. However right now I want to go back to say version 2 how do I do that I want now I may have hundreds of files but I want to get the status I want to see all the files at that point in time. So if I do hg update if I just do update it will say nothing because by default it will assume you want to update to the latest version. But if I say hg update I have to specify a particular change set so I take this I copy that sorry you do not need this you just need to hg update to remember at the current version there is only one file I remove new test I remove test all of them are there should only be hello but now what is there let us see two files are there and remember the current version of hello.sh has hello world and something have a good day or something like that second line that is gone. Now if I want to go back I can do hg update now do you see the power of committing so every time I make a commit I can go back to that point in time so I say at this time the project was working I made some mistake today 10 days ago I know it was working I want to rebuild my entire source run it I can rebuild it run it figure out then I can say that time I made these 10 changes look at the diff between that version and the current version and say oh this mistake I made here fix that mistake and now you can figure out so the nice thing is because you snapshot it in time I can go back in time and revert from my mistakes not using the revert command but I can figure out what mistakes were there and then fix those mistakes upstate so I am able to go back at any point look at all of the files so unlike in RCS there is no notion of the entire repository okay so there is two terminologies that I have not quite elaborated in on this directory that I have here this my project directory is called a working directory the repository information itself is inside the .hg directory the thing about modern distributed version control systems is your working directory itself contains the entire repository unlike in the past when the repository was somewhere else and your working directory was local right now everything is in one place which is extremely convenient as you can see just open a directory put files in it and you can start version controlling that entire directory you can also make directories for example I can say mkdir okay now hg status it says I do not know anything about test datasets I can say hg add test dataset same thing that you did hg status we will say it has been added hg check in ci is a alias for commit so here I have done I have committed it on the command line I did not have to open an editor because it is just a single line so I say hg commit minus m give it a string in quotes now I have this and notice I have the directory so if I do hg update to the directory is gone hg update directory is brought back so the nice thing is I can go back and forth it make sure that all of the stuff that you have added is taken care of so if you have not added files hg cannot help you so this is the reason it is important that you learn to make this a habit you add the files that are of relevance you come you commit them and every time you think there is an important change you make the commit so remember supposing you have a version control system you made lots of changes you changed over the last month you have been making changes regularly to all your files but you did not commit them then no one can help you hg will not be able to help you so it is important that whenever you make a change that is significant that you make a commit with a suitable commit message only then can hg help you if not it can only help you till the last time you commit so commit early commit often okay so I think now you have enough idea of how to create a repository how do you do that hg in it hg status will tell you current status of the repository hg log with an optional minus a l number of log messages you want so minus l say one hg add right file name hg add and put them in comments so you can see them hg commit with an optional minus m and then again hg status then hg diff with an optional minus r version number colon some other version number or minus r 1 minus r 2 something like that what else did we learn hg update very important no hg revert before that revert then we looked at hg update update without any arguments will get you to the current state the latest version or you can say either minus r revision or just give it a revision number it will update to that revision number and the revision number is the first part before the colon then what else hg mv slash rename some some file hg move some file to some other place okay then we had hg rm file name so the one issue that I have not discussed with some of you asking me as a question is hg revert is not working first thing is when you say hg revert is not working generally it is a good idea to give an error message so let me do something let me let me recreate the problem hg diff is saying I changed the dot to an exclamation mark right now I want to do hg revert it will give me an error hg revert has to be explicitly told minus minus all if you want to revert all files or explicitly specify as individual file the reason is if you accidentally hit hg revert finished all your changes will be gone so they make it safe for you today if you do hg revert sorry you did not specify any files so you do hg revert hello.sh then it will work okay the next question is how to check specific log info about changes I do not know I think you know enough shell scripting that you can figure out how to do that use grep so hg log and grep for that substring if you are interested in something usually many of these version control tools there are tools to do the visualization with a UI there are plenty of tools I do not know if this has been installed unfortunately it is not installed on this so there is something called hg view which needs to be installed so if you notice there is this package called hg view is this on the internet so what did I do I wanted to use hg view there is this package called hg view which will give you a view command that you can run from hg and will present a UI I simply did I have to get installed hg view for those of you who are not able to follow what I did I will just put it on a comment so you can see it now if I do hg view hg view it will show me all of the so this is now the original version this is the change log my screen is little small so adding out first files so it is just added these are the files that have been added the second commit has adding test.sh the third one says look at the diff it is showing me clearly these red lines were removed the green line was added fourth commit shows me this and remember if you have changed multiple files it will show you all of those multiple files then this one simply was a rename new test was created this removed new test this added a test directory so all of this can be viewed so typically you will use some kind of a tool either on the web or on the console like this and they are very useful in order if you have a large number of changes you can do a bunch of things and these tools will typically also have options that you can do commands various things depending on the tool there are variety of tools so there are some questions let me answer them first can we discard any revision completely the point is you do not want to do that the whole idea behind revisions is you do not want to destroy a revision keep it what do you lose okay so if you do not want a revision do not use it but the point is you want to keep track so you want to know that time I did this and I trust me I have used revision control for many many years I do not know if I have any time when I have wanted to destroy a revision completely unless it is a public repository and you put some code that you do not want even there once you have made it public it becomes very difficult to remove it completely because somebody else may be referring to your change and if you remove it their reference is gone so it is a bad idea to remove anything there are some things that you can do to cheat to maybe edit it but it is I am not going to teach it because it is simply too advanced but the idea is you are not supposed to be removing any revisions the whole point of a revision control system is that you keep all of the revisions okay the next question is once a file has been removed it cannot be retrieved using HG revert yes it cannot be see once you remove once a file has been removed and committed remember if you have committed it you can only go back in time and re-add the file right if you removed it instantaneously so if I say now it will do now it is recovered so if you have changed made it a commit then you have to go back get the previous version which you know how to do go to update minus update to that revision grab the file save it somewhere else and could put it back you can do that that is not a problem at all you can re-add the file back in next question is how to change the editor option typically what I do is I set the environment variable editor so I set it to win export editor equals emacs say it will use emacs for your editor so if you want I will repeat all the commands we have done so far so what is the first command we encountered in it the second command we encountered was what is the second command status thank you third command help very good then hg add files hg commit minus you notice that if you specify specific files only those will be committed if you do not specify anything everything will be committed next command hg revert log any options one option that we looked at was minus l number then next one so somebody has asked me a question hg log specific file specify the file and if you have questions like those you should always consult help hg help log will tell you what and all log can do obviously I cannot cover every single thing so if you have doubts of that nature I mean how do I do this how do I do that it is a good idea to just check with the help documentation okay then next what did we do hg revert right this you could say minus all dangerous or files then what did we do hg diff very important minus r then hg update revision number and then hg move or rename what is that then we said hg view or install apt get install hg view okay different tools are there there is something I used to use called olive or olive GTK there are a bunch of tools each will have its own advantages and disadvantages okay so you have the tool you pick for visualization and all that is kind of out of scope but just understand that it is convenient sometimes to be able to view very convenient so we have a large project we have a lot of changes it is very convenient to say over this is what however remember that the power whole thing is there in your command line command means you can do everything from the command you do not have to really use a UI and it is always useful to know the command line to know what are the options. So you can see that there are lots of options but it is not too many bulk of the time you will spend with okay in it is done only once so you hardly spend time with in it you spend time with status a lot help a lot easy log is very often used then there is commit which is very often used add reasonable every time you add a new file similarly MV and RM are used whenever you change update depends on your needs I have not used update too much personally because I keep moving ahead rather than going in the back if I need anything in the past I can always find out the diff and then figure out what is wrong. So typically you are using two or three commands you are committing adding and that is bulk of the time you are only doing those operations so it is not very difficult it does not add a lot of overhead second question why is error waiting for lock on working directory coming well I do not know it looks like you have made a mistake in your one of your previous HG commands has not completed and your HG is basically locked up I would suggest you wipe out the directory maybe there is some hung job or something you have look at the processes I do not know how you manage to get into that state it could be that you tried to commit it broke something did not work and it is HG is in one funny state I have never run into this issue how many commits can be submitted simultaneously next question there is no notion of commits can be submitted simultaneously every commit is atomic as I said a commit is an atomic set of changes so there is no committed continuously how many at one time there is one commit after pressing commit all my HG commands are showing parse errors. So that means it is likely that your HG RC is wrong so I will simply cat my and please use GR that is how your HG RC should look I have cat at it make sure it is correctly formatted if not you will get parse errors on what topics will we have multiple choice questions I am surprised you are asking me this questions on every topic under the sun we can think of we will ask you questions I will make sure we ask you questions that have not been taught in class yes we will ask you questions mostly I think it makes sense for us to ask questions about what we have covered today. REC has asked me a question give example of using plus symbol using HG diff I do not understand when you look at HG diff it prints a plus symbol for every so let me show you HG diff minus R okay so let us look at I have now done HG diff minus R0 to 2 hello dot SH what this is showing me is the difference between version 2 to the original version of hello dot SH minus signs indicate lines that are removed plus signs indicate lines that have been added okay so the next question is how memory management is done with HG you mean to say the hard disk management if you are saying hard disk management every file is different version control systems have different strategies what they typically do is they store the differences they do not store the entire files except for binary files in the case of a binary files very often it is difficult to make a meaningful diff therefore they will store the entire file otherwise they will store just the differences only the differences so it is actually fairly optimal and if you look at large projects say the size of the kernel it is actually very efficient the entire kernel repository can be downloaded by anyone and it is not that inefficient so it is actually they spend a lot of effort making it efficient so you do not have to worry about memory management because disk space is almost trivially cheap today so you should not be worried about the memory that way HG commit is waiting on lock on working directory I would suggest if you are running into that problem check your processes make sure there is some commit command that has not failed in the past and make sure that has been fixed if not create another revision control directory and start afresh next question is any other version control mechanism which is graphical there are plenty there is Tortois HG there is Olive GTK there are plenty and Google will give you plenty of hits on that revert will only give you the updated permissions that were checked into version control everything that was done in the last check-in is available and that will be restored the next question is if one user changes file permissions if we take difference in next version it would not show the changes in file permission file permissions are also locked so if you change permission it is going to it is going to it is going to version that information as well if I remember correctly it does soar the permission information as well so what is the there is no doesn't seem to be any issue with there well it won't show you when you do a diff it cannot show you the diff in the permission but it is there in the repository so when you get it back it will tell you and collaborative work this is never an issue really with collaborative work with being for file permissions are the least of your problems in collaborative work okay so let me interact Don Bosco College Cahati correct so the log message is not going to show you permissions the log message is only going to show you the change log that was made there is other information that is necessary that may be available that the log may not show you but the information is there in the HG repository okay so don't worry about the permission changes that were made to a file are not of relevance typically when you are doing version control the idea is you want to keep track of the changes to the files the contents of the files the permissions are really secondary in my life I don't think I have ever had to worry about the permissions of a file I am telling you honestly I have been using version control for the last 10 years there is definitely a case for it I am not denying it but it is not primary and the log file is not going to tell you permission changes it is not necessarily even going to sometimes tell you the details about what has changed typically a graphical tool or something like that will tell you more information but log by default doesn't tell you every single detail is not going to tell you yes so the HG is a content manager it definitely is a content manager in fact content is the most important you are getting a parse error so I think you are I think you have not typed it properly in that case typing cat tilde hgrc hrgc is not going to help you I am just catting my version you have to edit it and make it look like my version cat I am just showing you what my file looks like and please don't use my username change your username to your whatever your name is and your email address typing cat.hgr not hrgc hgrc is only going to show you the listing of that file cat is not a hg command edit that file change it to reflect something similar to this see this lock on working directory again you have basically there is some command you have run so let me try to make that same mistake yeah what I did was I made a commit and I control z from my editor which means the commit it's trying to commit you have not finished editing so it's locked up okay so you control see your hg update your foreground whatever process you are having finish that and now you do hg update it will work so basically you are having some commit that is uncommitted because you made a mistake if you fix that it will work if not throw away the directory you are working on and do it a fresh on some other directory okay make fresh files and do whatever you want the afternoon will maybe go through an exercise of creating content removing files etc. so KJSM other than username which information please read the manual please search on Google there is plenty of information available on all of these details what and all you can add there are many things you can add there is authentication there are aliases there is a bunch of things that you can add there are specific project related data you can add in hgrc so please refer to the help and the documentation I think you can say hg help config and it should tell you a lot more information so one question someone has asked I think tinjru has asked please explain the first three lines we getting after executing hg diff so if you look at the shell hg diff minus r0, 2 I will pipe it to less so we can see it clearly okay I will look at let us look at hello so by the way diff is a general unix command it is a standalone command also hg diff is presenting you a diff but diff itself is a command that is available on unix so the first three lines to want an explanation the minus minus is telling you what line was there in the original file the plus plus plus is basically saying any line you see with a plus here refers to the subsequent version okay so for example if I did I think this may work now it is gone the reverse now it is saying a is minus minus minus which is the 12 o'clock version b is 11 o'clock because I swapped the two version number okay so the order matters so 0 to 12 means what is there in 2 0, 2 means what was there in 2 is now compared with what was there in 0 what is there in 2 is compared with what was there in 0 so what this is saying is b is 12 o'clock a is 11 o'clock file which is that revision 0 revision these were the lines that were present in the first these are the lines that are currently present now and these three lines are not there the rest of the lines are there this third line is a special magic diff line which gives you which gives diff context information it is saying that it is roughly around the first line after the first line these kind of changes are arising okay so the diff file is simply it is a well known format you can also man diff itself there is information about what diff does in general outside the scope of hg so diff is please note that hg is also giving you a diff so it is a it is a it is a general file difference structure that is used not a structure a command that is used to generate these diffs the good thing about diffs is you can use a diff to what is called patch a file so given a diff I can apply the diff to a file in order to bring it to the new version because it has essentially recorded all the changes remove these lines add this line okay so one more question is if another user of the group changes the file how that changes are reflecting the law so we will be talking about collaborating with mercurial in the subsequent session this session so I will answer the this question later on but for now what we will do is I will give you a little exercise I want you to do the following I will put it in comments here create a project directory number 2 initialize hg repository create a simple hello okay it is a little complicated the last few steps are you have to think a little bit do not just blindly do it the first few parts are easy the last the last two steps will require you to think a little bit okay so I will give you about 10 minutes you please do this if you have questions you please send a message on chat and I will answer so I will repeat the question create a project directory then inside that project directory initialize a hg repository create a sample simple hello world shell script to whatever you want inside just echo hello world will work anything you want check that in create another script call it any name you want check that also in examine the logs you should at least have two commits then remove hello.sh check the removal remove money you do not obviously you should do Rn use hg to remove it check it in get back version 2 copy the file hello.sh back into the repository and these steps I am not telling you the answer you have to think about it and do it based on whatever I have thought it and finally check back the new obtained version into the repository okay I will give you a hint for number 10 and 11 you have to update and you have to update carefully remember you have to add the new hello.sh to the latest version so please finish this assignment and then we will ask I will answer questions I will give you 10 minutes 230 sharp I will work through the solution and if you have doubts I will answer them or I will answer some basic doubts and then I will show you the solution. So I hope most of you were able to execute the tasks should I show the actual workflow okay some of you are getting this parse error please if you are getting parse errors make sure that your user name looks like this you have to say user name space equals no quotation marks and you have to give the email address there so let us see if I can make a mistake here and show you I have made it this it works even if you just give your user name like that it should work there should be a new line at that so if you have not done it properly the option is you say hg touch hg add touch if you are getting that parse test that is it hg ci minus u if you are lazy to create that file that also works okay. So if you are getting into these silly errors and getting stuck use the minus u flag to pass in the argument like what we did first okay make sure do not make mistakes oh sorry someone is asking what is ci ci is an alias for commit I am sorry hg help commit alias is ci okay so ci is the same as commit I have become used to typing ci so I am sorry it just comes naturally okay so let me solve your exercise okay so I first create a directory test cd test hg init then then I do hg add hello.sh then hg commit minus m hello.sh so I am just being lazy you should actually type a proper log message you do not need to pass the minus m it will open an editor and you can type and save and quit in that editor then what is the next command check in another shell script so win test.sh okay so now I run set test.sh it works I am happy hg status I have to add it hg add test.sh then hg status added so then hg commit then hg log I have two commits okay which is what I was asked to do then step number 9 remove hello.sh 8 and 9 hg rm hello.sh hg commit so step number 9 is done now I need to extract the hello.sh from version 2 and copy it back version 2 and version 1 I meant the second version which is actually version 1 now I do hg update 2 no sorry hg update 1 to give me the second version that gives me hello.sh so I copy hello.sh to hg now I need to update to the latest version I do not have hello so I do cp now it is a new file so I do hg add hello.sh hg check in so we are done so it just takes a minute and I am able to revert I am going to go back recover a file that I deleted accidentally or whatever and get it back from the dead so let us now look at one simple thing hg log hello.sh so the only real version of this file is revision 0 let me make a change notice that hg is smart enough to realize that your hello.sh that you added back after you deleted has not shown up in another revision why because hg knows that the original hello.sh and the one you added in version 3 are identical so it does not really care it does not have to make a store of that however if I check back version 3 I will get back the file and notice that it still remembers that it was the original hello.sh and it shows you the log for that a 0 even though it is a fresh file that I apparently added does it make sense so hg is kind of smart it knows about the file it knows about the history and when you add something back with the same name it knows what minimal set of change sets it needs to remember to generate that file therefore it is a smart system it is not a stupid system therefore it is a good idea to rely on using the system effectively and not worry too much about is it doing it correctly is it not doing correctly you do not have to worry about it okay so with that we have done a basic introduction to hg and using hg and typically this much is enough if you want to get started using mercury and for many of us we do not have to collaborate there are many things that you do you may write a document may write a tech file you may be maintaining some personal documentation you may be maintaining some html pages your website your source code all of which are personal they are not relevant to you relevant to anybody else so there is no question of saving the content to anybody else or sharing the content with anybody else and interacting in such a case it really makes sense to be able to be doing things on your own machine and which hg makes it very easy to do so if you have on your computer hg installed you can use version control you do not have to care about collaborating with somebody else and you get all of the power of a distributed version control so before we move into collaboration I want to discuss one very simple fact about hg repositories notice that this test folder contains our hg repository this test folder technically can actually be copied directly so if you tar up this test folder and give it to a friend they will have all of the contents of your files along with all of the history that is the point of a repository a repository means that it contains not just the working directory which is all the files hello dot etc it also contains the history of all of those files so they can do everything that you have been able to do up to now in that directory the reason this is possible is because that dot hg directory