Skip to content

lab 8 Committing Changes

Goals

Committing u using an editor

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.js file to the repository, you included the -m flag that gave a comment on the command line. The commit command will allow you to interactively edit a comment for the commit.

If you omit the -m flag from the command line, git will pop you into the editor of your choice. The editor is chosen from the following list (in priority order):

I have the EDITOR variable set to vim. Here's an example of what that would look like:

|
  # 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.js
  #

On the first line, you would enter the commit message for example: “Using process.argv”. Save the file and exit the editor. You then would see:

git commit
  Waiting for Vim...
  [master 569aa96] Using process.argv
  1 files changed, 1 insertions(+), 1 deletions(-)

The “Waiting for Vim…” line comes from the vim program which sends the file to a running vim program and waits for the file to be closed. The rest of the output is the standard commit messages.

Committing is the action of saving the changes to the repository. It is like taking a snapshot of the changes. You can always go back to this snapshot later.

Commit the change

For this assignment we will use the -m flag so that you can commit in the simulation terminal. So commit now and check the status.

Execute:

git commit -m "Using process.argv"
git status

You should see …

Output:

$ git status
On branch main
nothing to commit, working tree clean

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