Computer Programming || Gaming || Technology || ai


Interlude: how can I edit a file?

Unix has a bewildering variety of text editors. In this course, we will sometimes use a very simple one called Nano. If you type nano filename, it will open filename for editing (or create it if it doesn’t already exist). You can then move around with the arrow keys, delete characters with the backspace key, and so on. You can also do a few other operations with control-key combinations:

  • Ctrl-K: delete a line.
  • Ctrl-U: un-delete a line.
  • Ctrl-O: save the file (‘O’ stands for ‘output’).
  • Ctrl-X: exit the editor.

Run nano names.txt to edit a new file in your home directory and enter the following four lines:


To save what you have written, type Ctrl-O to write the file out, then Enter to confirm the filename, then Ctrl-X and Enter to exit the editor.

ans: echo nano names.txt

How do I commit changes?

To save the changes in the staging area, you use the command git commit. It always saves everything that is in the staging area as one unit: as you will see later, when you want to undo changes to a project, you undo all of a commit or none of it.

When you commit changes, Git requires you to enter a log message. This serves the same purpose as a comment in a program: it tells the next person to examine the repository why you made a change.

By default, Git launches a text editor to let you write this message. To keep things simple, you can use

git commit -m "Program appears to have become self-aware."

You have been put in the dentalrepository, and report.txt has been added to the staging area. Use one Git command to check the status of the repository.

ans:git status

Commit the changes in the staging area with the message “Adding a reference.”

ans: git commit -m "Program appears to have become self-aware."


How can I view a repository’s history?

The command git log is used to view the log of the project’s history. Log entries are shown most recent first, and look like this:

commit 0430705487381195993bac9c21512ccfb511056d
Author: Rep Loop <>
Date:   Wed Sep 20 13:42:26 2017 +0000

    Added year to report title.

The commit line displays a unique ID for the commit called a hash; we will explore these further in the next chapter. The other lines tell you who made the change, when, and what log message they wrote for the change.

When you run git log, Git automatically uses a pager to show one screen of output at a time. Press the space bar to go down a page or the ‘q’ key to quit.

You are in the directory dental, which is a Git repository. Use a single Git command to view the repository’s history. What is the message on the very first entry in the log (which is displayed last)?

ans:”Added summary report file.”

How can I view a specific file’s history?

A project’s entire log can be overwhelming, so it’s often useful to inspect only the changes to particular files or directories. You can do this using git log path, where pathis the path to a specific file or directory. The log for a file shows changes made to that file; the log for a directory shows when files were added or deleted in that directory, rather than when the contents of the directory’s files were changed.

You have been put in the dentalrepository. Use git log to display only the changes made to data/southern.csv. How many have there been?

ans: 2 (git log data/southern.csv)

How do I write a better log message?

Writing a one-line log message with git commit -m "message"is good enough for very small changes, but your collaborators (including your future self) will appreciate more information. If you run git commitwithout -m "message", Git launches a text editor with a template like this:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Your branch is up-to-date with 'origin/master'.
# Changes to be committed:
#       modified:   skynet.R

The lines starting with # are comments, and won’t be saved. (They are there to remind you what you are supposed to do and what files you have changed.) Your message should go at the top, and may be as long and as detailed as you want.

You have been put in the dentalrepository, and report.txt has been added to the staging area. The changes to report.txt have already been staged. Use git commit without -m to commit the changes.

 ans:git commit  “Adding a reference.”

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *


October 2020