Second commit, and then let's check out the log.
If you check out the log,
you'll now see that there are two commits in my git repository;
the first and the second commit,
and note that each one of them is given a different number there.
If you want to see the full details of the log,
you can type simply,
git log, and then you will see
more details in there than what you would be interested in.
So, notice that the one line commit only
gives the first few characters of my commit number there.
That is sufficient enough for us to operate with.
Let me now go back again to my Visual Studio,
and just add one more line
to my index.html file.
So, now my index.html file has been modified.
Let's save the changes.
Going back to the command line,
doing git status shows that the index.html file has been modified.
So, let's add this to the staging area and then do a third commit.
So, let's say git add dot git status.
Now, you'll see that the index.html,
the modified version has been added.
Now, we can say git commit,
third commit, and do git log oneline,
and you'll see that there are three commits in our repository.
So, now our repository contains snapshots of three different points.
At the end of the first commit,
at the end of the second commit,
and at the end of the third commit.
Now, we also can roll back changes,
we can revert the repository to a previous version,
we can pull out a file from an older commit and
then replace the existing file directory from the old commit.
So, let's see how we can operate with these things by learning a couple of more commands.
At this stage, our index.html file is in the current state.
So, you can notice that it has an h1 and two Ps.
Let's now look at the next git commit.
The next git command that we're going to learn about is git checkout.
So, this checkout command allows us to check out
a file from a previous commit in our git repository.
So, if we don't like the current file that we have in
our folder and we want to go back to a previous version of the file,
we can always check out the file from a previous commit or from the current commit,
and then continue to work with that file.
So, let's make use of this and see some further changes to our git repository.
Going back to our command line,
we remember that between the second and the third commit,
I made changes to my index.html file.
Suppose I want to revert back to the index.html file from my second commit, so,
then I can simply say git checkout 900cfcf.
So, that is the commit identifier.
The number that identifies that particular commit,
and then I can say index.html.
And what you would notice is that that older file will now be checked
out into my current working directory.
Going to my Visual Studio code,
you'll now notice that my index.html file has reverted to the previous version.
So, the changes that I made before the third commit is now gone.
So, my index.html file has been restored to by its state at the end of the second commit.
Now, at the command line,
if I type git status,
you'll notice that this index.html
file which has reverted to what it was at the end of the second commit,
it has now already been staged.
So, using this git checkout,
will pull out an older version of the file and then replace what is in
the current directory and then it will also check it into the staging area.
So now, if I do that and then I realize that this is what I want,
I can simply do another commit at this point and then
that file can be committed as default commit.
But suppose I don't like this,
I want to revert back to the index.html file at the end of the third commit,
then all I can do is say,
git reset HEAD
and index.html.
So, at this point,
what happens is that the index.html,
the modified version that I have checked out is still there,
but this file has been unstaged from the staging area.
If you go back and look at the index.html in your editor,
it will still show the state at the end of
the second commit because we had pulled out that file using checkout for that.
Now, if you want to revert it back to what it was at the end of the third commit,
then we do one more check out from the third commit,
going to our RAM command window,
type git status and you would notice that the index.html is marked as modified.
But it also shows this particular statement here, it says,
git checkout minus, minus and
the filename to discard the changes in the working directory.
So, that's one way you can discard the changes that they are made to
a particular file corresponding to the previous commit.
So, let me restore this index.html back to what it was at the end of the third commit.
So, to do that, I would simply say git checkout minus, minus index.html.
And then if I do git status,
it shows that my directory is clean,
and basically my directory has been restored to the state at the end of the third commit.
Going to the file in my Visual Studio code,
I see that their file has been restored
back to what it was at the end of the third commit.
So, if you have made
changes to a file after they commit and you want to just discard those changes,
you can simply check out the file from the last commit,
and then all your changes that you've done after
the last commit will be discarded on the spot.
So, these are some basic commands that are very
useful for you as you go through the courses into specialization,
because you may want to commit at the end of each exercise.
And as you proceed forward,
you would still have a committed notion of
the state of your folder at the end of the previous exercise.
So, that way, if you are cutting out a new exercise and you discover that
you've made mistakes and you want to revert back to the previous commit,
you always have a way of doing that using the commands that we have just learned.
So, with this basic understanding of these few git commands,
we will be able to proceed forward with understanding
and using git in the courses of this specialization.
So, now, we have reviewed the git reset for a specific file or git reset in general.
If you simply type git reset,
it will restore you back to the last commit.
So, it'll reset the staging area to the last commit
without disturbing the changes that you've done to your working directory.
So, once you reset,
then you can check out
the previous version of the file that you have committed in the previous commit.
So, this way you can restore your folder back to where you were,
at the starting point of the previous commit.
So, sometimes when you are going through an exercise and you realize you made mistake,
you always have a way of reverting back to a previous version.
So, with this commands,
I think you're all set to go ahead to use Git in the courses of this specialization.
So, at the end of this exercise,
did you Git it?