OK.
Welcome back.
So in the last video we saw four new commands get in that status add and commit all very useful especially
add and commit you use all the time but all that that lets us do is add in files and commit them.
Save them basically make little checkpoints to actually go back the old code.
We're going to see two new commands.
Get log in get checked out and they're actually going to show you a few more but they're not as essential
as these two.
So I'm in the same folder if I type.
Let's start with us.
You can see I have those three files for type get status.
I haven't made any changes and if I take a look who me just reopen them.
C-9 actually yes.
And let's do cat and dogs.
I don't know if I've shown you that before you can just chain them together like that.
OK.
So we have these three files the dogs one is empty.
That's fine.
Let's suppose that this is a huge app and I somehow messed something up and I get an error.
So I do something wrong and my code no longer works.
And again pretend it's a big app and I don't actually know what the problem is or maybe I was trying
something out and I decided screw it.
I don't actually like that.
Let's go back to my old version.
So the first thing you want to do is type get log in and this will give us a history or a log of all
the commits that we've made in this repo.
So a quick note.
It opens up this kind of new terminal interface where if you hit enter it's actually going to scroll
you can use the up arrow as well to scroll through but you can't type regular commands right now.
Notice how the cursor has changed a little.
There's a curse or there's a colon right here to get out of this.
You can type Q So go back get log.
And let's start at the very beginning.
So at the bottom.
First thing I did You can see first the author the date the time that I made this and the code that
I ran which was are they commit message add X-File.
And then the next one was add catch file and then add me out to cats and dogs file.
And that was you know we had update files as well.
So yes they all have times the messages though are really important.
And they need to be descriptive especially if you're revisiting code if you're coming back to it after
a while away.
But the most important part as far as get is concerned the actual commands that we run.
We never actually type these commit messages again.
They're just for humans.
But the important part for good for the computer is this commit hash here this long string.
It's really really important because that's the unique identifier.
So that's what if I want to go back I want to look at the code from the very beginning add app file
back in time.
I need this.
So I'm going to copy that.
Let's say I want to go back all the way until when I just had the app file no cat file no dugs file
.
I copy this here command C and I hit Q to get out and then we're going to see the new command.
Or the second new command which is get checked out.
So I type get check out and this is a really versatile command.
It's used for a lot of different things but the general idea is that it's used for just going and viewing
something else going and checking something else out whether it's a branch or it's a previous commit
.
We haven't talked about branches by the way but it's often used to do that to change branches.
So we need to get checked out and then paste that long string in and hit enter.
And actually before I do that let me get out of there and just type get status.
First thing I see is that I did make a change in my app Yes which is fine but I didn't stage it for
Commit I didn't add it but more importantly said on Branch master again we don't really know what branches
are but but all that you need to know for now is that master is our home base.
So everything we've done has been on Master.
OK.
And I also have this little get prompt here on my command prompt it says master.
So now if I do run that command looks like I lost it.
Type it again.
Get check out and paste that and then hit enter.
First thing you'll see is that it's telling me I have changes that aren't committed.
And if I check out this if I go back here I'm going to lose those changes.
And that's because it can only keep track of so many things at once.
So I have some changes right now.
This one line that I made and get is watching that and saying do you want me to commit this to you want
me to add this.
But if I go back and view some old code it is not going to know about this anymore.
So it's basically warning me before you go back.
You should probably add and commit this or get rid of it entirely so just don't care about it just overwrite
it.
I'm going to add in commit though I'm going to do it get ad app.
Yes and my commit message will just be mess up app file to get status nothing to commit.
Still on Branch master.
Now let's try and check that out again.
This time we get a much longer message.
Most importantly though notice that it no longer says Master right here.
It gets cut off because it's so long.
But if I type that status I see head detached at 5 c d d blah blah blah.
Which is the beginning of that hash.
OK so in my opinion this is very good starts to get really confusing this term head here.
It's always confusing to most people I know including our developers.
It's basically a pointer in.
They give it as a pointer in space or in time the current place where you are and you can move it around
to move back and forth through time.
What's important though is that we're no longer on Master.
So what we've done is we've gone back and looked at we're basically checking out we're inspecting the
old version of the code.
So if I type LS This is what's pretty cool about it.
I only have one file here.
So when I went back when I checked that old code out it basically transported me back in time it took
me back and I could see what I had back then.
But it is important to note that when I when I do a check out like I'd get checked out and then the
name the commit hash if I do that it kind of takes me out of the current flow or the normal workflow
of good.
That's why it says Head detached.
So if you imagine our history has a history as sort of a timeline that looks like this where each one
of these shows is a commit.
Just do a few more.
OK.
Oh geez.
There we go.
So each one of these is sort of a point in time where we committed and it's in a sort of a linear list
here where we started that one and then we made some changes committed again.
And there's a flow to this.
This is where we were the last commit.
This is what is known currently at least this is where a master is so obvious right that Master This
is where we were before we made this get check out command.
Then I ran get check out and this commit and it took me all the way back to I believe our very first
commit and it told us that head detached at that commit message.
So that means that master is still here.
We haven't moved this master back.
What we've done is kept it there but we've detached the head.
And again I do think this is very confusing.
What's important is that basically we've added in this idea of what just a is right here.
Not sure why that changed the syntax highlighting but head is here.
But we left off here so we have unfinished business over here.
So what we either need to do is totally up to us.
Usually when we use check out it's to just go look at some old change just to check out our old code
and then go back to where we were.
So think of it as hitting the pause button on the code that we had and then we checked out some previous
code which is where we are right now and then maybe we copy a line or two maybe we view a note that
we wrote to ourselves or look at some old code and then we go back to master and that will fix a problem
of head detection.
It's not really a problem but it can be because if I start making changes right now in my app James
and I try and add and commit will run into a problem which is that it's I know what to do because we
have these we have a master here we have head here.
We're going to make a decision.
So usually what we do is we check something out inspected.
Look at it view some code and then go back to master.
Sometimes though you want to just go back to an old version and revert.
Which basically means go back and just start at that point in time rather than just checking it out
.
So before I do that let me just show you how you go back to master.
So again get status says that we're had detached on this long string.
I could do.
Good.
Check out master.
And that takes me back forward in time.
And now first thing I noticed those files come back I type ls and now have those three files again and
right type get status.
I'm on Branch master.
So we took a little trip backwards.
Half of us was a peer.
Half of us was back there and then we went back to master and everything is happy again.
All right.
But let's say do want to go back I want to revert back to let's do get log to before we added the dogs
file.
So this commit commit message where we added in meow to the catch file.
So we should have the cats and the app file and I just want to go back to that.
So I don't want to just go check it out and look at it but I actually want my code to reflect that state
.
I want to add a new commit that says we reverted back I'm starting over without the dogs file.
So this would be like if you scrapped you know a big part of your novel or you want to just go back
before you added in user authentication or before you added in Bootstrap and you just want to go back
and start over.
At that point and the unfortunate thing here is that there are a lot of ways of doing this.
And before I actually show you some of them I'm just going to show you one.
But before I do that I want to add a note here about how developers use it.
Most developers and this is definitely generalization but most developers are pretty are very comfortable
with the common workflow that we've been talking about status add commit status and commit over and
over maybe checking out something developers will work with branches.
But when it comes to reverting back to old code to undoing something to deleting changes whatever it
is that's something that you actually don't do it often.
It's pretty rare that you abandon you know your current code especially when you're on a bigger team
.
It's not it's not that it never happens.
But those sort of things are not the norm.
And I would say that most developers don't know how to do that off the top of their head or they might
know one way of doing it but there's five or 10 different ways of doing it.
So the way that people use get again is that they're comfortable with a lot of the basics.
The bread and butter commands really five to seven commands.
And then one day someone will have to do something they don't know how to do.
And they just research it.
So something like Stack Overflow is really really helpful.
And if we look I have a stack overflow postage included as a link.
There is a question here.
How do I revert from my current state to a snapshot made on a certain commit.
So how do I go back to an old commit not just check it out like we saw but how do I actually revert
to it.
And there's probably 20 different answers and none of them are the same.
So I'll just walk through some of them.
You're going to see some of them are multiple lines long.
Some of them will ask you or some of them will have you basically destroy any of the commits that you've
made before you revert back.
Some of them will keep the commits that you have.
There's lots of different ways.
The one that I'm going to work with is this one here.
It's nice and short and it's pretty easy to do what we do as we type get reversed.
Dash dash no dash commit and then the commit that we want to revert back to dot dot head.
And as you can see here it says this will revert everything from the head back to the commit hash back
to whatever commit we provided meaning it will recreate that commits date as if every commit since have
been a walk back.
So that's not as important.
And then the dash dash No commit is a flag that tells it just to revert all the commits at once rather
than doing them one at a time which would then ask us for a message for every single one.
So rather than doing that we can just do dash dash No commit it will revert everything back and then
we can run get commit and give it a message like reverted back or undo changes whatever we do.
So let's try it out now to go back here and I'm going to copy this into the notes so you have that there
as well as paste it here.
And again this obviously needs to change depending on your commit.
So I want to go back.
I think oh I just copied something else I don't have it on my clipboard anymore.
I want to go back to when I added meow to cats and let's just take a quick look at what the files look
like right now.
So dogs is empty.
Cats has meow and purr and address has all of this stuff.
OK.
So now if I try this line first always type get status and one thing that's worth noting is that if
you try and revert and you have changes that are uncommitted.
So if I made a new file or if I change something in dogs.
Yes.
And I tried to revert it would would warn me.
I would say you have uncommitted changes what do you want me to do.
So most the time you just add those changes.
Commit them and then you would refer.
OK so get river dash dash no dash commit then Pace said stringin dash dash or dot dot head.
Yes I know this is a lot.
No I would never remember this myself.
You stack overflow.
You find it online again.
Use your Googling skills.
It is.
As I mentioned something that you don't do all that often but it is important to know how to find and
figure out how to do it not that you need to memorize this at all.
So get commit add and knit.
Those are worth memorizing.
But something like this river dash dash No commit.
I wouldn't waste your time on it.
OK.
Noticed that happened over here.
You can see we have at Jasin cats J.S. but dogs is gone.
Let's look at cats.
It only has meow.
Let's look at actually yes it only has a single line.
This is my complex app for I type get status right now.
You'll see that we actually have some changes that that need to be committed and those changes are what
basically just changed.
When I reverted back it deleted the dog's file and it changed app and cats.
Yes.
So let's add commit and we don't need to add.
We just need to commit.
You can see it already says change is to be committed.
And also it tells us you are currently reverting commit and then the commit message.
OK so we would usually put in here is revert back to and then you could either pace that long hash right
there that string or you could give a commit message or a point in time revert back to before authentication
broke or revert back to before bootstrap added and then hit enter.
Now to get status were on Master.
Nothing to commit or can directory's clean.
I have actually yes in cats yes it is important to note that I don't just lose everything.
If I did want to go back to when I have had the dogs file I could do get log and you know see my committee
now look like this very first one ad app file then add cat's file add me out to cats and dogs file update
files mess up file and then revert back.
So even though I no longer have the dog file basically the state that we were in here I do have this
commit.
So I didn't either.
I don't lose it.
I can revert back to that at any point if I want it to.
So it gets really really powerful and I think it's also really intimidating when you're starting out
when you see something like this.
So I debated showing you reverting.
I had the reason I decided to do it is because even though you don't do it a lot I think it shows you
what you can do with get that with a single line maybe two lines.
You can have 100 files and you could revert back to when you had one file or you could have 100 files
that were all filled out with thousand lines each and you could write back and they might only have
one line each.
You can you can use it.
It's really powerful especially when you're working on bigger projects.
So I debated showing it to you though because I think it's a little bit intense.
It's a lot to see and it's you know something like this.
It's not it's not easy for anyone to remember or anyone to just know.
So I don't to get that impression.
I know I'm a broken record here but don't freak out about this line.
OK.
So we've talked a little bit about this workflow ad commit status if you want to you can check out old
code.
You can revert if you need to just take a look at the stack overflow post if you ever need to do it
.
What we're going to see next is how get how it plays into this.
So we've seen how we can use it locally.
So I could work on a project a novel.
I can write my novel at little checkpoints with get ad get commit and then I can go back and look at
what I had or I can revert.
But now what if I wanted to put my code put my novel up on good hub so that other people could share
it.
Other people could read it other people could edit it they could get it on their own machine make some
changes and then share that with other people.
So that's what get how busy is for and that's what we're going to talk about in the next video.