Linux and Command-Line Basics

After editing main.c, a file managed with Git, only git commit -m "fix" was run, and "no changes added to commit" was shown and nothing was committed. Which of the following is the reason?

  1. ABefore committing, the changes have to be sent to the shared repository with git push
  2. BChanges to be included in a commit must first be registered in the staging area with git add
  3. CGit commits automatically when a file is saved, so there is no need to run git commit
Show answer and explanation

Answer: B. Changes to be included in a commit must first be registered in the staging area with git add

In Git, of the changes edited in the working directory, only those registered in the staging area (the index) with git add are recorded by the next git commit. This two-step mechanism lets you pick only related changes out of several edits and make them one commit. git status shows which changes are staged. There is also git commit -a, which stages all changes to tracked files and commits them at once.

  • A. git push sends commits to the shared repository and is used after committing.
  • B. Correct. Only changes staged with git add are committed.
  • C. Git does not commit automatically. The user decides which changes to record and when, with git add and git commit.
Practice this topic Back to topic

Books on Linux and Command-Line Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Linux and Command-Line Basics questions

  1. You ran git commit in Git, but the commit does not yet appear in the GitHub repository shared by the team. Which of the following is the reason?
  2. "build/" was written in the .gitignore of a project managed with Git, but changes to build/out.log, which was committed earlier, keep appearing in git status. Which of the following is the reason?
  3. Which of the following correctly pairs standard Linux directories with what is placed in them?
  4. Which of the following correctly describes the /proc directory on Linux?
  5. The directory /home/alice/data exists, and the current directory is /home/alice/work. Which of the following is the directory shown when "cd ../data" is run and then "pwd"?