Version-Control-Git-Teaching-Notes

4.2 Committing Changes to Git

Which command(s) below would save the changes of myfile.txt to my local Git repository?

  1. $ git commit -m "my recent changes"
  2. $ git init myfile.txt
    $ git commit -m "my recent changes"
  3. $ git add myfile.txt
    $ git commit -m "my recent changes"
  4. $ git commit -m myfile.txt "my recent changes"
Solution
  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.

Episode 4 Exercise 3