Now even if we don't have a remote Git repository,
there are massive advantages to working with version control.
So we can go through and create ourselves a brand new directory.
We're creating this in our home directory. Make sure it doesn't
exist in a current Git project.
We move into that directory, and we can see our first
new sub command here, the git init.
So this is then creating our Git repository,
the .git subdirectory. We can check our status, and of
course, there won't be any changes.
We can create a new file and adding in our text. Again, now checking git status,
it will tell me really what we need to do to get our repository
in line with the data inside of the directory.
We can go ahead and run a git add. We can add just the one file,
but very often a shortcut to that is git add and dot, so that adds everything
from the current directory and below. We can save our changes.
So the git add is just putting it into our working space, and we can then
say that we want to commit those changes. So we use git commit ‑m, put a
commit message, and then we're done and dusted, and a git show will give
us a little bit more information about what's been happening within our
repository. But we might make some mistakes. Ideally when we're working
with code,
we will create branches and have a development branch so we're never
going to mess up our master or main code. However,
if we haven't created a branch,
we can still use a reversion system. So if we echo more tech through
to our file, and if you notice we're using the greater than symbol,
so we're overwriting the file. We don't check anything, so we go
ahead and run our git add command.
We do our git commit. Using the git log command,
we're able to see all of our changes; ‑‑oneline
summarizes I have one line for each entry.
We also get then identifiers for those commits.
So if I want to revert, I can pull out the correct identifier of
the save that I want to roll back to. Once we've retrieved that,
we can use the git revert command.
We don't need to, we will be making changes, but we don't need a
specialized commit for this, and we can specify then the
identifier of the commit we want to go to.
Now over here is just a sample.
Yours will be a completely different number I am guessing, and we
want to then move our head back to this position.
Our head is our working cursor position. So it's rolling back our change.
Once we have done that, we can check with git status. We can cat out
our file and see it's back to our initial text message. We can correct
our operation, so we're appending to it. And then, of course, we can do
our add and commit. Now I know we only had one line that we needed to
change, and I do accept it would be just as easy to go through and edit
the file.
But remember, there could be many files involved in this,
not just a single file.
So it gives you an idea of some of the things that we can do.
We need to dive out and get some hands‑on experience, so let's do that.
We're going to have a couple of separate demonstrations. The first is going to create our repository, so we are used to that.