lab 6 Committing Changes

Goals

Commit the change 01

Ok, enough about staging. Let’s commit what we have staged to the repository.

When you used git commit previously to commit the initial version of the hello.c file to the repository, you included the -m flag that gave a comment on the command line. If you omit the -m flag from the command line, git will pop you into the editor of your choice to edit the comment. The editor is chosen from the following list (in priority order):

For example, you can have the EDITOR variable set to vim. But you can also use:

git config --global core.editor vim

So commit now and check the status.

Execute:

git commit

You should see the following in your editor:

Output:

|
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	modified:   hello.c
#

On the first line, enter the comment: “Using argv”. Save the file and exit the editor (git waits until your editor exits). You should see …

Output:

$ git commit
[master bc2df82] Using argv
 1 file changed, 6 insertions(+), 2 deletions(-)
$

The rest of the output is the standard commit messages.

NOTE: Using a console editor like vim or "emacs -nw" (no window) is usally more efficient to provide a commit message, as compared to a graphical editor.

Check the status 02

Finally let’s check the status again.

Execute:

git status

You should see …

Output:

$ git status
# On branch master
nothing to commit (working directory clean)

The working directory is clean and ready for you to continue.

Table of Contents