>_ IzzyLab

Hands-on task

This task is step 5 of the course “Git: first commits”

Review changes before a commit

easy~5 min

In the /root/app repository, the file config.ini has changes that aren't committed yet. Before saving them, look at what exactly changed.

  1. Find out what value timeout had before the changes and write that number to /root/answer.txt.
  2. Commit the changes to config.ini with the message New server settings.
What you'll practise:
  • git diff
  • git diff --staged
  • reviewing changes

Topic breakdown

cat shows a file only the way it is now. git diff shows the difference between the files in the directory and what's saved in git — that is, exactly what you're about to commit.

$ git diff
diff --git a/settings.yml b/settings.yml
index 3b18e51..a1c4f02 100644
--- a/settings.yml
+++ b/settings.yml
@@ -1,3 +1,3 @@
 name: blog
-theme: light
+theme: dark
 lang: en

The first lines are a service header: which file is being compared. After that, a line with - is how it was, a line with + is how it is now, and lines without a sign are neighboring lines for context. Here theme was changed from light to dark.

  • git diff — changes that are not in the index yet;
  • git diff --staged — changes that are already in the index and will go into the commit.

A habit: look at git diff before every commit — that way a debug line or a password won't end up in the history.

What's checked

  1. /root/answer.txt holds the timeout value before the changes
  2. The config.ini changes are committed
  3. The last commit's message is the one from the task

What it looks like