Skip to content

Quiz - Test your knowledge

Overview

In the following you can test the knowledge you have acquired during the workshop.

Tips for instructors
  • Decide which channel (e.g., video conference chat) you want to use to collect the answers from your participants.
  • Go through every question one after another. For each questions:
    • Read out the question and all the answers.
    • Give a clear sign when the participants should give their answer.
    • Explain all answers separately.

Quiz

Git basics

Which of the following statements is true?

  1. Git is a centralized VCS
  2. Git is a decentralized VCS
Answer

The answer is (2).

Git is a decentralized VCS. For more information, please see git-scm.com: About Version Control

What is the purpose of the command git init?

Answer

git init initializes a new Git repository in the current working directory.

What is the .git folder used for?

Answer

The .git holds all information and configuration information of the Git repository.

What are the following commands doing?

   git config --global user.name "Vlad Dracula"
   git config --global user.email "vlad@tran.sylvan.ia"
  1. Set your GitLab authentication information.
  2. Set the metadata for your Git commits.
  3. Tell Git who will pay the invoice.
Answer

The answer is (2).

  • Answer (1) is wrong because these configuration options only influence the commit metadata.
  • Answer (3) is wrong because you cannot tell Git who pays the invoice.

The --global option sets your default values for these options. Without it the username and email is only set for the Git repository in which the command has been executed.

Tracking changes

Choosing a commit message

In the last commit the line “But the Mummy will appreciate the lack of humidity” has been added to the file mars.txt. Which of the following commit messages would be most appropriate for this commit?

  1. “Changes”.
  2. “Added line ‘But the Mummy will appreciate the lack of humidity’ to mars.txt”.
  3. “Discuss effects of Mars’ climate on the Mummy”.
Answer

The answer is (3).

  • Answer (1) is not descriptive enough and the purpose of the commit is unclear.
  • Answer (2) is redundant. Instead you can use git diff to see what changed in this commit.

Which command(s) below would save the changes of new-file.txt to the local Git repository?

  1. git commit -m "Add recent changes"
    
  2. git init new-file.txt
    git commit -m "Add recent changes"
    
  3. git add new-file.txt
    git commit -m "Add recent changes"
    
  4. git commit -m new-file.txt "Add recent changes"
    
Answer

The answer is (3).

  • Answer (1) would only create a commit if the changes to the file are already staged.
  • Answer (2) would try to create a new repository.
  • Answer (4) would try to commit a file named Add recent changes with the commit message new-file.txt.

Exploring history

How is git diff and git diff HEAD different from git diff --staged?

Answer
  • git diff compares your working copy with your staging area. It tells you what you could add on top of what is in the staging area.
  • git diff HEAD compares changes in both your working copy and the staging area with the last commit.
  • git diff --staged compares the staging area and the commit you specify. If no commit is specified, it compares the staging area with your HEAD.

What is git restore <...> used for?

Answer

It undoes changes in your working directory or staging area. It has been introduced as the alternative for git checkout -- <file> in Git version >= 2.23.

Recovering older versions of a file

You have made changes to the file you have been working on for a long time. The modifications you have done this morning “broke” the script. Which commands let you recover the latest committed version of the file mars.txt?

  1. git restore
    
  2. git restore mars.txt
    
  3. git restore -s HEAD~1 mars.txt
    
  4. git restore -s <unique ID of last commit> mars.txt
    
  5. Both 2 and 4
Answer

The answer is (5) - Both, (2) and (4) are correct.

  • The restore command restores files from the repository, overwriting the files in your working directory. Answers (2) and (4) both restore the latest version in the repository of the file mars.txt. Answer (2) uses HEAD to reference the latest commit, whereas answer (4) uses the unique ID of the last commit.
  • Answer (1) results in an error. You need to specify a file to restore. If you want to restore all files you should use git restore .
  • Answer (3) gets the version of mars.txt from the commit before HEAD, which is NOT what we want.

What is the output of the last command in the following command sequence?

   cd planets
   echo "Cold and dry, but everything in my favorite color" > mars.txt
   git add mars.txt
   echo "The two moons may be a problem for Wolfman" >> mars.txt
   git commit -m "Add considerations about Mars' conditions"
   git restore mars.txt
   cat mars.txt
  1. Cold and dry, but everything in my favorite color
    
  2. The two moons may be a problem for Wolfman
    
  3. Cold and dry, but everything in my favorite color
    The two moons may be a problem for Wolfman
    
  4. Error because you have changed mars.txt without committing the changes
    
Answer

The answer is (2).

  • The command git add mars.txt adds only the initial version of mars.txt into the staging area. The changes to the file from the second echo command are only applied to the working copy, not the version in the staging area.
  • I.e., when git commit -m "Add considerations about Mars' conditions" is executed, the version of mars.txt committed to the repository has only one line. Afterwards, the file mars.txt in the working copy still contains the second line and a git status command would show that the file is modified.
  • Finally, git restore mars.txt replaces the working copy with the most recently committed version of mars.txt. I.e., cat mars.txt only shows one line.

Working with branches

What is git branch <branch name> used for?

Answer

It creates a new branch with the name specified based on the currently checked out commit.

What is git switch <branch name> used for?

Answer

It switches to the branch that is specified. It has been introduced as the alternative for git checkout <branch name> in Git version >= 2.23.

How does the feature branch workflow basically work?

Answer
  1. Create the feature branch and switch to it: git branch <feature branch name> + git switch <feature branch name>.
  2. Perform your task and commit your work: Modify - Add - Commit workflow.
  3. Merge the feature branch into the main branch: git switch <feature branch name> + git merge <feature branch name>.

Working with remote repositories

What is git clone used for?

Answer

git clone creates a local copy (“clone”) of a remote Git repository. Afterwards, you have a local copy of the Git repository which is directly connected with its remote Git repository.

Which of the following commands only interact with your local Git repository?

  1. git push
  2. git commit
  3. git pull
  4. git fetch
  5. git switch
  6. Both, (1) and (2)
  7. Both, (2) and (5)
Answer

The answer is (7) - Both, (2) and (5) are correct.

  • git push, git pull and git fetch are used to synchronize your local repository with a remote repository.
  • git commit creates a new commit in your local Git repository.
  • git switch is used to switch branches in your local Git repository.

How is git push different from git commit?

Answer
  • git push pushes commits to another repository.
  • git commit creates a new commit in the local repository. In contrast to svn commit, git commit performs a local operation and does not require network access.

How is git pull different from git fetch?

Answer
  • git pull updates the local meta information of the remote Git repository and directly integrates new commits.
  • git fetch only updates the local meta information of the remote repository. Afterwards, you can examine the new commits before you actually integrate them.

Key points

Congratulations! You have recapped the acquired Git basics and tested your knowledge.

Looking for a currently offered workshop?

Other workshops building on this workshop are regularly offered by the HIFIS team. Please see the course catalog for current offerings. If you are affiliated with Helmholtz and would like to have a dedicated workshop for your team, please contact us.