So in our next demonstration,
we're going to take a look at using that Git repository.
We're going to make changes to the data that we have.
Then perhaps we discover that there's been a mistake and
we need to roll back those changes.
And as I've said previously, ideally we create branches,
and they become our development areas,
and we don't then affect our master or main branch.
But as we haven't done that, we can still revert.
So we've discovered we've made a mistake,
so we're going to go through and revert our changes.
Again,
the idea is here that we're showing you the power of using a Git repository.
So come on, dive out to your command line.
We're going to have some fun.
Now we're in our project directory, and if I go through and ls,
we can see we've got our file.
If we go through and check what we've got in our file,
then obviously we've got our initial text that we've put in.
When I go through and check the git status command,
we can see then everything is up to date,
and we're working on our master branch.
Now ideally, if we are going to make changes, we would create a new branch.
That then gives me a completely separate working area,
and we never affect then the master until I choose at some stage,
if necessary,
to merge the changes in from my development branch into my master branch.
But even if we haven't done that,
there are mechanisms that we can use to roll back changes.
So if I go through now and echo some more text through to my file,
maybe I'm trying to append to the file,
so I go echo Hello world in however much I want it.
But instead of appending, I overwrite, and we go through to then my file.
Now maybe I haven't noticed the change,
but I'm then happy to go ahead and do a git add and dot.
We can go through and do our git commit ‑m "Added text".
So we've now saved the change.
Now, of course, the change was always in the file once we had made it,
but we've now saved it in our revision control system.
We've only got the one branch, so I can't switch between my branches.
So, again, we can look at some of those commands.
We can go through and look at git branch.
We can look at our git status.
So we haven't got anything to commit.
We can't roll anything back from this stage.
However, if we go through and do something like a git show,
we can read our commit message, Added text.
But more importantly, we're running a differencing between myfile and myfile,
and we can see then the difference.
We've removed First text and added in Hello world!
Now because we only made such a trivial change,
it would be easy to go through and correct this.
But often we've worked with multiple files,
and perhaps those edits haven't been trivial.
There are many,
many changes that are not going to be easily manually rolled back.
With our git log command, we know we can go through and look at then our commits,
and we can see then that we've got multiple commits,
so the information is starting to grow.
If we go back and look at then the ‑‑oneline,
we're able then to summarize those commits.
So we still see each commit, but we see the summary information on a single line.
We want to go back to that first commit, so we can use git revert.
We don't need to make a commit for this ourselves,
so we can go through and do ‑‑no‑commit.
We can specify how we're rolling back, and we're rolling back to this ID.
Obviously, I'm putting in my number,
and we want our head to be rolled back to this point.
Our head really is our cursor, where it is at the moment.
Currently, our head, or cursor, is on the added text.
We want to move it back to our first commit.
So let's roll this back.
With that done, if I go through and cat out my file,
we're back then the way we need it.
Now that we've got our information back the way that we need this,
we can go through and append the way we need,
so echo "Hello world!" or whatever we want to put in. And make
sure that we append it through to our file, so we're going to
write through to myfile. With that, we might double‑check now that it is correct.
So that's appearing the way that we want. Now we can go
through and do our git add and dot, run our git commit ‑m
and then "Added text correctly".
Let's go through and make sure we've written correctly.
And with that done,
we should be ready to go. Now moving back up to the top of our screen,
we can go through and look at git show, and we can see now
essentially the edit between this edit and our last edit
is adding in the first text.
So we can see now the difference between this commit and our previous
commit where we had just added only Hello world.
We can also go through and take a look at git log. We
still have our full history of commits.
So even if we needed to at some stage, we can move back to our commit where
we had added the text, that middle commit. But ideally, we don't work in this
way. When we're developing or making changes,
we create a branch, and we make the changes in the branch. That then is
isolated from our main or master, and we choose when we want to merge or if we want to merge into the main or master branch.