- After you setup your project,
you'll need to get used to managing files
in and out of the staging environment.
Let's take a look at how to get things
in and out of our staging queue.
Now first, let's go ahead and make a few changes
to our index.html document.
I'm gonna close this about.html
and I'm gonna set this to Revision Two here
and type in a different pangram.
Now I'm gonna save this document
and I'll come back into my terminal
and do a git status command.
Now, here you can see that
Git is telling us a couple of things
about this index.html file.
First, it's not staged for committing.
It means that it is not in the staging environment yet,
it needs to be added there.
We already know how to do that,
you can do that using a git add command,
you can do either git add and then the name of the file
or git add . and then it adds all of the files
or we can discard the changes in the working directory
by using the git checkout
and checking out this file right here.
Let's go ahead and take a look at what that's like.
If we say "git checkout" and then "index.html,"
I'm gonna hit return and I'm gonna go back
into my text editors.
Notice that it switches back to being at Revision One.
What we did is we grabbed the file
out of our staging environment
which grabs the previous version of the file
and then it overwrote the changes that we had just made.
That means that we're ignoring
the changes that we just saved
and we pulled whatever was in staging
into our work environment.
Now we're back to what we had before.
Now, this is sort of like undoing
but remember that you can do this
to all of your files at once.
If you're messing around with different documents
because you're trying out some extreme new feature
and you feel like you've screwed up,
you know that you can always go back
to the version that you put in staging
using this git checkout command.
This is really useful.
Let's go ahead and make those changes again
and we'll send them to staging.
Just because I know that I have this
in my document's clipboard,
I can actually just undo
and it will take me back
to the last version of the project.
Notice that this is not a saved version,
this is just what is in my Sublime Text clipboard.
I'm gonna grab those changes
and then hit Save again.
We're back into the terminal
and we'll do git status.
Notice that it's the same as it was just a minute ago,
it's telling us that these changes are not staged for commit
so we can add them to the staging environment
by using the git add .
or git add and then the name of the file.
Now are changes are in the staging area.
Sometimes it's a good idea to issue the clear command
just so that we can see things a little bit cleaner
on our terminal.
I'm gonna do the git status command now.
Notice that now
this right here shows up as green,
it's telling us that these changes
are in the staging environment
and they're ready to be committed.
Notice that git status is not suggesting
that you check things out from the staging area any more.
If something is already in staging,
we can take it out
by using this git reset HEAD and then the file name command.
This is called unstaging,
it's taking whatever was in our staging environment
and replacing what's in our working files environment
with whatever is in staging.
Let me show you how that works.
Right now if I just do that,
my staging and my work environment are the same
so let's go ahead and make some changes here.
All right, so I'm gonna save that
and I'm gonna do a git status command.
Let's go ahead and clear the screen
because it's actually a little bit confusing,
it looks just like it did a minute ago,
and do a git status now.
Notice that it's showing you that now we have things
that have been saved
and are in our working environment,
they're not in staging,
that's this information you see right now.
And we still have something in our staging environment,
that would be Revision Two.
We can take the things that are in staging
and then overwrite whatever we have
in this environment.
Let's go ahead and do that, we'll issue the
git reset HEAD command
and then do this index.html file.
All right, so if we look at git status again,
now it looks like I have something
in my working environment
that is not in staging.
So we just grabbed whatever was in staging
and we replaced our working environment.
If we click over here you'll notice that
it's sort of ignored Revision Two altogether,
it just sort of deleted it out of staging
and looked at the fact that we have
this item right here that we saved
in our work environment
and that's the one that's in here right now.
If we want to we can go ahead and add that,
we would completely miss out on Revision Two
but that's sometimes exactly what we wanna do,
we just wanna clear out the staging environment
and continue to work on our project.
Now, it's as if you'd never added
what was in the staging environment in the first place.
This is slightly different from checking things out
because we're not moving any of the changes,
we're just telling Git that
we never meant to stage that file.
Let's go ahead and do a couple of commits
of all these files.
I'm gonna undo to get back my Revision Two here.
All right, so I have that one,
I'm gonna save this
and I'm gonna do a git add . command.
All right, so if I do a git status,
now you should see,
let's go ahead and clear this out and do a git status,
you can see that this Revision Two
has been placed into our staging environment.
Now we can go ahead and schedule or setup a commit.
We'll do git commit -m for the message
and then we'll do "revision two"
and then we will do
(mumbles) a clear here
and we'll do a git status.
Right now there's nothing to commit,
this is on Revision Two.
Let's go ahead and make the changes
for Revision Three again here
so we'll do Revision Three
and we'll just type this in again,
we could undo but I think it's a little bit clearer
if I just type this in again.
All right, so I'm gonna save this
and this is gonna be Revision Three
so let's clear this out, git status,
it shows us there's something
in the working environment that needs to be staged
so we'll stage it, we'll say "get add index.html."
All right, so let's go ahead and clear, look at git status.
I'm running git status a lot more than I normally would
just to show you sort of the progression
of what I'm doing here.
Now, if I do a
git commit -m
"revision three," all right.
Then our git status,
let's go ahead and clear,
git status,
we should be all good.
If we take a look at the log now,
so we'll do a git log,
you can see that
all the different revisions that we have done,
and there should be revision one, two and three like this,
and each one of those revisions has a hash
that we can use checkout to go back to
and Git has stored each one of those commits
so we can always get back to any one of those points.
Now, staging environment gives you
another level of control over the state of your files.
To me, it's like the first time I learned
about multiple undos.
Once you start using it,
you'll never wanna live without it,
it'll be another way to control
the status of all your files.