Solutions

Choosing a Commit Message

Answer 1 is not descriptive enough, and answer 2 is too descriptive and redundant, but answer 3 is good: short but descriptive.

Committing Changes to Git

  1. Would only create a commit if files have already been staged.
  2. Would try to create a new repository.
  3. Is correct: first add the file to the staging area, then commit.
  4. Would try to commit a file “my recent changes” with the message myfile.txt.

Committing Multiple Files

First we make our changes to the mars.txt and venus.txt files:

% nano mars.txt
% cat mars.txt

Maybe I should start with a base on Venus.

% nano venus.txt
% cat venus.txt
Venus is a nice planet and I definitely should consider it as a base.

Now you can add both files to the staging area. We can do that in one line:

% git add mars.txt venus.txt

Or with multiple commands:

% git add mars.txt
% git add venus.txt

Now the files are ready to commit. You can check that using git status. If you are ready to commit use:

% git commit -m "Write plans to start a base on Venus"
[master cc127c2]
 Write plans to start a base on Venus
 2 files changed, 2 insertions(+)
 create mode 100644 venus.txt

One of the powers of git is being able to choose which files to commit at the same time, e.g. if files have dependencies.

Author and Committer

% git add me.txt
% git commit -m "Update Vlad's bio." --author="Frank N. Stein <franky@monster.com>"
[master 4162a51] Update Vlad's bio.
Author: Frank N. Stein <franky@monster.com>
1 file changed, 2 insertions(+), 2 deletions(-)
% git log --format=full
commit 4162a51b273ba799a9d395dd70c45d96dba4e2ff
Author: Frank N. Stein <franky@monster.com>
Commit: Vlad Dracula <vlad@tran.sylvan.ia>

Update Vlad's bio.

commit aaa3271e5e26f75f11892718e83a3e2743fab8ea
Author: Vlad Dracula <vlad@tran.sylvan.ia>
Commit: Vlad Dracula <vlad@tran.sylvan.ia>

Vlad's initial bio.

</div>