 Good morning everyone, welcome back to this course. My name is Prabhu Ramachandran and I think most of you have seen me on the first day of the course. And today I will be teaching you about version control. It looks like the whole day is available for version control but we may not want to spend the entire day on version control. So I may change a few things. So in case we finish version control to satisfaction today, I may actually start off on a little bit of basic python today itself. And then tomorrow you will have latex and next week again you will have python as for the schedule so far. So let us see how things go today and then we will decide how we proceed. So anyway good morning to you all. Thank you for joining us this weekend, yet another weekend, a long string of weekends you have. So today's topic as you have seen is version control. I will try to make sure that I teach you some of the theory and then I will show you a live examples of trying to create, use some examples of version control. And I will expect that you also follow suit that is after I do an example I will give you a few minutes that you should experiment, play around and be comfortable with creating a repository and things like that. I think it is a good idea if you have any questions I will pause once I do an example or something like that I will pause at that time ask specifically for questions at that point you can ask me questions. If you have any problems in between you can contact on the chat it will be monitored and if there are any questions that you need attention maybe you can say attention we are not able to hear you or something like that so that I can stop and I get signal to property. So today as I said we look at version control we are going to use a particular tool called mercurial. Hg is short for mercurial as you would imagine. Hg is the symbol for mercurial and mercurial is the name of the tool that we will be using in order to do version control. So if you see the slides now the outline of this session is basically we will have an introduction on version control itself, motivate the need for a version control system and basically give you an idea of why we need to do version control and some idea of how it actually works without getting into the nitty gritty details just the overall perspective of how it works with an analogy and then we will start with creating an actual repository and getting our hands dirty with creating a version control repository, seeding it with some files, learning the actual workflow how do you actually use a version control system effectively this is very important as with anything that you have a tool is only a tool. So even if you have a chisel or a hammer it is only as good as how you use it so it is important that you be able to use that you be able to use these tools well therefore you should understand the workflow the question is you have tools and it is important that you know how to use the tools effectively and that is the crucial part there are millions of tools what you need to know is how to use them effectively so we will teach you some aspects of that and kind of go through some exercises on how best to do these things. An important aspect of much of open-source software is that there is a lot of collaboration and it makes a big difference when you can actually collaborate with other people on your source code these version control tools that we will be teaching you today allow for very easy sharing of code so we will teach you the basic aspects of collaborating with mercury and then conclude with a summary. So the objectives of the session are that first you will understand what version control is and why you need it you will learn how to create and use repositories on a daily basis how to clone existing repositories so clone is exactly what it means it is a clone so if I clone myself you would imagine another Prabhu next to me the same way if you clone a repository you get the entire repository and how to do this from the web we will see how you can view the history of a repository and you will learn how to make changes to a repository and commit them commit is an important technical term that is used in version control systems finally you will learn how to work collaboratively as a team and needless to say how well you are able to do all of this depends on how much you practice and what we will try to do is we try to insist that in future as you do things that you use a version control repository in order to do all of your assignments and things like that. So let us begin with an introduction of what is version control so think of it as a very simple in a simple way essentially what a version control system does is it allows you gives you a system with which you can keep track important word is track of changes that are made to files over time so basically the keywords are track changes made to files over time so as you evolve your code base or your document or whatever it is that you have it will keep track of what the changes are and it will internally keep copies and the details of how it keeps copies is not of any relevance to us right now what is important is that it keeps some reference or copy of all of this information and usually version control is best used with text things that have a notion of a difference if you have just a binary chunk of data it is very difficult to actually produce something that shows an incremental change so we have an image you do not have an incremental change to an image you can usually change the image completely typically so the notion of version control is best applied to things like text files and documents which are not binary so if you use latex which you will be learning soon you can see that you can use all your latex sources can be put into a version control you can also use binary files and version control binary files as well but the way in which a binary file behaves is sufficiently different that binary files are treated differently they are not the same as a text file but regardless the version control tool will allow you to keep track so every time I check in a new version of any file I will be able to go back in time and retrieve the old version if I want so if I want to use my own home boron solution to do this how would I do it well we all have done it many times when we write our own projects or if you look at any student's project typically they will have one directory saying my project and inside that my project they will have a in this case you have an a.out id 1.x id 2.txt pda 1.cpp pda 2.cpp pda 2.1.cp so basically the user every time they make a significant change will copy the file change the name slightly and do it and what a mess so imagine if you have a file you have a project which has 100 files if you change every file like this for every version it is going to be some 300 files already 100 files is difficult to manage the idea is the tool that we build will make it a lot easier for you to cognitively manage all of this so you do not have to deal with 100 files which revision what date for example in this case I have pda 1.cpp and I have pda 2.cpp how do I know which I modified how do I know when I modified it how do I know which other files this pda 1 so supposing I have pda 1 and I have some gda 1 do I keep track is gda 1 link to pda 1 the idea is I want to be able to build the same project which has interdependent links for example at another point in time I cannot do it because I do not know if these files together fit as one or each is in its own independent universe right I may have made pda 1 pda 2 and gda 1 for example and gda 2 but gda 2 may only work with pda 2 but gda 1 may work with both you do not know all of these things so if you have a version control system it manages all of this for you and makes it very clean so again let us recapping the issues name and changes made or not related or linked so any changes you make to a file are not linked you do not know what is the connection between one link are they all at the same time are they at different times there is no time information similarly I cannot quite track the sequence of changes on this I impose a convention saying 1 2 3 4 5 the connection is 1 2 3 4 5 right however I may have made changed pda 1 then made gda 1 and then made pda 2 which means it flows in a different way right pda 1 back I first change pda 1 then I change some id 2 and then I come to pda 2 that is one way or it could be pda 1 pda 2 and then id 2 none of this information is actually tracked the other issue is obvious but it does not scale as I said if you have 100 files it is not possible to manage this so given all this version control allows you to do the following you can track the entire history and evolution of a project so if you look at many open source projects they will even have a web interface where you can go on the web check that project and see what happened at this time what was the situation of the repository and you can actually fetch the entire source code one month back which is very convenient because I can now track the history and evolution of a project it allows us to collaborate effectively why because if I am developing say the same source code I do not have to necessarily be in sync with you every single day supposing I say this is my version I am now building all my changes with respect to a version one month from before today and you are working on the code today then both of us know with reference to what are both of us working so it's easy for us to collaborate I now know oh this change only applies to the file at that time I can now look at my file and say oh this is the actual change he's made and now add this instead if I had it if I didn't have this information I have had no way of figuring out what exactly the changes are unless I looked at every single file and the tool also typically provides a lot of other additional functionality that lets you collaborate very effectively it allows you to merge it allows different people to clone so it becomes a instead of having me to make tar balls every time if I just give a URL someone is able to make a copy of my entire repository immediately another major advantage is very often so you may have seen Firefox I think the latest version is 8 many of us not running 8 many of us are running some 7 or 6 or God knows what but 6 may there is some bug right now how do I go to 6 and then that releases over some 5 years or 2 years 3 years ago how do I now make a fix some new major security fix we have to update a patch to 6 well obviously the people who using version 6 for whatever reason so if I am able to use I have a version control system I can say okay get me the release 6 make a fix to that build that ship that so I now have the ability because I can go back in time to get files at a different point in time make changes and fix software so how does it work underneath the covers obviously every version control system has a different way of doing it but the analogy that you should keep in mind when you are working with the tool is imagine you are playing a game many of you must have played some video game or the other when you play a game you know that many smart good gamers will not play from level 1 to level 10 in one day you don't have that kind of time and even if you do sometimes it's not easy to do so many games will have what's this save save the game so I finish level one at the end before I meet that monster I save the game because I don't want to finish all of level one and then fight the monster so what you do is you play the game you achieve a point at a point that you are happy you make a save the next time you want to start what you do you start from where you save not from 0 correct you're playing a game with 10 levels you don't wear last fellow is very difficult you don't start from level 1 all the way to level 10 so you save just before you finish 10 and then you say okay now I'll fight the monster and I mean right so it's a very sensible way of working the analogy is almost direct whenever you create your source code repository you're happy with it at some particular point of time you tell the version control system saying these are files these are the files this is a working set of files that works for me and you add a message to it and you make what's called a commit when you do this the version control system knows that hey at this point of time these are the set of files so somebody else wants the set of files at this point of time they can get and as it will associate with that particular point of time a bunch of additional metadata like a log message a revision number and any other data you may want to associate so there's something called a change set if you look at hg we look at so it'll give all of that information so you're able to identify exactly the set okay so let's now move on to actually getting something useful done the tool we're using is called mercurial many of you would have heard of various other tools so there are two classes of tools there's the old class and the new classes are not quite there in the slides but I'll just tell you some history and background original version control systems are what are called the classic version control systems examples of these are like CVS concurrent version system or SVN which is subversion there are a variety of others but these are probably probably the most popular this was about five to six maybe even ten years ago but today even five years ago subversion was used a lot and these tools required access to a server in the sense that if I were to use a repository the repository was one repository that was available in a central location and everybody had to change send their changes so if you imagine I am the central repository every one of you is sending me files all of you will need network connectivity to me right however this is a problem for many of us network connectivity is a problem secondly everybody needs access to the server which means the server goes down finished nobody can do any check-ins nobody can actually make any connections to it and therefore they cannot actually commit their changes or they cannot log their changes so after a while of development distributed version control systems came about there were many of them but probably the two most popular three most popular distributed version control systems today are Git which you must have all heard about which is what the Linux kernel uses Mercurial there is also Bazaar and there are a whole host of others like old ones like monotone darks there are a variety of other version control tool distributed version control tools in distributed version control tools the idea is that your everybody's repository is their own there is no central one repository but everybody has their own copy of the entire repository which makes it extremely convenient because now I do not care about a server I can be on an airplane without any internet connection whatsoever and continue to do my work on my laptop it also allows for a lot of very easy development by multiple people spread all over the world who then later collaborate okay so the the modern tools are distributed version controls and HG is one of them Mercurial is one of them so we are using it because it is easy to learn and use we could have also use Git please note that there are some things that may be different if you go to use Git but the essential ideas are the same and if you go and read some little documentation after this course you will have enough initiation to understand oh this is how Git also is supposed to work and it is not very different so basically it is very easy to learn and use as you will see it is lightweight and I will show you how lightweight it is once you install Mercurial it is very it is trivial almost to create a new repository it does not require a server it does not require any special kind of Apache server or it does not require special configuration you have a directory you can use it as a repository essentially it scales very well things like the Linux kernel, Mozilla project all of these large projects actually use specific version control systems today Mercurial itself is written in Python and so it is also extensible in Python it is an interesting feature so how do you install Mercurial I think all of you should have it installed already okay so let us proceed with respect to installation if you are on a Debian or Debian like system I think you have to do sudo apt get install Mercurial Tatois HG is a Windows client so there are a variety of options for installation depending on if you are a red hat machine it will be something different but if you are using the live DVD it should have HG installed already so essentially once you install Mercurial this executable called HG will now be available so let us now try a little example so I am in slash TMP I hope the font is visible is the font okay big enough little bigger okay so I am in slash temp I do not type HG the command works so it says Mercurial distributed SCM HG version HG version tells me this is the distributed sorry this is the mercurial distributed SCM copyright blah blah blah okay and please note it is free software the version I am using is 1.4.3 depending on the version certain features may be slightly different so do not worry about it right now if you have it installed that is all you are going to need right now so now let us begin with creating our first repository what is a repository so a repository is basically the place where all of your files associated with a particular project is exist okay so essentially it is all your project files along with one special directory that is made depending on the version control tool you use and this directory stores all of the changes okay I will show you the details of this the key idea with version control systems is every time you make a check-in or you make a change or you tell the version control system I will tell you these when you make a commit the term commit will come again and again and again essentially I have a set of files and I commit these set of files the version control system understands that these committed files represent the state of this repository at this point in time so think of it as imagine the classroom I have some students if I want to take an instantaneous snapshot of this classroom I take a photograph now I have that photograph saved so I know where every student is sitting one day later students have changed positions I want to record this I take another photograph and I get another picture commit is like that I have kind of like a picture but in this case that is only a picture it is only an analogy but in the version control system I can actually get all the students back at that particular point of time okay I know everybody is there this was their state all of that information is now available to me in the repository so this is what commit means so what happens when you do a commit is the entire repository is kind of snapshot so I know that at this point of time this is the state of the full project it is not just the state of one file one file also is available because I know the full repository the advantage this makes is supposing I am building something like fire forms this one the one file does not exist in isolation it exists along with a bunch of others so I make that change I know that every other file is also linked to that point so it helps me keep track of that so I will repeat a repository is the directory which contains all of your files it will have one special directory typically called .hg which is hidden which will contain all of the changes and whenever you make a commit you are essentially snapshotting the entire repository at that point of time so let us make our first repository so let us create I am going to create a dummy directory my project so now I am inside this my project this project does not have to be necessarily be empty so it could have some dummy file so I will just create one dummy file since you have done bash I will write a little bash script so I have my little hello world bash script I have one file in this hello.sh I am in slash temp slash my project so now how do I create a new repository I simply type hg in it that is it I have now created a repository so where is the repository notice that there is this new directory here called .hg there is hello.sh and there is .hg let us look at what .hg contains some change log requires some store so it has internal data that is none of our business to touch so do not delete the .hg directory do not make changes to it yourself unless you know what you are doing okay so basically this .hg directory is this magic directory that keeps log of all the changes made henceforth to this repository please note that if I go out of this directory there is no repository it is only in my project that this exists and inside my project everything can be tracked I can make sub directories sub sub directories all of that can be taken care of okay so I will repeat .hg space init will create a new repository it creates a .hg directory your working directory and this .hg directory you should not touch okay it is a secret directory so now first thing is we need to learn how to use the tool more effectively there are always man pages but one very useful command is .hg status which will tell us the status of our repository okay and we will be using it a lot so get comfortable using .hg status the second thing that you should learn is how to use .hg's help system so if I say .hg help some command or just .hg help it will show me information if I want to scroll it I pipe it to less it will tell me list of available commands okay so the left hand side column here indicates the command name this is a short description if you look at .hg help command so let us look at add .hg help add pipe to less so it tells me that the option is .hg add some option some files both of which are optional and then it gives me a description of the feature of the command and the various options that are applicable to that command so it says minus i minus x minus n so on and so forth okay so recapping .hg init creates the repository .hg status allows you to see the status of the repository at this time and .hg help gives you help so I will give you a minute okay so you want me to go slow for terminal sessions okay I will do that thank you for your feedback anyway I have repeated myself enough this session so I now want you to experiment I will give you two minutes it is now 10 47 when do we break 11 okay fine so two minutes I will give you by 10 50 I will resume I want you to make to do the things that I have done number one make a directory in slash 10th or anywhere you want where you have right access call it whatever you want this my project that I have used is just the name that I have picked you can use any name you want any valid directory will work okay so there is no sanctity to my project call it anything you want cd into that directory use .hg init type .hg help type .hg status and be comfortable with using all of these commands I will give you two minutes I hope all of you are doing this because very important you actually do it now because at the end of the session there will be 10 different commands and if you have not done the first few you will be stuck in the subsequent ones which is important you know how to do this first okay so we are done with the time I am going to proceed no one has any questions I think I have repeated myself enough that it is clear to everyone anyways the test will reveal whether it has been clear or not so I will repeat again .hg init creates a .hg directory which has your entire repository .hg status will give you status information I will explain the details of the .hg status command shortly .hg help will give you information about the command yes yes you had a question as I said that mercurial is local and we do not need servers to actually connect to repositories yes but we have a unique utility called rcs that is also local and that can be used as we use the mercurial I am sorry can you actually elaborate on the advantages of using mercurial over rcs over rcs are you talking of revision control system the original rcs tool yeah okay rcs can be used as we use mercurial yes well but rcs is file centric it is not repository centric that is also local we do not need a server repository to connect it but rcs is like it is like asking a dinosaur as far as we are concerned rcs does not allow you to serve your files rcs is file centric it is not repository centric so let me explain the question is rcs is also a tool that you can use locally does not require a server it is a very valid point it is a very valid question hg is also local but remember that they are completely different beast if you have used rcs it will actually create the revision file in the same directory with one special file name rcs is file centric which means for every file you will have to do the revisioning yourself for every file which means it only is file centric it is not entire directory or entire project centric hg is project centric i make a commit it reflects the state of the entire repository rcs also typically gets in your way i have used rcs before it is a it is a clunkier tool it is a more old-fashioned tool but it is very convenient we have one single file that you are trying to revision control the other thing with rcs is it does not have all the other nice features that hg offers it is very difficult to collaborate i cannot start a server for hg for rcs trivial well you will have to build a separate server hg comes built in with it there are no models by which i can clone that easily its merge model is non-existent you have to basically use patches and merge it whereas here there is a notion of merges and if you start using git there is the notion of pull request there is a there is a lot more involved with hg and git and the other modern tools that rcs rcs is even worse than cvs basically if you are talking of a serious project people will not even consider using rcs for a project for a single project let alone a distributed version control project so it is basically not even a fair comparison does that answer your question so the dot hg is simply a directory think of it as a magic directory and that you do not have to worry about it contents do not touch the directory do not remove it and do not touch anything inside that that is the directory which contains all of the the revision control information of your entire repository and the configuration a bunch of things are stored in dot hg that you do not have to worry about it so do not worry about it it is just a directory okay are we all clear no I will finish a little more okay so I will just do one more little concept I will just do one more important thing just take five minutes is to discuss status codes and the hg status so notice that if I do hg status it prints out this peculiar line saying question mark hello dot sh what hg is telling us is I do not know anything about this file hello dot sh now instead of this question mark you can have a variety of other codes they are called status codes there is capital M capital A R C exclamation mark question mark and I each of these means something different what you are seeing now is not track it means this hello dot sh hg is not tracking you have not told it to track it hg is not magic it cannot read your mind what it will do is what you tell it to do so you have to tell it hg pay attention to this file then it will start keeping track of it okay once you have told it hey these are my files then it will tell you oh this file was modified oh this file was added oh somebody removed this file okay oh this file has a conflict and you have to manage that conflict see typically means you have to clean up this file it is a mess something happened somebody else made something you made something they are now conflicting you have to fix exclamation mark means that file is missing that file you deleted it it is missing you did not tell me you are going to remove a file if you tell hg saying remove this file he will say okay I will not bother you but if you remove it behind hg is back he will say array this file is gone so hg keeps track of what files are there you have to tell it keep track of these files so until you do that it will say I do not know anything about this file it will give you a question mark okay so for example if I touch another file it says test.sh also I do not know anything about now if I remove test.sh it won't say anything because it doesn't know anything about it won't say oh that file was removed until I actually tell it this file was you take this file add this file it will not bother about that file okay final tag is ignored so you can tell hg ignore all .out like a.out I want ignore all .out files I don't want unnecessarily have it so any question mark question mark so you can tell it to ignore in which case sometimes if you say hg status verbose it will say these files were explicitly ignored and then it will show you okay so basically the status codes are explained here and question mark currently tell us that the file is not added. In the next session we will start looking at how to add files and how to commit files I will do that in the next session there are some questions that I will answer first question is is it always needed to create .hg directory the answer is no when you do hg in it so you should never create .hg yourself when you do hg in it it will create it for you you don't bother about it as I said don't worry about .hg as far as you are concerned it doesn't exist leave it don't think about it okay so .hg will be created when I run .hg in it it will create .hg directory to the current directory that you are added when wherever you did the in it that directory it will add it and that directory is the root inside which all files will be tracked okay so I will repeat myself to end this session .hg in it we motivated the need for a mercurial system showed you how to create a repository how to find the status how to get help technically this is all I should be able to if I teach you this you should be on your own but obviously in the next sessions we will look at more details I also elaborated about status codes explaining to you that question mark when you do hg status means that the file is not being tracked in the next session we will see how to add files how to make changes how to track these changes okay so there is one more question we have to install mercurial due to which we are using hg command if we change the software naturally .hg is a software like any other software it's like your bash or sh which is why I covered installation at first in case you are not paying attention I said very clearly that hg needs to be installed you can install it on a Debian system like this Tata is hg is available on I think windows and linux as well these tools will give you the hg command tool that you can use that we have been using so far so if you are using git obviously the command you will use is not hg it will be git or whatever git installs for you okay but we are using hg for the purposes of this course remember that they will always be differences so do read some documentation before you switch to some other version control just because you know hg doesn't mean you know everything about git there will be some differences some subtle difference but the overall structure the strategy the workflow will be kind of similar be very similar so if you understand one and comfortable using one switching to another is not very hard I will just quickly repeat what we did the first part very quickly the idea is we are creating a repository and this repository will contain all of our files which we want to be properly managed as a result we need to create this repository so the way you do that is to first do hg in it and the hg command is something that should be available you should basically install mercury and the way to install it depends on your platform so we won't get into the details but most of you should have it installed so if you go to the shell and create a directory I have created my project so let me create one more I have created this new folder called junk I cd into the directory called junk here I do hg in it that's all it takes to create an ls minus a reveals an empty directory with a dot hg the next command that we looked at was hg status right now status tells me nothing I created a simple shell script I will copy that shell script now we have hello.sh in this folder now hg status tells us there is some file called hello.sh with a question mark the status code for which we discussed in the subsequent slide saying it is not tracked this file is not tracked the other command that we mentioned was help so hg help will give me a lot of information but if I want to say hg help add it will give me specific information if I want to pipe it through a pager I do hg help add pipe to less repeat that that is the command I am talking about hg help add this will give me information on the add command with all the details so basically when we do hg status it will let us know whether the file is tracked or not tracked in this case the file was not tracked one important thing to note is it is perfectly fine to do rm minus rf junk except your whole directory is gone and your repository is gone you lost everything so that directory where you have your code and the dot hg directory if you delete you have no help your repository is basically gone so but remember that I had two repositories I have my project I do not want the junk anymore so I am going to remove it so basically it is just another directory my project of course is still a repository and it still has the file I just created a the point I was trying to illustrate is it is trivial to create a new repository it does not require anything you just need to do hg in it you can create them you can destroy them it is yours to do as you please with it now obviously if you want to keep it you want to keep it safe it is your responsibility to keep it safe so you want to back it up you tar it up and put it somewhere save it somewhere if better yet would be if you are going to share this on a long term basis and it is an open source project you use any well known site there is something called bit bucket which lets you host hg repositories on the web or you can use code.google.com again they have mercurial hosting that they provide for free for open source project so if you have an open source project you can always use those to host in which case you can even delete your own repository it will still be saved upstream wherever you are hosting okay so this is what we covered I did it at length I have just shortened it when you do hg status remember that the first column gives you a question mark the second column gives you the file I showed an example where I had two files so if I do touch test.sh now it shows me two files that it has no idea about both files are not tracked once I tell the thing about hg is you have to tell it what files you want it to track if you tell it to not track something it is not going to bother about it but if you tell it to modify something sorry if you told it something then it will make sure that it tells you oh this file is modified this file is removed or this file is added so on and so forth it will tell you only when you tell it to track a particular file or if you tell it to ignore a particular file. So our next task is so let me first remove this test.sh was just a sample I am going to remove it say if I do rm test.sh please note that hg is not going to complain if I do hg status it is simply going to say hello.sh is not known because I have not told it about test.sh it is not going to give me warning nothing as far as hg is concerned that file does not exist essentially is all saying so how do we now tell hg about these files so from hg status we know that none of the files are tracked what we need to do is we need to do hg add so let us do that hg add hello.sh so hg add specific filename I hit enter no problem no errors which means it went well and now if I do hg status what do you expect to see you will see question mark has become a which means this file was just added to the repository now however all you have told is there is this now there is this new file which has been added to the repository you have not actually said you have not taken that photograph remember I gave you the analogy if I have a classroom I want to know the state of this class at this time I take a photograph we have not done that yet all the hg knows is that file has been added now I have to tell hg to say I finished adding all my files take a snapshot save it how do we do that what we need to do is we need to say hg commit hg commit if I simply hit return now it will tell me you have not supplied a username for this particular user who is using hg and it says see hg help config so essentially every time I make a commit I have to tell it who I am then it will know so and so made this change the idea is if you are sharing with repositories with other people you know which person has made which change at what time so you need to supply a username so let us see hg help commit changes to the given file given set of files notice that it has a minus u given as the username and the format is as described in the slide you say minus u first name last name email so let us do that hg commit minus u so now it is asking me to use a editor to edit the commit logs I am going to choose vim which is 4 over here I basically have an editor window vim in this case and I can add a log I can say now this is a very silly message normally you will give a more meaningful commit log remember that this commit log will be stored with this change set so you know hey I have done this so if you made a bug fix it is a good idea to describe the bug fix say point it to a url saying okay there is a bug fix here so this patch whatever you want to write it is good to keep your commit logs reasonably informative this does not mean you should write a Ramayana here the idea is you write something small descriptive that gives you a sense of what has happened now you simply save it the lines below this all of these lines will not be added all these hg fellows are just information for us to know that what it says is help message here enter commit message user it is telling me that this is the user who is making the change and here it is saying it is added hello.sh these are also if I added five files those five files will be listed here so that you know what files are being changed is this clear now I save this now if I do hg status it says nothing remember last time when I did hg status it said question mark there is no question mark now it knows that hello.sh is there and the current version of hello.sh is the version that was checked in there is nothing there is no change so hg is saying everything is fine ls it still has hello.sh so if I do sh it gives me hello word so everything is fine now so hg is happy hg status gives us information that everything is fine is this okay so I will repeat what we have done we first did hg status we had one file hello.sh which it said is unpacked and now we said hg add it added that file at which point the status said question mark has become then we committed we said okay I finished adding all my files so imagine I had put one file add it put another file add that third file add that now I have a set of files now I can say hg commit it means hg will now save at this point of time these three were the files that were added to this repository so I did hg commit it gave me an error saying you have not set the username so to fix that I first did hg commit it gave me an error I looked at the help and found that the option is I have to give hg commit minus u this full name correct then it opened an editor inside which I was able to give a message saying something additional files added this fixes some bug whatever message I want to associate with this change with these set of changes from the last time I committed I continue to commit once I do that if I now run hg status it says everything is fine and the file is there so now hg is aware of the file and I have snapshot at the system at this point now I want to see what has all happened in the repository what I can do is I can say hg log let us see what it gives us so it says hg log says change set some funny looking thing tag is some again let us forget about the tag it gives me my username Prabhu Ramachandran Prabhu at posi.in the date that is the time at which that commit last commit was made and the summary and notice that it is only some it is only given me the first line okay so if I did hg log minus v it will give me a verbose log which will tell me the entire log string that I have supplied okay so it says adding out so I made a typo adding our first files this change fixes issue number blah blah blah whatever so whatever I have typed there is now available so one year from now if I come back to this directory if I do log I know that the first commit this is what I did so it is therefore makes sense to have clean log messages meaningful log messages so later on you have to understand what these things are so the first terminology we are learning here is what is this change set so a change set this is a definition so I will repeat exactly what the slide says is an atomic collection of changes to the files between successive commits okay so if I make another commit now the change set basically records all of the set of changes between the previous commit to the current commit okay and it has a number that you see here the first number is the revision number the 0 you see here the second is called a change set id which is not of too much relevance to you so you do not have to remember this too much you can use the revision number for all practical purposes in this case okay the 0 is the important identifier you should keep in mind and as we have seen the log information gives us change set the identifier the user the date and the summary for this particular change set okay now let me do this again let me create another file okay simple file now I have hello.sh and test.sh what should I do now hg status now it says test.sh I do not know anything about so what do we do now we add this file say hg add test.sh now hg status gives us what test.sh what should hg log give me now hg log will list all of the commits not the ads so hg log will still only tell me 0 I will repeat what I did I created a file okay vim test.sh I added the file looked at the status and the log now I have to commit hg commit so I am going to use the previous commit so I can do this hg commit blah blah blah instead of going into an editor if I just have a single line I can always type minus m and give the commit log also in this one line supposing it is just a one line the minus m will allow me to give the commit message in the same that command rather than it open a separate editor however I always prefer using the editor because then I can write a nice log message but if sometimes for a single commit you can just do minus m to go slow okay so let me edit this now it is added the file I will repeat what I did clear why it is not doing this I will repeat exactly what I did I first created this test.sh so I did vim test.sh I created this file then I did hg add test.sh to add the file it got added then I did hg commit minus u blah blah blah minus m some message okay and it was committed now if I do hg status again it shows me nothing means all the files are tracked now if I look at hg log it shows me two things adding out first files and adding test articles is this clear so the first one is one this is the first this is the current latest version this is the original version is this clear so I am repeating myself many times so if you miss something once you will get the hang of it don't worry about if you just generally get the idea don't worry about it so now we have saved two versions of our project okay so there is one small problem every time it is irritating to say hg commit minus u blah blah blah blah and I have to write my full name and I have a long name so it is not very convenient to be able to do this every time I have to keep typing my name my email address so there is a file called in your home directory dot hg rc is a file where we can add our user name permanently okay so let's do that to do this I am going to edit tilde slash dot hg rc okay over here I will say add a UI section so I am saying in the UI section that is the user interface my user name is Prabhu Ramachandran with my email address I made a mistake here okay so create your own file with your own user details now I am closing this file it has this information I will give you a second to write your own give you 10 seconds so you can write your own file okay so I assume you have looked at that carefully enough that you understand what is going on now if I want to make a fresh commit I don't have to supply this minus u every time so what is with this commit what are these commits and how do we utilize these things well every commit is atomic which means it's one unit it's an indivisible thing something that's atomic means it's indivisible I can't break it down any further a commit is one unit of changes okay so atomic changes for every set of changes that you think is one concrete unit you make a fresh commit you typically give a single line summary the first line should be a single line summary remember when you do HG log it only prints the first line it doesn't print the whole line remember okay as an example if you look at HG log so let me since I made the same mistake you should not make the same mistake it should you should not have a space there I unnecessarily indented that's why there was an error it should look like this username is aligned at the left now if you look at the log messages notice on the second line it basically says it has truncated the log message and I had to do log space minus V to get the full message so a good idea is for you to make sure that you have a single line summary and then subsequent lines you have an elaboration if you need an elaboration so if it's a trivial commit you don't have to write more if it requires more detail you supply the detail in the next paragraph okay so you can say the next why the change what does it affect known bugs all of that you can specify in whatever detail you want to do and it's a good idea to have this detail because then you will be able to use that detail later on someone has added as a question about no hgrc file in home directory well you have to add one there is no .hgrc in your home directory but you will have to create one as I did I clearly showed you that you win that file save it and then you create it that file only then will you be able to use you don't have to supply the minus u if not every time you make a commit you will have to do with the minus u so let's make one more edit so let's move on and make a change firstly what is our current status hg status says nothing means everything is fine all the files are intact as against the last version they are all at the latest version there is no problem so now let me edit the file so now let me I don't like this white space and I'll capitalize this and I'll put a punctuation mark at the end this is my new version now notice notice that the file now says the status is clearly saying m you see in the first column clearly indicates that so if you go back to the slides m means modified so what it's saying is the file hello .sh alone has been modified test.sh has not been modified now if I want to save this now I can continue to make changes that I want but if I want to tell hg saying okay I am done record this currents change what should I do if I want to tell hg that this is my current state of directories that I am happy with I have to do commit so I do hg commit notice that in this time it didn't give me any error because I have set the username already and it has filled that out for me so now I can add the summary line okay so now I have given a detailed error message log message saying summary is better hello message details are they were punctuation and case problem is the previous version and now I save quit commit is done hg status empty which means now it is recorded now if I say hg log it tells me that the latest is better hello message previous one is test.sh and the last is the original commit the first commit is adding files that are initial commit so all these three versions are now recorded fully now if I want to add more files I can continue to do that I want to add a directory add a file I can continue to do that very easily with this system with the same strategy you add the file commit add commit you want to remove something we look at that in a short while okay so some questions people are asking if more than one file is in the directory is there any provision to distinguish by name in the log distinguish what by name in the log your commit message applies as a whole to all files there is if you want to distinguish between each file change you have to explicitly only commit those files or add those files okay so for example if you do hg help commit you can say commit either a specified file so if I want to say I do not want to commit all the other changes I want to only commit 3 4 this file hello I do not want to commit test.sh even though there are changes it is modified you say hg commit hello and only hello will be commit so you can do things like that however you cannot distinguish between the files once you make the commit the commit as a whole records changes to all of the files the second question is I typed hg-u your formatting of the string is wrong and it is not hg-u you have to give it as hg some command minus u and I am not sure why you are getting a waiting for the lock on working directory something you must probably have done a previous commit that is broken that is not completed and someone wants me to repeat the win.hgrc okay so I will just cat the file screen this is how the file should look bracket square bracket open ui close square bracket use a name equals use a name and email