Version-Control-Git-Teaching-Notes

5.3 Understanding Workflow and History

What is the output of the last command in

$ cd recipes
$ echo "I like tomatos, therefore I like ketchup" > ketchup.md
$ git add ketchup.md
$ echo "ketchup enchances pasta dishes" > ketchup.md
$ git commit -m "my opinions about the red sauce"
$ git checkout HEAD ketchup.md
$ cat ketchup.md # this will print the content of ketchup.md on screen
  1. ketchup enchances pasta dishes
  2. I like tomatos, therefore I like ketchup
  3. I like tomatos, therefore I like ketchup
    ketchup enchances pasta dishes
  4. Error because you have changed ketchup.md without committing the changes
Solution

The answer is 2.

The changes to the file from the second echo command are only applied to the working copy, The command git add ketchup.md places the current version of ketchup.md into the staging area. not the version in the staging area.

So, when git commit -m "my opinions about the red sauce" is executed, the version of ketchup.md committed to the repository is the one from the staging area and has only one line.

At this time, the working copy still has the second line (and git status will show that the file is modified). However, git checkout HEAD ketchup.md replaces the working copy with the most recently committed version of ketchup.md. So, cat ketchup.md will output:

I like tomatos, therefore I like ketchup

Episode 5 Exercise 4