Master: git commit
In this video we'll Master some of the additional options for git commit
.
We talked about how Git splits this process into two steps - first adding your changes and second making your commit.
You can do this in one step by using the -a
option.
This will add all changes to all tracked files as well as make your commit.
Let's demonstrate this by first modifying two of our tracked files.
I'm just going to quickly append a timestamp to each file by redirecting the output from the date
command.
date >> new-file-1.txt
date >> new-file-2.txt
If we run git status
, we'll see these two files are modified, but not staged.
Now, by running:
git commit -a -m 'add + commit in one step'
If we run git status
again, we'll see a clean state as our changes were staged and committed.
We can also use git commit
to add additional changes to the previous commit or modify it's commit message with the --amend
option.
Let's demonstrate this by running:
git commit --amend
This launches our text editor, where I can edit the previous commit message.
More often you'll use the --amend
option to add additional changes to the previous commit and don't care about changing the message.
In this case, you can streamline the process by running:
git commit -a --amend --no-edit
That was a lot of options, so let's review them one by one.
The -a
option will add your changes.
The --amend
option will join them to the previous commit.
And the --no-edit
option tells Git we do not want to edit the previous commit message, just use the original message.
There are more options for git commit
which relate to other commands we'll Mater in later videos.