Git Fundamentals
- 82Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the primary purpose of a version control system?
What is the primary purpose of a version control system?
82 questions
- 1
What is the primary purpose of a version control system?
- A
To prevent multiple developers from editing the same project at the same time
- B
To record changes to a project over time so its history can be reviewed and earlier states restored
- C
To compile project files into executable programs whenever they are changed
- D
To automatically decide which changes should be released to users
Correct answer
BTo record changes to a project over time so its history can be reviewed and earlier states restored
Explanation
A version control system records project changes over time, making it possible to review history and return to an earlier state.
- A
- 2
How does version control make collaboration easier than passing project copies around manually?
- A
It removes the need for developers to communicate about their changes
- B
It ensures that each developer always edits a separate project that never needs to be combined
- C
It automatically approves and releases every change made by a team member
- D
It tracks changes in a shared history and helps combine work instead of relying on manually exchanged full copies
Correct answer
DIt tracks changes in a shared history and helps combine work instead of relying on manually exchanged full copies
Explanation
Version control tracks project history and supports collaboration, avoiding repeated manual exchanges and merges of whole project copies.
- A
- 3
What is a key limitation of a centralized version control system?
- A
Each team member must store a complete copy of the project's history on their machine
- B
It requires every developer to work without a network connection
- C
If its central server goes offline, team members may be unable to collaborate or save snapshots to the system
- D
It cannot record who made a change or when the change was made
Correct answer
CIf its central server goes offline, team members may be unable to collaborate or save snapshots to the system
Explanation
A centralized system depends on its central server, creating a single point of failure when the server is unavailable.
- A
- 4
What capability does a distributed version control system provide to each team member?
- A
A separate project history that cannot be synchronized with other team members
- B
A local copy of the project and its history, allowing snapshots to be saved on that machine
- C
A connection to a central server that is required for every local commit
- D
A graphical interface that replaces all command-line operations
Correct answer
BA local copy of the project and its history, allowing snapshots to be saved on that machine
Explanation
In a distributed system, each team member has a copy of the project and its history and can save snapshots locally.
- A
- 5
Which pair consists of distributed version control systems?
- A
Git and Mercurial
- B
Subversion and Git
- C
Team Foundation Server and Subversion
- D
Mercurial and Team Foundation Server
Correct answer
AGit and Mercurial
Explanation
Git and Mercurial are distributed systems; Subversion and Team Foundation Server are given as centralized examples.
- A
- 6
Why is Git described as scalable and efficient for branching and merging compared with some other systems?
- A
It stores every project in a central server and prevents parallel work
- B
It uses only graphical tools, which automatically combine all changes
- C
It avoids recording project history until a release is complete
- D
It is free, open source, fast, and performs branching and merging quickly
Correct answer
DIt is free, open source, fast, and performs branching and merging quickly
Explanation
The material identifies Git as free, open source, fast, and scalable, and notes that branching and merging are fast in Git.
- A
- 7
Why is command-line Git useful even for someone who prefers graphical tools?
- A
Git commands can only be run through a terminal on Windows
- B
Some GUI tools have limitations, and a command line may be available where a GUI cannot be installed
- C
A command line automatically makes every Git operation safer
- D
GUI tools cannot show any Git information about project history
Correct answer
BSome GUI tools have limitations, and a command line may be available where a GUI cannot be installed
Explanation
GUI tools may not support every needed feature or be available on a remote machine, so command-line skills remain useful.
- A
- 8
What is a practical approach to choosing between command-line and GUI Git tools?
- A
Use whichever tool best suits the task, and be prepared to use both
- B
Use the command line exclusively because GUI tools cannot support Git
- C
Use a GUI exclusively because command-line Git is unavailable on servers
- D
Choose one tool permanently because using both corrupts repository history
Correct answer
AUse whichever tool best suits the task, and be prepared to use both
Explanation
The material recommends using the right tool for the job; many people use both command-line and GUI tools.
- A
- 9
What is Git Bash on Windows?
- A
A graphical Git history viewer that replaces the Git executable
- B
A command-prompt-style application that emulates Unix or Linux environments
- C
A centralized server for storing Windows repositories
- D
A configuration file that sets Git's default editor
Correct answer
BA command-prompt-style application that emulates Unix or Linux environments
Explanation
Git Bash is a command-prompt-style application that emulates Unix or Linux environments on Windows.
- A
- 10
Which command displays the installed Git version?
- A
git --version - B
git config --version - C
git status --version - D
git version --help
Correct answer
Agit --versionExplanation
Running
git --versionprints the Git version installed on the machine. - A
- 11
Which statement correctly describes Git's system-level configuration?
- A
It applies only to the next commit
- B
It applies to all repositories belonging to the current user
- C
It applies only to the repository in the current folder
- D
It applies to all users of the current computer
Correct answer
DIt applies to all users of the current computer
Explanation
System-level settings apply to all users of the current computer.
- A
- 12
What is the scope of Git's global configuration settings?
- A
They apply only to the current terminal session
- B
They apply to all repositories of the current user
- C
They apply to every user account on the computer
- D
They apply only to the current repository
Correct answer
BThey apply to all repositories of the current user
Explanation
Global settings apply to all repositories belonging to the current user.
- A
- 13
What is the scope of Git's local configuration settings?
- A
They apply to the current repository
- B
They apply to all users of the computer
- C
They apply to all repositories of the current user
- D
They apply to every repository on every computer
Correct answer
AThey apply to the current repository
Explanation
Local settings apply to the repository in the current folder.
- A
- 14
Which command sets the current user's name in Git's global configuration?
- A
git config --local user.name "Your Name" - B
git config --system user.email "Your Name" - C
git config --global user.name "Your Name" - D
git user --global name "Your Name"
Correct answer
Cgit config --global user.name "Your Name"Explanation
The global
user.namesetting can be set withgit config --global user.name, with quotes useful when the value contains a space. - A
- 15
Why might a Git configuration value such as a person's name need quotation marks?
- A
The value contains spaces that should be treated as part of one value
- B
Git requires every configuration value to be enclosed in quotation marks
- C
Quotation marks make the setting apply to all users
- D
Git uses quotation marks to encrypt configuration values
Correct answer
AThe value contains spaces that should be treated as part of one value
Explanation
Quotation marks are needed in the example because the name contains a space; an email address without spaces does not need them for that reason.
- A
- 16
What does the
--waitflag do when configuring VS Code as Git's editor?- A
It opens every file in the repository at once
- B
It makes VS Code wait until Git is uninstalled
- C
It forces Git to use VS Code only for viewing history
- D
It makes the terminal wait until the VS Code instance is closed
Correct answer
DIt makes the terminal wait until the VS Code instance is closed
Explanation
The
--waitflag keeps the terminal waiting until the opened VS Code instance is closed. - A
- 17
What does
git config --global -edo?- A
It lists every commit in all of the user's repositories
- B
It opens the current repository's working directory in an editor
- C
It opens the global Git configuration file in the configured default editor
- D
It deletes the global configuration and restores defaults
Correct answer
CIt opens the global Git configuration file in the configured default editor
Explanation
The
-eoption opens the global configuration file for editing using the default editor. - A
- 18
How should
core.autocrlfgenerally be set on Windows, according to the material?- A
Set it to
input, so Git adds carriage returns on checkout - B
Set it to
true, so Git adjusts line endings when checking in and checking out - C
Leave it unset, so Git converts all files to binary data
- D
Set it to
false, so Git always adds carriage returns when storing files
Correct answer
BSet it to
true, so Git adjusts line endings when checking in and checking outExplanation
On Windows, setting
core.autocrlftotrueremoves carriage returns when storing code and adds them when checking code out. - A
- 19
How should
core.autocrlfgenerally be set on macOS or Linux, according to the material?- A
Set it to
input, so Git modifies line endings when storing code but does not add carriage returns on checkout - B
Set it to
true, so Git adds carriage returns whenever code is checked out - C
Set it to
output, so Git changes line endings only in the working directory - D
Set it to
false, so Git removes every line-feed character when storing code
Correct answer
ASet it to
input, so Git modifies line endings when storing code but does not add carriage returns on checkoutExplanation
On macOS and Linux,
inputtells Git to modify line endings when storing code in the repository, without adding carriage returns on checkout. - A
- 20
Which command opens the full help documentation for
git configin a terminal pager?- A
git help --short config - B
git config --version - C
git config -h - D
git config --help
Correct answer
Dgit config --helpExplanation
git config --helpopens the full documentation; the shortergit config -hprovides a quick summary. - A
- 21
What does
git config -hprovide compared withgit config --help?- A
A short summary of the command and its options
- B
A full list of commits that used the config command
- C
A graphical configuration tool
- D
A complete editable copy of the global configuration file
Correct answer
AA short summary of the command and its options
Explanation
The
-hoption gives a short summary, whereas--helpprovides full documentation. - A
- 22
What does
git initdo when run in a project directory?- A
It downloads a copy of the project from a central server
- B
It creates the first commit with all current files
- C
It adds every file in the directory to the staging area
- D
It initializes an empty Git repository in that directory
Correct answer
DIt initializes an empty Git repository in that directory
Explanation
git initcreates an empty repository in the directory; it does not automatically track the files already there. - A
- 23
Where does Git store information about a repository's history and internal data?
- A
In the staging area inside the working directory
- B
In the system-level configuration file only
- C
In a hidden
.gitsubdirectory inside the project directory - D
In a visible
.historyfile beside every project file
Correct answer
CIn a hidden
.gitsubdirectory inside the project directoryExplanation
Git stores repository information in the hidden
.gitsubdirectory. Removing it removes the repository history from that directory. - A
- 24
What happens if the
.gitdirectory is removed from a project?- A
Only the current branch is removed; all repository data remains available
- B
The project loses its Git repository and its stored project history
- C
Git automatically recreates the directory with the previous history
- D
The project remains a repository, but all files become staged
Correct answer
BThe project loses its Git repository and its stored project history
Explanation
The
.gitdirectory contains the repository data; removing it means the directory is no longer a Git repository and its history is lost. - A
- 25
What does Git's staging area represent?
- A
A list of remote servers for synchronizing work
- B
A backup of files that Git does not track
- C
A permanent copy of every version ever committed
- D
The proposed contents of the next commit
Correct answer
DThe proposed contents of the next commit
Explanation
The staging area, also called the index, holds the changes proposed for the next commit.
- A
- 26
Why is the staging area useful before creating a commit?
- A
It automatically deletes any changes that are not useful
- B
It prevents all untracked files from being created
- C
It lets you review and select changes before recording a snapshot
- D
It replaces the working directory after every file edit
Correct answer
CIt lets you review and select changes before recording a snapshot
Explanation
The staging area allows review and selection, so changes not intended for the next snapshot can be left out or unstaged.
- A
- 27
What does creating a commit do?
- A
It deletes the previous snapshot and keeps only the newest one
- B
It places unstaged changes into a remote server's staging area
- C
It permanently records the staged project state as a snapshot in the repository
- D
It moves every file from the repository into the working directory
Correct answer
CIt permanently records the staged project state as a snapshot in the repository
Explanation
A commit permanently stores the proposed staged snapshot in the repository.
- A
- 28
After a commit, what is normally true of the staging area?
- A
It becomes a copy of the working directory's unstaged changes
- B
It contains only files that were modified after the commit
- C
It reflects the same project snapshot as the new commit rather than becoming empty
- D
It is emptied, so all tracked files become untracked
Correct answer
CIt reflects the same project snapshot as the new commit rather than becoming empty
Explanation
After committing, the staging area reflects the committed snapshot; it does not simply become empty.
- A
- 29
If a tracked file is modified after it has been staged, what must usually happen for the newer content to enter the next commit?
- A
The file must be staged again
- B
The file must be added to
.gitignore - C
The repository must be initialized again
- D
The existing commit must be deleted
Correct answer
AThe file must be staged again
Explanation
Staging captures a snapshot of the file at that time. Later changes remain unstaged until the file is staged again.
- A
- 30
What must be done to include a file deletion in the next commit?
- A
Add the file name to
.gitignore - B
Add the deleted file's old contents back to the working directory
- C
Stage the deletion after removing the file from the working directory
- D
Commit immediately, because Git stages deletions automatically
Correct answer
CStage the deletion after removing the file from the working directory
Explanation
A deletion is a change that must be staged before it is included in a commit.
- A
- 31
What information does a Git commit contain, as described in the material?
- A
A project snapshot, a unique identifier, and information such as what changed, who made it, and when
- B
A pointer to the current working directory, but no project content
- C
Only the commit message and a list of remote servers
- D
Only the lines changed, without any information about the author or date
Correct answer
AA project snapshot, a unique identifier, and information such as what changed, who made it, and when
Explanation
Each commit has a unique identifier and information about the changes, author, and time, along with a complete project snapshot.
- A
- 32
Why does storing complete snapshots in commits not necessarily require storing duplicate file contents repeatedly?
- A
Git saves only the commit message and reconstructs all file contents from memory
- B
Git replaces every old snapshot with the newest one
- C
Git compresses file contents and avoids storing duplicate content
- D
Git stores all repeated content as separate uncompressed copies
Correct answer
CGit compresses file contents and avoids storing duplicate content
Explanation
Although commits represent complete snapshots, Git is efficient about storage by compressing contents and avoiding duplicate content.
- A
- 33
Which command stages all files and subdirectories in the current project directory recursively?
- A
git init . - B
git commit . - C
git status . - D
git add .
Correct answer
Dgit add .Explanation
git add .adds the current directory recursively, so it should be used carefully if unwanted files are present. - A
- 34
What does
git add *.txtdo in the example described?- A
It ignores all files with the
.txtextension - B
It commits all text files immediately
- C
It stages files matching the
.txtpattern - D
It stages every file in the repository, regardless of type
Correct answer
CIt stages files matching the
.txtpatternExplanation
A pattern such as
*.txtcan be used withgit addto stage matching files. - A
- 35
What does
git adddo the first time it is used on a new file?- A
It creates a remote copy of the file
- B
It commits the file directly to the repository
- C
It stages the file so Git begins tracking it for a future commit
- D
It adds the file to
.gitignore
Correct answer
CIt stages the file so Git begins tracking it for a future commit
Explanation
Git does not automatically track files just because a repository was initialized;
git addstages new files for tracking and committing. - A
- 36
What does the
-moption do in a command such asgit commit -m "Initial commit"?- A
It removes the staging area after the commit
- B
It makes the commit include every untracked file
- C
It opens the commit in a visual diff tool
- D
It supplies the commit message directly in the command
Correct answer
DIt supplies the commit message directly in the command
Explanation
The
-moption provides a commit message on the command line. - A
- 37
When is running
git commitwithout-museful?- A
When you want to discard the staging area
- B
When you want Git to commit without any message
- C
When you want to stage files without creating a commit
- D
When you want to write a longer commit message in the configured editor
Correct answer
DWhen you want to write a longer commit message in the configured editor
Explanation
Running
git commitwithout a message option opens the configured editor, allowing a longer description. - A
- 38
Which commit-message practice is recommended for a change that needs extra context?
- A
Leave the message empty and explain the change only in chat
- B
List every unchanged file in the message
- C
Use a concise summary followed by a blank line and a longer explanation
- D
Write one extremely long line with no summary
Correct answer
CUse a concise summary followed by a blank line and a longer explanation
Explanation
A commit message can have a short description followed by a longer explanation that gives context.
- A
- 39
What is a good balance in commit size?
- A
Commit every keystroke so no edit is ever combined with another
- B
Wait until several unrelated tasks are ready and combine them
- C
Commit coherent checkpoints: not every trivial edit, but not only after a very large task
- D
Commit only once after an entire project is finished
Correct answer
CCommit coherent checkpoints: not every trivial edit, but not only after a very large task
Explanation
Commits should be made at useful checkpoints: neither so often that each is trivial nor so rarely that a large body of work is difficult to recover or understand.
- A
- 40
Why should a commit generally represent one logically separate change set?
- A
It keeps unrelated changes separate and makes the commit easier to understand
- B
It ensures every commit contains exactly one changed file
- C
It allows Git to avoid creating a unique identifier
- D
It prevents other developers from viewing the project history
Correct answer
AIt keeps unrelated changes separate and makes the commit easier to understand
Explanation
Separating logically distinct work, such as a bug fix and a typo correction, makes commits and their messages clearer.
- A
- 41
Which commit message best follows the preferred wording convention described?
- A
Signup validation bug had been fixed - B
Fix the signup validation bug - C
The signup validation bug was fixed - D
Fixed the signup validation bug
Correct answer
BFix the signup validation bugExplanation
The material says many developers prefer present-tense wording, such as “fix the bug.” The important point is also to use a consistent team convention.
- A
- 42
When is it appropriate to use
git commit -ato skip manually staging changes?- A
Whenever the repository contains untracked files that should be committed
- B
Whenever you want to commit only a selected subset of staged changes
- C
When you are sure the tracked-file changes do not need staging-area review
- D
Whenever you want Git to stage ignored files
Correct answer
CWhen you are sure the tracked-file changes do not need staging-area review
Explanation
The
-aoption can commit modified tracked files without a separate staging step, but the material advises staging and reviewing changes in most cases. - A
- 43
Which type of file is often appropriate to exclude from a repository using
.gitignore?- A
A test file that documents expected application behavior
- B
A source file required for every developer to build the project
- C
A carefully maintained configuration file needed by the whole team
- D
A generated log file that is specific to one developer's machine
Correct answer
DA generated log file that is specific to one developer's machine
Explanation
Generated logs and other machine-specific or unnecessary files can add repository size without providing shared value.
- A
- 44
Where should a project's
.gitignorefile generally be placed in the example?- A
Beside each file that should be ignored
- B
Inside the hidden
.gitdirectory only - C
In the user's home directory for every repository
- D
In the root of the project
Correct answer
DIn the root of the project
Explanation
The example creates
.gitignorein the root of the project and lists files, patterns, or directories to ignore there. - A
- 45
What does the
.gitignoreentrylogs/indicate?- A
Git should rename the
logsdirectory - B
Git should stage all files beneath
logs - C
Git should ignore the
logsdirectory - D
Git should ignore only a file named exactly
logs
Correct answer
CGit should ignore the
logsdirectoryExplanation
The trailing slash in
logs/indicates a directory to ignore. - A
- 46
What is an important limitation of adding a file to
.gitignoreafter Git already tracks it?- A
Git immediately removes the file from both the working directory and the repository
- B
The ignore rule applies only after the next
git init - C
Git turns the file into an untracked file without any other action
- D
The ignore rule alone will not stop Git from tracking changes to that file
Correct answer
DThe ignore rule alone will not stop Git from tracking changes to that file
Explanation
.gitignoreaffects files Git has not already included in the repository; tracked files need to be removed from the index to stop being tracked. - A
- 47
How can a tracked directory be removed from Git's index while keeping the directory in the working directory?
- A
Use
git rm -ron the directory - B
Use
git rm --cached -ron the directory - C
Add the directory to
.gitignorewithout changing the index - D
Use
rm -rand then commit without staging
Correct answer
BUse
git rm --cached -ron the directoryExplanation
git rm --cached -rremoves a directory recursively from the index while leaving it in the working directory. - A
- 48
What does
git rm file.txtnormally do?- A
It deletes the file from the latest commit without making a new commit
- B
It removes the file from both the working directory and the staging area
- C
It adds the file to
.gitignoreand leaves it untouched - D
It removes the file only from the staging area and keeps it in the working directory
Correct answer
BIt removes the file from both the working directory and the staging area
Explanation
git rmstages the removal and removes the file from the working directory, combining both operations. - A
- 49
What is needed to rename or move a file using ordinary filesystem commands and then have Git record the result?
- A
Make the rename in the working directory, then stage the resulting deletion and addition
- B
Commit the old file first, then create a new repository
- C
Rename the file only in
.git, then rungit init - D
Add the new name to
.gitignoreand leave the old file staged
Correct answer
AMake the rename in the working directory, then stage the resulting deletion and addition
Explanation
With an ordinary move command, Git sees a deletion and a new untracked file; staging both lets Git recognize the rename.
- A
- 50
What does
git mvdo for a rename compared with using an ordinary move command?- A
It renames only the commit message while leaving the file in place
- B
It creates a new repository at the destination
- C
It applies the rename to both the working directory and the staging area
- D
It moves the file only in the staging area and not in the working directory
Correct answer
CIt applies the rename to both the working directory and the staging area
Explanation
git mvupdates both the working directory and staging area for the rename. - A
- 51
Why might compiled binaries or generated class files be excluded from a repository?
- A
They contain the complete project history and duplicate the
.gitdirectory - B
They cannot be stored in Git because Git tracks only text files
- C
They prevent all team members from creating commits
- D
They are generated by building the project and can unnecessarily increase repository size
Correct answer
DThey are generated by building the project and can unnecessarily increase repository size
Explanation
Generated files such as compiled binaries or Java class files can often be recreated and needlessly increase repository size.
- A
- 52
Which statement about
git statusis correct?- A
It reports the state of the working directory and staging area
- B
It permanently stages all modified files
- C
It lists only the remote repositories configured for the project
- D
It displays the full content of every commit
Correct answer
AIt reports the state of the working directory and staging area
Explanation
git statusreports which changes are staged, unstaged, or untracked. - A
- 53
In
git status --short, what do the two status columns represent?- A
The left column represents local branches, and the right column represents remote branches
- B
The left column represents the working directory, and the right column represents the repository history
- C
The left column represents the staging area, and the right column represents the working directory
- D
The left column represents file size, and the right column represents file permissions
Correct answer
CThe left column represents the staging area, and the right column represents the working directory
Explanation
In short status output, the left column reports staged state and the right column reports working-directory state.
- A
- 54
In short status output, what does
??mean for a file?- A
The file is modified in both the staging area and working directory
- B
The file has been staged for deletion
- C
The file is ignored by Git
- D
The file is untracked
Correct answer
DThe file is untracked
Explanation
Two question marks indicate an untracked file.
- A
- 55
If a file has an
Monly in the right column ofgit status --short, what does that indicate?- A
It has unstaged modifications in the working directory
- B
It is a newly added untracked file
- C
It has been deleted from the last commit
- D
It has staged modifications and no further working changes
Correct answer
AIt has unstaged modifications in the working directory
Explanation
A modification marker in the right column indicates changes in the working directory that are not staged.
- A
- 56
What does a green
Min the left column of short status output indicate?- A
A modified file has changes staged for the next commit
- B
A file is untracked and ignored
- C
A file has been deleted from the repository history
- D
A modified file has changes only in the working directory
Correct answer
AA modified file has changes staged for the next commit
Explanation
The left column represents the staging area, so an
Mthere indicates staged modifications. - A
- 57
Which command shows staged changes that are proposed for the next commit?
- A
git log --staged - B
git diff --staged - C
git status --staged - D
git diff
Correct answer
Bgit diff --stagedExplanation
git diff --stagedcompares the staged version with the last commit and shows what will go into the next commit. - A
- 58
What does
git diffwith no arguments show?- A
Every change made in the repository's full history
- B
Staged changes between the staging area and the last commit
- C
Only untracked files that are not in
.gitignore - D
Unstaged changes between the working directory and the staging area
Correct answer
DUnstaged changes between the working directory and the staging area
Explanation
Without arguments,
git diffcompares the working directory with the staging area, showing unstaged changes. - A
- 59
In the usual diff display, what do
-and+lines indicate?- A
A minus line is staged, and a plus line is untracked
- B
A minus line is from the old version, and a plus line is from the new version
- C
A minus line is ignored, and a plus line is deleted
- D
A minus line is a commit message, and a plus line is an author name
Correct answer
BA minus line is from the old version, and a plus line is from the new version
Explanation
Diff output uses minus signs for lines in the old copy and plus signs for lines in the new copy.
- A
- 60
Why might a diff show only a chunk of a long file rather than the entire file?
- A
Git shows only lines that are untracked
- B
Git permanently removes unchanged sections from the file
- C
Git cannot compare files with more than a few lines
- D
Git displays sections around the changed lines to provide context without showing the whole file
Correct answer
DGit displays sections around the changed lines to provide context without showing the whole file
Explanation
A diff divides a file into chunks and displays relevant context around changes rather than necessarily showing every line.
- A
- 61
Why might a developer use a visual diff tool instead of reading diff output in a terminal?
- A
A visual tool can show changes only when the repository is offline
- B
A visual tool automatically commits every displayed change
- C
A visual tool can make differences between old and new copies easier to see
- D
A visual tool is required for Git to save staged changes
Correct answer
CA visual tool can make differences between old and new copies easier to see
Explanation
Visual tools can make file comparisons easier to inspect, though terminal diff output remains useful to understand.
- A
- 62
What is the main purpose of
git log?- A
To open the current commit in a text editor
- B
To stage all modified files and create a commit
- C
To show only the current working directory's untracked files
- D
To display the repository's commits, typically from newest to oldest
Correct answer
DTo display the repository's commits, typically from newest to oldest
Explanation
git logdisplays the commit history, with the newest commit shown first by default. - A
- 63
What does the
--onelineoption add togit logoutput?- A
A compact summary with a shortened commit identifier and one-line description
- B
A complete file-by-file snapshot for every commit
- C
A graphical view of all working-directory changes
- D
A full list of author emails and commit timestamps
Correct answer
AA compact summary with a shortened commit identifier and one-line description
Explanation
git log --onelinegives a short summary of each commit, including a shortened identifier and its one-line message. - A
- 64
What effect does
git log --oneline --reversehave?- A
It shows the history of the current file in reverse alphabetical order
- B
It removes commit identifiers from the output
- C
It displays commits from earliest to latest
- D
It displays only commits that changed file names
Correct answer
CIt displays commits from earliest to latest
Explanation
The
--reverseoption reverses the usual ordering so the earliest commit appears first. - A
- 65
What is a Git commit identifier?
- A
A sequential revision number that increases by one for each commit
- B
A file path that identifies the working directory
- C
A branch name shared by all commits in the repository
- D
A unique hexadecimal identifier generated for a commit
Correct answer
DA unique hexadecimal identifier generated for a commit
Explanation
Git generates a unique identifier for each commit; it is a hexadecimal string rather than a simple increasing revision number.
- A
- 66
When can an abbreviated commit identifier be used to refer to a commit?
- A
When the abbreviation is long enough to identify that commit without ambiguity
- B
Only when the commit has no parent
- C
Only when all 40 hexadecimal characters are included
- D
Only when the commit is the latest one
Correct answer
AWhen the abbreviation is long enough to identify that commit without ambiguity
Explanation
A shortened identifier can be used as long as it is unambiguous among the repository's commits.
- A
- 67
What does
HEADindicate in the branch model described?- A
The reference to the branch currently being worked on
- B
The next untracked file to be added
- C
The first commit ever made in the repository
- D
The system-level Git configuration
Correct answer
AThe reference to the branch currently being worked on
Explanation
HEADis a reference that tells Git which branch is currently checked out. - A
- 68
What does
HEAD~1refer to?- A
The first commit on every branch
- B
The current commit's first changed file
- C
The next commit that will be created
- D
The commit one step before the commit currently referenced by
HEAD
Correct answer
DThe commit one step before the commit currently referenced by
HEADExplanation
Starting at
HEAD,~1moves one commit back to its previous commit. - A
- 69
What can
git show <commit>display?- A
The contents of every file in the working directory without history
- B
Only the current contents of the staging area
- C
Information about the specified commit and a diff of its changes
- D
A list of ignored files and directory patterns
Correct answer
CInformation about the specified commit and a diff of its changes
Explanation
git showcan display commit details and the changes introduced by that commit. - A
- 70
How can
git showdisplay the version of one file stored in a particular commit?- A
Use
git showfollowed by the name of the current branch only - B
Specify the commit followed by a colon and the file path
- C
Use
git showwithout a commit or a path - D
Specify the file path followed by
--staged
Correct answer
BSpecify the commit followed by a colon and the file path
Explanation
A commit followed by a colon and a file path asks Git to show that file's contents from that commit.
- A
- 71
What does
git ls-treelist for a commit?- A
All Git configuration settings for the repository
- B
Only the unstaged modifications in the working directory
- C
Only the commit messages on the current branch
- D
Files and directories stored in that commit's tree
Correct answer
DFiles and directories stored in that commit's tree
Explanation
git ls-treelists the files and directories represented in a commit's tree. - A
- 72
How are files and directories represented among Git's stored objects?
- A
Files are represented as blobs, and directories are represented as trees
- B
Files are represented as tags, and directories are represented as blobs
- C
Files are represented as trees, and directories are represented as commits
- D
Files and directories are both represented only as branch names
Correct answer
AFiles are represented as blobs, and directories are represented as trees
Explanation
Git represents file contents as blobs and directories as trees; commits and tags are also object types.
- A
- 73
What does
git restore --staged file.jsdo to a staged modification?- A
It discards the working-directory change and commits the old version
- B
It permanently deletes the file from both the working directory and repository
- C
It removes the staged version of the modification, leaving the working-directory change unstaged
- D
It restores the file from the latest remote server
Correct answer
CIt removes the staged version of the modification, leaving the working-directory change unstaged
Explanation
Restoring a file with
--stagedrestores the staging-area copy from the last commit, leaving any newer working-directory changes unstaged. - A
- 74
When
git restore --stagedis used on a newly staged file that has never been committed, what happens?- A
The file is committed automatically
- B
The file is deleted from the working directory
- C
The file is restored from the previous commit
- D
The file is removed from the staging area and becomes untracked
Correct answer
DThe file is removed from the staging area and becomes untracked
Explanation
A new file has no version in the last commit, so restoring it in the staging area removes it from the index and returns it to an untracked state.
- A
- 75
What does
git restore file.jsdo when the file has unstaged local changes?- A
It adds the local changes to the staging area
- B
It removes the file from the repository and working directory
- C
It replaces the working-directory copy with the version from the staging area
- D
It restores the file from the commit before the last commit
Correct answer
CIt replaces the working-directory copy with the version from the staging area
Explanation
Without
--stagedor a different source,git restorereplaces working-directory changes with the version in the staging area. - A
- 76
Why does
git restore file.jsnot remove a new untracked file?- A
The command restores untracked files only when a remote is online
- B
The file must first be added to
.gitignore - C
Git automatically stages every untracked file before restoring
- D
Git has no tracked previous version of that file to restore
Correct answer
DGit has no tracked previous version of that file to restore
Explanation
Git cannot restore an untracked file from a prior version because it has not been tracking or storing that file.
- A
- 77
Which command can remove untracked files after confirming that they are unwanted?
- A
git clean -f - B
git rm --cached - C
git log --reverse - D
git restore --staged
Correct answer
Agit clean -fExplanation
git clean -fforces removal of untracked files. This is dangerous because removed untracked files cannot be recovered from Git. - A
- 78
What does the
-doption add when used withgit clean -f?- A
It allows removal of untracked directories as well as files
- B
It restores deleted directories from the last commit
- C
It deletes the
.gitdirectory and all repository history - D
It displays a diff before staging changes
Correct answer
AIt allows removal of untracked directories as well as files
Explanation
The
-doption tellsgit cleanto remove whole untracked directories as well. - A
- 79
How can a tracked file be restored from a commit other than the most recent one?
- A
Use
git init <commit> <path> - B
Use
git add --source=<commit> <path> - C
Use
git clean -f <commit> <path> - D
Use
git restore --source=<commit> <path>
Correct answer
DUse
git restore --source=<commit> <path>Explanation
The
--sourceoption specifies the commit from which Git should restore the file. - A
- 80
What does
git restore --source=HEAD~1 file.jsrequest?- A
Stage
file.jsfrom the latest commit without changing its contents - B
Delete
file.jsfrom the current branch and all earlier commits - C
Restore
file.jsfrom the working directory into the last commit - D
Restore
file.jsfrom the commit one step beforeHEAD
Correct answer
DRestore
file.jsfrom the commit one step beforeHEADExplanation
HEAD~1identifies the commit immediately before the one referenced byHEAD, so the command restores the file version from that earlier commit. - A
- 81
How can a deleted tracked file be restored from the commit before its deletion?
- A
Use
git rm --cached <file> - B
Use
git status --short <file> - C
Use
git restore --source=HEAD~1 <file> - D
Use
git clean -fd <file>
Correct answer
CUse
git restore --source=HEAD~1 <file>Explanation
Specifying the earlier commit as the source restores the file's contents from that commit into the working directory.
- A
- 82
Which statement distinguishes restoring a file from undoing a commit?
- A
Restoring a file always creates a new commit without user action
- B
Restoring a file rewrites every branch that contains the commit
- C
Restoring a file to an earlier version changes the file in the working directory; it does not itself undo the commit that recorded a deletion
- D
Restoring a file automatically removes the commit that deleted it from history
Correct answer
CRestoring a file to an earlier version changes the file in the working directory; it does not itself undo the commit that recorded a deletion
Explanation
The described restore operation retrieves a file version; undoing or reverting the commit itself is a separate operation.
- A

Ask anything
We've read this whole study set, so questions about it get the best answers.