← All lessons

Git: saving versions

Sign in · Sign up

Lesson 13.0

Git is like save games for code: it keeps every version, and you can go back to any of them.

git init                          # create a repository
git add main.py                   # stage the files to save
git commit -m "First commit"      # save a version
git log                           # look at the history
  • git add puts a file into the "basket", git commit saves everything in it;
  • -m is the commit message: write what it means, "asdf" won't help you in a week;
  • every commit gets a long number and keeps the author, the date and the message;
  • Git cannot run in the browser, so the check imitates it: it gives ready-made commits and you build the history from them.

The check gives the list of commits commits — triples of "message, file, whether the file made it into the commit". Print:

  1. Total versions: <how many commits>;
  2. Latest: <message of the newest commit> — it is at the end of the list;
  3. Files: and one item - <file> for every file that made it into a commit, in order of first appearance.
Hint

The number of commits is len(list), the latest is by the index [-1].

Collect the files into a list without repeats and print it line by line. A commit with no file (an empty name) must not give an empty item.