 Good morning everyone. I am Srikanth Patnaik. So first session will consist of version control. Before we start version control I want to show you some repositories which eventually lead you to motivate how why to use version control. So let me go back to browser. So this is one of the version control hosting website and what we will do is we will see some of the good projects which which are hosted on this website. So let us see most of you know about the Linux kernel. So we will just search for Linux. So in the first link you can see it says torbles slash linux. Torbles is linux torbles who we have started the Linux kernel project. So you can see this is the entire Linux kernel source code which linux torbles and he authored a day ago. You can see he has made modifications one day before. So you can see he has updated a day before. So what is all this? Why why why this website and why this linux version control? Why these many files? What is this read me? Let we get let us get through it before that just keep in mind then these files get changed day by day every day people download people contribute it is a large community. So it is a collaborative effort in which many people contribute to this project. So let us come back to our version control topic. So we will cover these many things version control using git is our main topic today. So there are many other tools beside git that of course we are not going to cover but they are also important but git is the most widely used and most fast available version control tool which we know. So let us start with what is not a version control before that let us know what is a version control and official definition. So what is a version control when you write any document in Microsoft Word or open office you save it right again you write something again you save it. So that is also a version control let us take a simple example this is my linux terminal emulator what I will do I will open a vi editor vi is a command line editor and say I will write hello dot txt. So this will open an empty file hello dot txt and if I write hello world and I save it correct. So is there any version control involved here till now not exactly again what I decide later no it is not hello world let it be hello India then again I save it. So far all good there is no version control practically but there is a revision control you can say. So hello India is the new revision of this file how if I undo this I get hello world. So this is the previous version of this file if I redo this I get hello India. So this is the latest version of this file correct fine. So this is a revision control this we do all the time in open office in Microsoft Word in emails we save our emails in graphs etc. But this is not good enough for our source code to be managed with you cannot write your source code save and undo it to make a separate version. What happens if you deal your source code like this or your hello India or hello world program with this if I exit this editor vi editor by pressing shift z z or call and wq write and quit if I open it again it will show hello India this is the latest version. And if I try to undo it is not possible it says already at the oldest change that means whatever previous changes to this document I made just before they all get lost why because I just close the document and everything get lost. So do we want this kind of revision control for our source code to get managed we will come to that not exactly we will come to that fine. So let me remove this hello.txt and let me come back to our slides. So version control is a also known as revision control or source control is the management of changes to documents computer programs large websites and other collection of information. So it clearly states that not only source code you can manage your any kind of document. So let us see how to do it means we do not use version control by default means this should be a default practice from now onwards because this is very easy to use tool of course it is very scalable you can scale it to any extent we will see just basic of that which will get used going. So normally people get confused with version control with software versions say software version of GIMP GIMP 2.6 it is not a version control it is a version of that software. So similarly the version of open office it is 3.6 point something now. So that is not the version control it is the version of the software and that numbers 3.6 does not signify any amount of source code management done to that am I making sense. So it is not a version control. So what is a version control? Version control is a source code management tool which manage the changes to the document or source code etcetera. So I think I made very clear what is a version control and what is not a version control of course without knowing why we need to learn the software it is just wastage of your time and mind too. First of all for anything we must be motivated to learn the topic. So I think this paragraph will tell you why we need a version control. First of all with our hello dot txt example what happened suppose I remove the hello dot txt what happen if in your source code you accidentally remove a source file does it mean that your project is means over you have you have launched a critical source data if this file would have been under version control you can retrieve the deleted file also is not that good. So you can go to previous versions you can even retrieve the deleted files also which are of course under version control then only. So this paragraph will tell you why we should get motivated to learn this particular tool and use in our day to day life the first one says reversibility. So it says that you can get back to the previous state if you discover some modification you did is a mistake or a bad idea of course suppose in our case in hello dot txt we did a mistake with hello world and we just get reverted to hello India etcetera etcetera. But with the version control you can easily get the previous version even if you close the file also concurrency its ability to many people modifying the same set of files or same source code and history means you can browse and navigate the history of the changes which you made. So what we will do we will just focus on a particular version control tool known as get version control which is fast robust and most popular tool around. So if you just search for get in your Google it will give you tons of results you have lot of online documentation you have very good support you have YouTube videos to support of course it is written by Linus Torvels who is the maintainer of linux kernel which is the single largest project in the world means it has more than 10 million lines of code still adding. So if this version control tool can manage linux kernel efficiently you can think of what it can do with your simple projects. So I think these three reversibility concurrency and history in a single word or in a single statement I can say you can able to revert your changes you can go to your previous version of changes you can retrieve some lost files and you can collaborate many people to work on the same project. So this is very important third statement is very important because none of the projects big projects or small projects done by a single person even the linux kernel it is initiated by Linus Torvel but it is carried out by thousands of developer around the world. So unless a version control tool allows you collaborate with people it is not worth using okay I think this is enough to motivate you why you should go for version control and why you should go for get version control especially of course I have not given you any examples of other version control tools let me give you a few. So there is a version control tool known as bazaar and there is known as mercurial. So there are very good version control tools but they have their limitations. So we are not going to discuss those limitations here. So our first topic for today is how to make a simple hello world project with get version control okay so this will take hardly five minutes because I am explaining also that makes it maybe 15 minutes but believe me initiating a program initiating version control tool for a particular project mainly takes two to three minutes that is it. So every step is documented here so if you lose anywhere continuity you can just go back and see your file. So what we will do come back to terminal I want to clear the terminal so control L will clear the terminal for me so it says record at the red del what I will do I will just change this name and replace it with dollar sign like this again control L to clear the screen. So now we have clear Linux terminal emulator let me do LS first to know what all files are here though it is not required let me delete unnecessary files clear the screen MKDIR what is the project team hello world hello iPhone world. So this will create a hello world directory in my home so where I am PWD will tell me in which directory I am it says slash home slash Srikant so this is the home for user Srikant so you can see clearly there is a hello world directory CD to hello world. So now our present working directory says we are in Srikant hello world home Srikant hello world let me clear the screen for you so what we have done those we started a simple hello world project we created a directory we CD into the directory now as the name suggests hello world we will this project indirectly says that there will be some source code inside this project which will print hello world finally so this directory itself communicate to user that what kind of source code or what kind of project is going to be this is also a good practice to have a directory named after the project. So before starting before writing the actual code it is also a very good practice and well recommended by many experts that you start with a read me file so read me file means the read me file should state about the project that what that project is going to do what kind of application is going to host etc. So what we will do we will create a read me file for those who are not comfortable with vi text editor vi is a command line text editor what I will do I will use g edit just for just to make you comfortable so g edit read me dot rst so g edit is a graphical text editor remember sorry I forgot to tell you these tools you can use it on your windows operating system also so this will open g edit so I have a read me dot rst and I already have written a small dot rst file read me dot rst file to save time so what this read me dot rst file says let me copy first if you have terminal with you please you also practice with me it is not showing any syntax highlights let me discuss this because I want to show you the syntax also so let me get back to vi editor it is if we get time I will tell you about basics of vi later though it is covered in the android advanced debugging so vi read me dot rst I for insert so I am in edit mode now fine so let me so escape will turn off the edit mode and if I press I or insert on the keyboard it will again put me into edit mode escape get back to the command mode so you can see there is a neat syntax here so this is a rst file known as restructured text which is the markup lightweight markup language which will deal in the end of this session from 2 to 230 so this read me is significant though it is not nothing to do with the git version control but you can see the syntax of read me why this is important is I have not written a single line of code but I know what I am going to do this is very helpful for my collaborators because suppose I have added multiple people to this project then they might want to know what exactly is going through going in my mind and what exactly what I am looking for so this will say that okay there is a project known as what is this project for this project will create a binary executable file which when invoked will print hello world on terminal we will get back to the syntax of rst file later so basically this double dots will make the header this will be subheading and double star will make this text bold take bold and prerequisite says what it requires it requires a GNUC compiler that is it how to use compile the source file and generate binary executable name as hello how to do that like this save and exit done now our simple hello world project we have our read me file in place to let me initiate the git repository inside this directory before that let me clear the screen pwd I am in hello world project let me do ls-la so this will list all the hidden files also so it says no hidden files this dot means present working directory this double dot means previous directory parent directory and only one file read me dot rst so just initialize the repository here single command git init git init will initialize empty git repository in this directory then you have to do git add you might think that how I know these commands because first of all I should tell you right means these commands are listed in such and such directory etc. If you get lost anywhere just do man git this is the inner star world documentation you will find many funny lines here so this will list all the commands and their use and to get information for individual commands you can also invoke like man git init just now we did git init to initialize empty repository in this directory so let us see what is the manual entry for that create an empty git repository or re-initialize an existing one q to quit this manual page control l to clear the screen let me do ls let me do ls-la so now you can see there is a directory known as dot git which will host all your future repository files in a non readable non editable format okay so never ever try to edit these this directory this will corrupt your repository or of course you will not delete this directory for sure now the repository in place I have to tell the repository I have to tell git to start tracking the file so how many files we have in this repository only one read me dot rst so what I will do git add read me dot rst this will add read me dot rst to git repository so git will start tracking this file suppose you have multiple files in this directory it won't start tracking all the files by default you have to tell git explicitly that I want to track this file then only git will start tracking that file suppose just out of context I will make two or three files here touch is a command that will create an empty file so touch one two three will create three empty files in this repository so you can see one two three and read me dot rst is there but I have not added file one two and three I have ordered added only read me dot rst so if I do git status it won't say anything about these three files one two three you can see them it says untracked files what does it mean it means git has no tracking information git has been not approached to track these files so it also suggest you if you have forgot to add please add these files git add and file name clear and it says there are some changes in this read me dot rst which has been recently added control l to clear the screen I will remove all these temporary files which are nothing to do with our program project coming back to my documentation okay so our read me dot rst file is there so how do I tell git to make a version of it so far what I did I asked git to add this file in the repository by git add command so git add will add this read me dot rst file into the repository now I want to say because I have completed finishing finishing this documentation read me dot rst so I know this is the right time to commit this changes what I mean by commit changes means I want this version of file to be saved somewhere somewhere means in the git repository only so what I want I want to tell git that okay whatever the version of read me dot rst file is there please commit to that so git commit so now I am committing that whatever read me dot rst file is there is a version a stable version appropriate version to come back from future if required so it will open an GNU nano command line editor so it is asking for a commit message so if I want to come back to this previous version somewhere from future then I must have some text to it text associated with so that it will remind me okay this commit refers to this this text message refer to this come in that means okay I can revert back to this because this commit miss this commits will be logged as a encrypted form you won't know you will not know the content of the file unless you revert to that version so it is recommended and recommended to add a commit message so that it will tell you when you come back from the future so this commit message will look like this so you can add anything I have added a statement like added read me dot rst what else I with instruction yes your commit message should be small precise and it should save what exactly you want to convey yourself when you return to this so I want to convey myself that okay this version means this so I added this read me dot rst file with instructions to compile and execute that's it it's basically done so what we have done now we have written a commit message for this particular commit now you might be wondering why this GNU nano what is this again you don't know vi editor you again introduced with a new editor forget about these editors you can modify this editor preferences later in your git config file this is a separate topic but for time being just just accept this changes that somewhere it will open a graphical editor for you in windows or in Linux also which where you can enter these things so control O will write the file and control X will exit so it clearly states on command line that one file changed 22 insertions in the in that file plus means insertions and created a mode for that rst file that's it we have successfully created a git repository for our hello world project isn't it simple what we have done so far we have done only these three steps we have done git init to initialize a empty git repository in our hello world program let me clear it first first command we did was git init then if I do git init it will again re-initialize it so I won't do then we did git add read me dot rst again we did after that we did git commit and we have given a commit message that's it we have created a success we have created a empty git repository but is it enough like we have seen before that git has main advantage with collaborative project means unless you invite people to work on your project there is no use of a single hello world project lying somewhere in someone's computer so let's let's add people to this okay so there is a note here if you want to remove any file from git you can use git rm that file name because that is not part of this tutorial so I prefer to add it in a separate note so likewise you added git add file name similarly you can do git rm file name everything is documented don't worry you will not get lost so the more practical approach will be doing this on some server so collaborating with people doesn't mean that you will share your files via email or you will create some tar file and put it in some pen drive and give it to your friend that is not a collaboration what does git offer you when we say collaboration git offers you a centralized server on which you can upload your files in technical term git says git push and collaborators can also push to that server it's like this diagram so there will be something cloud cloud means there will be some web website on which there will be repository which we will push and this is suppose my repository working directory I will push to this server and someone else may be someone else here will also push to this repository someone else here will also push to this repository and we will have collaborative coding effort means we will be assigned multiple tasks which we decide among ourselves or our read me will communicate there is there is no particular reason that collaborators should know each other suppose I am here and my collaborator is somewhere in US and we never met we don't know each other this happens because suppose I have this project hello world for example I have something better project say I have created something a programmer 8051 programmer someone in some other part of the world has appreciated it and you want to contribute to that he don't know me it doesn't know me then what you will do he will just ask me for the request he will ask me request that please add me to this project I want also to contribute to this so I will add him see if he do something bad to that project or if we remove something I can revert back to my previous version I have saved copy so every collaborator has a complete copy of the repository so let's not move around let's concentrate our work now it is best to have a server based approach rather than having a local repository so these are the benefits you can see you can access your file from anywhere you can share with people people can communicate with you people can see your files they can comment on your files etc etc and of course if you don't like any contributor as an administrator you can manage that also so you remember I shown you one web page github.com this is one of the web page one of the website which allows you to host git projects there are many such like gittorias or bit bucket or source force.net there are many such projects but most of the open source people choose github to host their project you can see the best example is we have linux linux project hosted on this linux torbal has hosted his project on this so this gives us some confidence that's okay this website might have some value so what we will do we will create a account here I assume that you don't have account on github I do so what I will do is I will just go to my account so it will save what all repositories I have so if you don't have an account it's free just create an account initial process is to create a new repository by clicking first option next to username this is my username and there is a first option is it says create a new repo click on it even this web page is part of this documentation you can go through this also I have previously created a hello world project just to make this documentation so it says create a repository with Srikanth Patnaik and repository name remember this is important because we have created our repository locally as hello world and git github.com doesn't know about it so you can't give any other name you should give only the only possible name allowed here is hello world the name should be same suppose if I started my project from github itself that is also possible you can directly come to github.com create a new repository then it will give you some instruction that download that repository and that will create a local copy of it so that is also possible so both ways you can do so I choose to do the previous first way so this is a hello world and there is a simple hello world project you should give some description meaningful description it says is it a public or private we are open source people initialize this repository with a readme not required because we are smart people we have already created a readme created repository that's it so it says Srikanth Patnaik slash hello world and this is the link for a repository okay so now github.com shows me few options it says if you have not created locally which is which I want to convey now then it says that create a file like this get init git add do these steps push an existing repository from command line this is important because ours is an existing repository isn't it we have already created a hello world project so all we have to do is we have to add this line so what does our documentation says so a new page with two option will be displayed as we seen so just add this git remote add origin why because this will tell my local repository this command let me copy this come back to terminal pwd I am still in my hello world project this give me a confidence that I am doing right I will paste this command git remote add remote means a remote server add origin means the url you can add multiple origins https github.com Srikanth Patnaik hello world.git this is the recommended thing to do that's it I have added my remote now what I will do so we have added our server information in our local repository we have created a repository in the server with the same name we have copied the url of the repository in our local repository then what we have to do next of course we want to push our repository to server so a simple one line command is git push will do the work but as we are doing it for first time you should tell which origin you want to push so we have only added one url you can host your code on different website suppose you have created hello world project on github.com and source force dot net also now you want to push to both the servers simultaneously you can do that so in our case so we have added git remote git push let me clear the screen control l git push hyphen you origin master so it is asking me username so I know my username it is asking me password star star star star star star that's it so it says that a new branch is created master and that's it so you want to verify yes you should just reload this page control r that's it so here is my hello world project and this is my password that's it my read me file and you can see Srikant has authored 14 minutes ago so it is a time when I committed it is showing the commit time it is not showing when I pushed to the server server does not have any intelligence whatever I commit that is local to me whatever my collaborators commit that will local to them whenever they push to server then already they get merged okay if there is a some conflict between the files suppose we will come later so you can see that read me that rst file is now rendered beautifully as this file so this is my heading this is my subheadings this hello world turn to be bold isn't it good yeah one more thing you need not to open github web page every time to push changes this this is a common practice people do they the thing that unless you get online on github.com you can't push on push your repository to get this is not true is nothing to do with browser you have added your git remote add URL then you push it it will push no need to get login into github every time though it seems seems stupid to mention it but it happens okay so far what we have done we have created our hello world project locally we committed a sing we have done single commit we pushed our repository to Srikanth Patna slash hello world now I am interested to add collaborators to it someone has approached me and he want to collaborate to this project you want to contribute to this project then what I will do I will go to github.com and in the settings tab in the same repository remember in the in the collaborators tab so I know my collaborators who collaborator whose name is akash m h rd this is a temporary account I created to just demonstrate this project add so what does this signifies this signifies that my solo project now become a multi user project so I have another user who will contribute to it and mostly this user m h rd akash m h rd will create the source code for this project so my task is to create read me file and I asked my collaborator to create source code logic that is it now splitting the task and collaborator side so what I will do so you can see who am I is a command which will tell who am I means which user is says it says Srikanth so if I download the project and again try to push git will push from my user account only because it is saved here locally but I do not want that what I will do control shift t this will open a new terminal and what I will do I will switch user to akash I have created a user akash on my machine so in linux gnu linux you can have multiple users logged in that same time password for akash is I do not know so you can see the font terminal color everything changed because it takes from local bash rc bash so if I type cd it will put me into akash at the red del so you can see here pwd who am I Srikanth and here who am I is akash that means there are 2 separate users presently logged in this machine so we are not doing any mess up so let me clear it and let me change this prompt from dollar to or what I will do is let me exit from this and let me create a new terminal and I will keep both the terminal terminal side by side so it will be easy to understand ps1 equals to let me resize Srikanth's window also now we have 2 terminals side by side control l will clear my both terminals so this one is Srikanth and this one is akash so what I am going to do is I am going to create what I will do Srikanth terminal already has this read me dot rst it already of course Srikanth is admin so has this project this akash is a collaborator he does not have this files one way is I can email these files to him ok old way the other way is he can download from github so they are multiple way to download he can click on read me dot file he can copy the content of read me dot file he can save that file in his local repository as read me dot file is it that is also possible another way is he can download this entire repository as zip that also he can do but as a collaborator it is not recommended what he has to do is he has to clone this repository cloning means getting the entire commit messages logs whatever the previous collaborators have done everything will be carried out to the new collaborator so cloning is the right way to get a repository so control c to copy akash user now control v so git clone so this will clone the repository for whom for our collaborator akash enter so it will throw some error do not worry now you see ls so now you can see a directory hello world in the user akash control l will clear the screen cd hello tap completion press tap to get complete ls so he has a copy of read me dot rst ls hyphen la will also show that he has this dot git directory to that means he has the commit information which Srikant the admin has done fine so let me see what does this read me dot rst contains it basically contains the same correct so as a collaborator I go through this read me dot rst I know my job I have to create a source file and the function of source file should be it should create a binary which eventually print hello world so this is the source file let me copy this so vi hello underscore world dot c i for insert okay so this is the simple program which will print hello world on terminal so as a collaborator I have completed my work now my job is to push this changes to server back to server okay that is what the meaning of collaboration so what all steps control l to clear again what all steps we should do do we need to do git init again no because git init will create a repository again because this contain already initialize repository we need not to create again so the what we will do git add hello world dot c so this will tell local git to track hello world dot c file so now git will track hello world dot c you can check my git status so it says our master changes to be committed in hello world dot c git push either you can say hyphen you origin master or as this information is already there you can simply say git push now it will ask for username so username of whom Srikanth Patlaik no username of collaborator whose name is Akash and his password authentication failed let me try again yes thank you username is Akash mh rd is it mh rd okay it says everything is up to date let me check the server control r to reload let me check the username of collaborator Akash mh rd correct git status so this is a lesson now so git commit will open a editor mt okay now let me check the user name when a new user comes in he has to configure git for first time okay so git suggest me how to configure that so all you need to do this thing in fact this is also mentioned in your document in document also I intendedly make this error so that when you do it on first time you will get to know how to do this so git config global username you have to do like this so I am just copying this paste which say some see this username and email address need not to be same of github this is nothing to do with github this is this will help you this will help git to create a encrypted file with your username and username and email address it will create unique non-editable encrypted files this is nothing to do with github account or source for account so what I will do I will give some say some email address and name I will give Akash so now I have successfully configured my git to do git commit so let me clear the screen control l now git commit so what should be my commit message anything sign which signifies added hello sufficient enough control o to write control x to exit now the collaborator Akash mh rd has created this file and created hello world dot c file he has committed to it so now in total to this repository we have two commits one commit made by administrator who has made commit to read me dot rst the second commit is made by collaborator who has made commit to hello world dot c so git push will push this changes to github fine so done because administrator has allowed me to push back the changes so I can push now let us verify again let us click on hello world program hello world repository you can see there is a new file hello world dot c you can click on that file that will open in local repository it says Akash has committed two minutes ago he has this is the commit message of Akash it says added hello world c program that is it fine now think of a situation where I have means as an admin Srikanth Patnaik who has initiated this project has decided to modify the read me okay most likely condition I do not know what my collaborator did in the back end I do not go to website all the time and I do not check whether he has pushed or not etc etc so what I decided to do I decided to edit my read me dot rst file and I want to add this last line to it so this is Srikanth again admin of the project what all he contains he contain only read me dot file read me dot rst and what is there with collaborator he has read me dot rst as well as hello world dot c now I decided to edit this file and I want to append this line at the end thanking my users what will be my process user process get add read me dot rst there is a shortcut to it see we have not actually added a file we have modified a file so you can do directly get commit by command line flags like add all files which are modified this hyphen m will tell you will allow you to add your commit message in line so if you type only get commit what will happen it will open a text editor and it will ask to enter your commit message but I want to add all the modified files hyphen a means add all the modified files I know there is only one file which has been modified and m means I want to add my commit message in line within double quotes modified read me read me dot rst simply that is it so this is my third commit for this repository first two commits made by me one commit made by my collaborator now I will do git push so this should push my this changes to server okay user name it says error what is the error fail to push some reference to server very well why failed same thing is documented here so so this says that there are some changes in the server which are not there in my local repository so I cannot push it so git is intelligent it says I will not push it unless you both means the collaborator and the admin have the same copy of the repository only one updated file can be there in the server clear so my collaborator has pushed hello world dot c file with read me dot rst file that is commit number two the copy of that I do not have and I did not check the server and I decided to push the file what happened it rejected so now this diagram will make some sense so this is the github server so you can see the first commit is made by me admin one signifies commit number it says read me dot rst I committed to means second step git clone done by who akas mh rd third step akas mh rd pushed read me dot rst plus hello world dot c good enough then shrikan modified read me dot rst and he also try to push unaware of that there is an updated version there now what happens it get rejected now what shrikan will do what any collaborator anyone will do he will do git pull then he will do git push so git pull will pull all the changes from server and it will merge if at all any merge is required and if ok it will merge simply merge do not get into more detail so what I will do I will do git pull that is what my document also suggest do a git pull so git pull from shrikan side and it pulled and while pulling see we had three commits right the git pull will merge the both files one which if it one with shrikan pattern that hello world and the commit means the modified version of hello world which shrikan has committed that commit will get merged with the collaborators commit so there will be a new commit so git will not modify the previous commits it will not say that ok your collaborator has committed before so he has the priority so you have to merge with something like that no when you pull anything from server and you have local commits it will merge those commits and it will create a new commit so if you remember this diagram git pull will what it will do it will fetch the it will internally it will execute two commands git fetch which will fetch the changes from server and git merge it will merge the changes whatever it get from the server so it will create a new commit so the commit message is already written so if I want to add something to this commit message I can so what I will say I will say my mistake I forgot to pull first of course so this will create a new commit which is not very relevant commit though the relevant commits are what which have some changes relevant changes this does not have any relevant change this is just a merge why because of my mistake I forgot to pull control o save control x to exit now I will do git push now if you see ls now the who am I I am streak on the of course admin so I had only read me dot rst but after git pull I get the changes of my collaborator also who has created this hello world dot c and of course my modified read me dot rst also the git push that is it so now the latest version on github.com is my merge commit commit number four does collaborator has this copy no you understand collaborator does not know about my merge does not know about my modification done to read me dot rst what the collaborator should do he should pull the changes so let us go to collaborator account and let us see what all he has he has the read me dot rst with with no greetings at the end then it is a good practice to do git pull all the time when you start doing some meaningful job so git pull will pull the changes and the changes signifies clearly that there is a commit and there is a merge so one file has been changed one insertion the insertion is the last line that is modified by admin now if you see what is read me dot rst thanks for using our hello world program so collaborator also has the updated copy so now we can say collaborator administrator and the github server all have the same copy right so the second aspect of version control we will see now which is reset as I mentioned earlier you can revert back revert to previous version if you have made any changes that is the beauty of version control like we have seen in our first file in that hello dot txt once you save and exit the file you cannot undo the changes but with version control you can easily get back to your previous state of the file or if you are in a previous state if you want to go to the next state that also possible you will just see that to know all the commit history there is a command known as git log hyphen all hyphen hyphen all space hyphen hyphen graph this graph is not much significant to us this graph will show a dot means this will show a plot so these action means this git reset I can demonstrate on either way on admin side or on collaborator side because both have the same copy now this we know so control L will clear the screen who am I I am Akash so what I what I will do git log hyphen hyphen all so if you do not know how this flag came what you can do git log hyphen hyphen help this will display all the help commands associated with git log or optionary you can do man git log this will also point to the same help content q 2 quit this page now let us do our git log hyphen hyphen all without adding a graph attribute let me unzoom a bit so it will display all the commits so it would be better if I could place all the commits in a single page so basically git this is my command so the top most entry will be the latest commit so the commit hash you can see this is a hash of that commit which is created from the user name and user name an email address provided by Akash while configuring the git not the git have user name password but the git local git configuration so latest commit shows that there is a merge of this hash and this hash so these are 7 digits you can count 1 2 3 4 5 6 7 so only first 7 digits are sufficient enough to point a particular commit you can you can point a particular commit by referring to the entire entire hash but it is sufficient to mention only 7 digits of each commit hash to point to that commit that is not relevant immediately but we will come to that so this is my latest commit I have selected it you can see it says merge author shrikan because shrikan has pulled and merged it date and this is my commit message shrikan's commit message so it would be better if I select up to here so it says by mistake I forgot to pull first this was my latest commit if you remember so before that there is a commit by shrikan only that was third commit which is a modification to readme.rst so this git log will show all the logs all the commits which is there in the repository this could be thousand this could be 2000 also fine so let us get back to our document so it says git log hyphen hyphen all hyphen hyphen graph let us see what does hyphen hyphen graph will show you graph will make a small text based graphical interpretation that who has done what you can see it says that this is a merge here and this is a commit done by akash and this is a separate this is a master branch this is a main branch on which administrator is working admin is working and someone has cloned here who is someone someone is collaborator who has cloned from here and he had made a commit what is his commit he added a hello world dot c file then his commit got merged here and so this is the latest which is common to all collaborator as well as administrator so this is a graphical pictorial representation of all commits and all branches etc q to quit now we will use the feature of git to get back to a previous version so which version we want to reset so this hash will not be present in this file because this I created two days back and that time my file and my content probably little bit different so just replace this with the commit log hash which we have now so to simply move our head means the latest commit technical term is this a head to simply move your head to commit corresponding to read me dot rst that is our first commit remember our first commit is read me dot rst which admin did if you want to move to that what you have to do git reset hyphen hyphen hard and that commit hash that commit hash you will find from git log so let me do git log again so you can see added read me dot rst with instruction now the commit message make some sense isn't it so can you remember out of nowhere if you have two thousand commits in your repository and simply point to what you want to mean without knowing the this commit message is it possible difficult so I can recognize my commit with this commit message now so what is my first commit message added read me dot rst with instructions to compile and execute this make sense right so I will take the corresponding hash entry it is not necessary that you copy exactly seven characters okay you can take some like this not an issue it should be minimum seven copy q to quit now I will do git reset let me clear the screen so that git reset hyphen hyphen hard and my commit hash so it should take my version back to first version it should discard everything else that means there should be no hello world dot c file in the directory it's not that means it should not have the modified version of read me which I did in commit three that's verify you can do cat also see it doesn't have that what does it signifies signifies that if a user in future thinks that whatever changes he has done to his source code or project they are not going well he want to get back he want to choose a previous version which is more meaningful he want to start from here not from some other version he can just do git hyphen hyphen git reset hyphen hyphen hard and that commit log hash and you can get back here okay this this has been done where on akash akash user so does administrator know about this no unless akash user push this modified version to github server the administrator won't know okay so to push the changes to server what you can do is okay you can you can check the git log again so it says there is no commit changes right we haven't done any changes to commit message instead of all all will show the all commit messages so far but we want to know what is my present state of log message for that let me clear the screen git log so git log will show the present state of the commits not all the commits from the entire repository from day 0 so it is showing me only one commit is true because I revert to this version by telling it that do a hard reset and come back here so if I know what is there now it shows me only this commit okay what about the other commits suppose later I realize no no no again I did mistake I want to get back to that version in which my collaborator just had added hello world dot c I don't want my modifications I want that version in which my collaborator has added hello world dot c so how to get back to that version simple you will do git log hyphen hyphen all because you know all the list of commits so this is the commit I was looking for this says author akash added hello world c program now I am where now my commit because I did a hard reset I revert to this version now I am here I am this version now I am here means once one version back now I want to go one version ahead of me by because I want to know I want to have hello world dot c also what I will do I will just copy this randomly more than seven has is control I will clear the screen up arrow will show you the previous commands so git reset hard instead of this I will paste my relevant commit hash now it says head is now at added hello world dot c how to verify git log git log will show you the head is at head means the latest commit latest commit is hello world dot c now how to verify visually you can see your hello world dot c file here right so suggested reading comes here so this is the official git hyphen scm documentation you can browse this there are many there are really good tutorials and examples here there is a book free book this book is pro git and if you want to practice git online there is a try dot github.com which allows you to practice these commands online also so that is all about git we will discuss about the about your questions during our discussion session.