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?
- Git is a centralized VCS
- 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?
- Set your GitLab authentication information.
- Set the metadata for your Git commits.
- 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?
- “Changes”.
- “Added line ‘But the Mummy will appreciate the lack of humidity’ to mars.txt”.
- “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 diffto see what changed in this commit.
Which command(s) below would save the changes of new-file.txt to the local Git repository?
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 changeswith the commit messagenew-file.txt.
Exploring history¶
How is git diff and git diff HEAD different from git diff --staged?
Answer
git diffcompares 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 HEADcompares changes in both your working copy and the staging area with the last commit.git diff --stagedcompares the staging area and the commit you specify. If no commit is specified, it compares the staging area with yourHEAD.
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?
- Both 2 and 4
Answer
The answer is (5) - Both, (2) and (4) are correct.
- The
restorecommand 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 filemars.txt. Answer (2) usesHEADto 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.txtfrom the commit beforeHEAD, 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
Answer
The answer is (2).
- The command
git add mars.txtadds only the initial version ofmars.txtinto the staging area. The changes to the file from the secondechocommand 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 ofmars.txtcommitted to the repository has only one line. Afterwards, the filemars.txtin the working copy still contains the second line and agit statuscommand would show that the file is modified. - Finally,
git restore mars.txtreplaces the working copy with the most recently committed version ofmars.txt. I.e.,cat mars.txtonly 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
- Create the feature branch and switch to it:
git branch <feature branch name>+git switch <feature branch name>. - Perform your task and commit your work: Modify - Add - Commit workflow.
- 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?
git pushgit commitgit pullgit fetchgit switch- Both, (1) and (2)
- Both, (2) and (5)
Answer
The answer is (7) - Both, (2) and (5) are correct.
git push,git pullandgit fetchare used to synchronize your local repository with a remote repository.git commitcreates a new commit in your local Git repository.git switchis used to switch branches in your local Git repository.
How is git push different from git commit?
Answer
git pushpushes commits to another repository.git commitcreates a new commit in the local repository. In contrast tosvn commit,git commitperforms a local operation and does not require network access.
How is git pull different from git fetch?
Answer
git pullupdates the local meta information of the remote Git repository and directly integrates new commits.git fetchonly 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.