init: git commit
In this video we'll commit our changes to the repository.
We've already told Git what changes we want to track by using git add
.
In Git terms, this is called staging our changes.
We can use git commit
to take all of the staged changes and record them together as a version.
To demonstrate, let's make some quick changes.
First we'll create two new files.
Next we'll add one of these new files.
Finally, let's update the contents of one of our existing files.
Let's see the current state of the repo by running git status
.
I see the new file I staged (in green), the file I modified, and the other new untracked file (both in red).
So, let's make a commit by running:
git commit
git commit
is one of the Git commands that opens our text editor.
This is so you can provide a commit message.
I'll cover commit messages in one of the Everyday Git videos.
For now, let's just say something like, Initial commit.
After running git commit
two things happened.
First, Git took all of our changes and recorded them into a version. It assigned this version a unique identifier.
In Git terms, this is called the hash or SHA. It can be used to uniquely identify this commit.
Second, if we run git status
again we will now see that our staged changes no longer appear.
Since we committed these changes, Git no longer sees their state as modified.
Notice also the changes that were not staged still remain.
As mentioned before, this process is slightly different than other version control systems.
Effectively Git uses a two-part process to give you full control over your changes.
First you tell Git what changes you want to be in the version.
Then, you record the changes to create the version.
Let's add the rest of our changes to demonstrate git commit
one more time.
First, I'll quickly add all changes.
git add .
We'll run git status
to see that both of these files are now staged.
And then I'll run git commit
.
This time let's avoid opening the text editor by providing the message inline with the -m
option.
So, we'll run:
git commit -m ''
For the message, we'll just say something like Adding additional files.
Finally, if we run git status
, we can confirm all our remaining changes were added and the repository is in a clean state.