1. Home
  2. Explore
  3. Computer Science
  4. Git Fundamentals

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Git Fundamentals

  • 82Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Git Foundations

What is the primary purpose of a version control system?

82 questions

  1. 1

    What is the primary purpose of a version control system?

    1. A

      To prevent multiple developers from editing the same project at the same time

    2. B

      To record changes to a project over time so its history can be reviewed and earlier states restored

    3. C

      To compile project files into executable programs whenever they are changed

    4. D

      To automatically decide which changes should be released to users

    Correct answer
    B

    To 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.

  2. 2

    How does version control make collaboration easier than passing project copies around manually?

    1. A

      It removes the need for developers to communicate about their changes

    2. B

      It ensures that each developer always edits a separate project that never needs to be combined

    3. C

      It automatically approves and releases every change made by a team member

    4. D

      It tracks changes in a shared history and helps combine work instead of relying on manually exchanged full copies

    Correct answer
    D

    It 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.

  3. 3

    What is a key limitation of a centralized version control system?

    1. A

      Each team member must store a complete copy of the project's history on their machine

    2. B

      It requires every developer to work without a network connection

    3. C

      If its central server goes offline, team members may be unable to collaborate or save snapshots to the system

    4. D

      It cannot record who made a change or when the change was made

    Correct answer
    C

    If 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.

  4. 4

    What capability does a distributed version control system provide to each team member?

    1. A

      A separate project history that cannot be synchronized with other team members

    2. B

      A local copy of the project and its history, allowing snapshots to be saved on that machine

    3. C

      A connection to a central server that is required for every local commit

    4. D

      A graphical interface that replaces all command-line operations

    Correct answer
    B

    A 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.

  5. 5

    Which pair consists of distributed version control systems?

    1. A

      Git and Mercurial

    2. B

      Subversion and Git

    3. C

      Team Foundation Server and Subversion

    4. D

      Mercurial and Team Foundation Server

    Correct answer
    A

    Git and Mercurial

    Explanation

    Git and Mercurial are distributed systems; Subversion and Team Foundation Server are given as centralized examples.

  6. 6

    Why is Git described as scalable and efficient for branching and merging compared with some other systems?

    1. A

      It stores every project in a central server and prevents parallel work

    2. B

      It uses only graphical tools, which automatically combine all changes

    3. C

      It avoids recording project history until a release is complete

    4. D

      It is free, open source, fast, and performs branching and merging quickly

    Correct answer
    D

    It 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.

  7. 7

    Why is command-line Git useful even for someone who prefers graphical tools?

    1. A

      Git commands can only be run through a terminal on Windows

    2. B

      Some GUI tools have limitations, and a command line may be available where a GUI cannot be installed

    3. C

      A command line automatically makes every Git operation safer

    4. D

      GUI tools cannot show any Git information about project history

    Correct answer
    B

    Some 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.

  8. 8

    What is a practical approach to choosing between command-line and GUI Git tools?

    1. A

      Use whichever tool best suits the task, and be prepared to use both

    2. B

      Use the command line exclusively because GUI tools cannot support Git

    3. C

      Use a GUI exclusively because command-line Git is unavailable on servers

    4. D

      Choose one tool permanently because using both corrupts repository history

    Correct answer
    A

    Use 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.

  9. 9

    What is Git Bash on Windows?

    1. A

      A graphical Git history viewer that replaces the Git executable

    2. B

      A command-prompt-style application that emulates Unix or Linux environments

    3. C

      A centralized server for storing Windows repositories

    4. D

      A configuration file that sets Git's default editor

    Correct answer
    B

    A 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.

  10. 10

    Which command displays the installed Git version?

    1. A

      git --version

    2. B

      git config --version

    3. C

      git status --version

    4. D

      git version --help

    Correct answer
    A

    git --version

    Explanation

    Running git --version prints the Git version installed on the machine.

  11. 11

    Which statement correctly describes Git's system-level configuration?

    1. A

      It applies only to the next commit

    2. B

      It applies to all repositories belonging to the current user

    3. C

      It applies only to the repository in the current folder

    4. D

      It applies to all users of the current computer

    Correct answer
    D

    It applies to all users of the current computer

    Explanation

    System-level settings apply to all users of the current computer.

  12. 12

    What is the scope of Git's global configuration settings?

    1. A

      They apply only to the current terminal session

    2. B

      They apply to all repositories of the current user

    3. C

      They apply to every user account on the computer

    4. D

      They apply only to the current repository

    Correct answer
    B

    They apply to all repositories of the current user

    Explanation

    Global settings apply to all repositories belonging to the current user.

  13. 13

    What is the scope of Git's local configuration settings?

    1. A

      They apply to the current repository

    2. B

      They apply to all users of the computer

    3. C

      They apply to all repositories of the current user

    4. D

      They apply to every repository on every computer

    Correct answer
    A

    They apply to the current repository

    Explanation

    Local settings apply to the repository in the current folder.

  14. 14

    Which command sets the current user's name in Git's global configuration?

    1. A

      git config --local user.name "Your Name"

    2. B

      git config --system user.email "Your Name"

    3. C

      git config --global user.name "Your Name"

    4. D

      git user --global name "Your Name"

    Correct answer
    C

    git config --global user.name "Your Name"

    Explanation

    The global user.name setting can be set with git config --global user.name, with quotes useful when the value contains a space.

  15. 15

    Why might a Git configuration value such as a person's name need quotation marks?

    1. A

      The value contains spaces that should be treated as part of one value

    2. B

      Git requires every configuration value to be enclosed in quotation marks

    3. C

      Quotation marks make the setting apply to all users

    4. D

      Git uses quotation marks to encrypt configuration values

    Correct answer
    A

    The 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.

  16. 16

    What does the --wait flag do when configuring VS Code as Git's editor?

    1. A

      It opens every file in the repository at once

    2. B

      It makes VS Code wait until Git is uninstalled

    3. C

      It forces Git to use VS Code only for viewing history

    4. D

      It makes the terminal wait until the VS Code instance is closed

    Correct answer
    D

    It makes the terminal wait until the VS Code instance is closed

    Explanation

    The --wait flag keeps the terminal waiting until the opened VS Code instance is closed.

  17. 17

    What does git config --global -e do?

    1. A

      It lists every commit in all of the user's repositories

    2. B

      It opens the current repository's working directory in an editor

    3. C

      It opens the global Git configuration file in the configured default editor

    4. D

      It deletes the global configuration and restores defaults

    Correct answer
    C

    It opens the global Git configuration file in the configured default editor

    Explanation

    The -e option opens the global configuration file for editing using the default editor.

  18. 18

    How should core.autocrlf generally be set on Windows, according to the material?

    1. A

      Set it to input, so Git adds carriage returns on checkout

    2. B

      Set it to true, so Git adjusts line endings when checking in and checking out

    3. C

      Leave it unset, so Git converts all files to binary data

    4. D

      Set it to false, so Git always adds carriage returns when storing files

    Correct answer
    B

    Set it to true, so Git adjusts line endings when checking in and checking out

    Explanation

    On Windows, setting core.autocrlf to true removes carriage returns when storing code and adds them when checking code out.

  19. 19

    How should core.autocrlf generally be set on macOS or Linux, according to the material?

    1. A

      Set it to input, so Git modifies line endings when storing code but does not add carriage returns on checkout

    2. B

      Set it to true, so Git adds carriage returns whenever code is checked out

    3. C

      Set it to output, so Git changes line endings only in the working directory

    4. D

      Set it to false, so Git removes every line-feed character when storing code

    Correct answer
    A

    Set it to input, so Git modifies line endings when storing code but does not add carriage returns on checkout

    Explanation

    On macOS and Linux, input tells Git to modify line endings when storing code in the repository, without adding carriage returns on checkout.

  20. 20

    Which command opens the full help documentation for git config in a terminal pager?

    1. A

      git help --short config

    2. B

      git config --version

    3. C

      git config -h

    4. D

      git config --help

    Correct answer
    D

    git config --help

    Explanation

    git config --help opens the full documentation; the shorter git config -h provides a quick summary.

  21. 21

    What does git config -h provide compared with git config --help?

    1. A

      A short summary of the command and its options

    2. B

      A full list of commits that used the config command

    3. C

      A graphical configuration tool

    4. D

      A complete editable copy of the global configuration file

    Correct answer
    A

    A short summary of the command and its options

    Explanation

    The -h option gives a short summary, whereas --help provides full documentation.

  22. 22

    What does git init do when run in a project directory?

    1. A

      It downloads a copy of the project from a central server

    2. B

      It creates the first commit with all current files

    3. C

      It adds every file in the directory to the staging area

    4. D

      It initializes an empty Git repository in that directory

    Correct answer
    D

    It initializes an empty Git repository in that directory

    Explanation

    git init creates an empty repository in the directory; it does not automatically track the files already there.

  23. 23

    Where does Git store information about a repository's history and internal data?

    1. A

      In the staging area inside the working directory

    2. B

      In the system-level configuration file only

    3. C

      In a hidden .git subdirectory inside the project directory

    4. D

      In a visible .history file beside every project file

    Correct answer
    C

    In a hidden .git subdirectory inside the project directory

    Explanation

    Git stores repository information in the hidden .git subdirectory. Removing it removes the repository history from that directory.

  24. 24

    What happens if the .git directory is removed from a project?

    1. A

      Only the current branch is removed; all repository data remains available

    2. B

      The project loses its Git repository and its stored project history

    3. C

      Git automatically recreates the directory with the previous history

    4. D

      The project remains a repository, but all files become staged

    Correct answer
    B

    The project loses its Git repository and its stored project history

    Explanation

    The .git directory contains the repository data; removing it means the directory is no longer a Git repository and its history is lost.

  25. 25

    What does Git's staging area represent?

    1. A

      A list of remote servers for synchronizing work

    2. B

      A backup of files that Git does not track

    3. C

      A permanent copy of every version ever committed

    4. D

      The proposed contents of the next commit

    Correct answer
    D

    The proposed contents of the next commit

    Explanation

    The staging area, also called the index, holds the changes proposed for the next commit.

  26. 26

    Why is the staging area useful before creating a commit?

    1. A

      It automatically deletes any changes that are not useful

    2. B

      It prevents all untracked files from being created

    3. C

      It lets you review and select changes before recording a snapshot

    4. D

      It replaces the working directory after every file edit

    Correct answer
    C

    It 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.

  27. 27

    What does creating a commit do?

    1. A

      It deletes the previous snapshot and keeps only the newest one

    2. B

      It places unstaged changes into a remote server's staging area

    3. C

      It permanently records the staged project state as a snapshot in the repository

    4. D

      It moves every file from the repository into the working directory

    Correct answer
    C

    It permanently records the staged project state as a snapshot in the repository

    Explanation

    A commit permanently stores the proposed staged snapshot in the repository.

  28. 28

    After a commit, what is normally true of the staging area?

    1. A

      It becomes a copy of the working directory's unstaged changes

    2. B

      It contains only files that were modified after the commit

    3. C

      It reflects the same project snapshot as the new commit rather than becoming empty

    4. D

      It is emptied, so all tracked files become untracked

    Correct answer
    C

    It 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.

  29. 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?

    1. A

      The file must be staged again

    2. B

      The file must be added to .gitignore

    3. C

      The repository must be initialized again

    4. D

      The existing commit must be deleted

    Correct answer
    A

    The 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.

  30. 30

    What must be done to include a file deletion in the next commit?

    1. A

      Add the file name to .gitignore

    2. B

      Add the deleted file's old contents back to the working directory

    3. C

      Stage the deletion after removing the file from the working directory

    4. D

      Commit immediately, because Git stages deletions automatically

    Correct answer
    C

    Stage 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.

  31. 31

    What information does a Git commit contain, as described in the material?

    1. A

      A project snapshot, a unique identifier, and information such as what changed, who made it, and when

    2. B

      A pointer to the current working directory, but no project content

    3. C

      Only the commit message and a list of remote servers

    4. D

      Only the lines changed, without any information about the author or date

    Correct answer
    A

    A 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.

  32. 32

    Why does storing complete snapshots in commits not necessarily require storing duplicate file contents repeatedly?

    1. A

      Git saves only the commit message and reconstructs all file contents from memory

    2. B

      Git replaces every old snapshot with the newest one

    3. C

      Git compresses file contents and avoids storing duplicate content

    4. D

      Git stores all repeated content as separate uncompressed copies

    Correct answer
    C

    Git 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.

  33. 33

    Which command stages all files and subdirectories in the current project directory recursively?

    1. A

      git init .

    2. B

      git commit .

    3. C

      git status .

    4. D

      git add .

    Correct answer
    D

    git add .

    Explanation

    git add . adds the current directory recursively, so it should be used carefully if unwanted files are present.

  34. 34

    What does git add *.txt do in the example described?

    1. A

      It ignores all files with the .txt extension

    2. B

      It commits all text files immediately

    3. C

      It stages files matching the .txt pattern

    4. D

      It stages every file in the repository, regardless of type

    Correct answer
    C

    It stages files matching the .txt pattern

    Explanation

    A pattern such as *.txt can be used with git add to stage matching files.

  35. 35

    What does git add do the first time it is used on a new file?

    1. A

      It creates a remote copy of the file

    2. B

      It commits the file directly to the repository

    3. C

      It stages the file so Git begins tracking it for a future commit

    4. D

      It adds the file to .gitignore

    Correct answer
    C

    It 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 add stages new files for tracking and committing.

  36. 36

    What does the -m option do in a command such as git commit -m "Initial commit"?

    1. A

      It removes the staging area after the commit

    2. B

      It makes the commit include every untracked file

    3. C

      It opens the commit in a visual diff tool

    4. D

      It supplies the commit message directly in the command

    Correct answer
    D

    It supplies the commit message directly in the command

    Explanation

    The -m option provides a commit message on the command line.

  37. 37

    When is running git commit without -m useful?

    1. A

      When you want to discard the staging area

    2. B

      When you want Git to commit without any message

    3. C

      When you want to stage files without creating a commit

    4. D

      When you want to write a longer commit message in the configured editor

    Correct answer
    D

    When you want to write a longer commit message in the configured editor

    Explanation

    Running git commit without a message option opens the configured editor, allowing a longer description.

  38. 38

    Which commit-message practice is recommended for a change that needs extra context?

    1. A

      Leave the message empty and explain the change only in chat

    2. B

      List every unchanged file in the message

    3. C

      Use a concise summary followed by a blank line and a longer explanation

    4. D

      Write one extremely long line with no summary

    Correct answer
    C

    Use 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.

  39. 39

    What is a good balance in commit size?

    1. A

      Commit every keystroke so no edit is ever combined with another

    2. B

      Wait until several unrelated tasks are ready and combine them

    3. C

      Commit coherent checkpoints: not every trivial edit, but not only after a very large task

    4. D

      Commit only once after an entire project is finished

    Correct answer
    C

    Commit 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.

  40. 40

    Why should a commit generally represent one logically separate change set?

    1. A

      It keeps unrelated changes separate and makes the commit easier to understand

    2. B

      It ensures every commit contains exactly one changed file

    3. C

      It allows Git to avoid creating a unique identifier

    4. D

      It prevents other developers from viewing the project history

    Correct answer
    A

    It 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.

  41. 41

    Which commit message best follows the preferred wording convention described?

    1. A

      Signup validation bug had been fixed

    2. B

      Fix the signup validation bug

    3. C

      The signup validation bug was fixed

    4. D

      Fixed the signup validation bug

    Correct answer
    B

    Fix the signup validation bug

    Explanation

    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.

  42. 42

    When is it appropriate to use git commit -a to skip manually staging changes?

    1. A

      Whenever the repository contains untracked files that should be committed

    2. B

      Whenever you want to commit only a selected subset of staged changes

    3. C

      When you are sure the tracked-file changes do not need staging-area review

    4. D

      Whenever you want Git to stage ignored files

    Correct answer
    C

    When you are sure the tracked-file changes do not need staging-area review

    Explanation

    The -a option can commit modified tracked files without a separate staging step, but the material advises staging and reviewing changes in most cases.

  43. 43

    Which type of file is often appropriate to exclude from a repository using .gitignore?

    1. A

      A test file that documents expected application behavior

    2. B

      A source file required for every developer to build the project

    3. C

      A carefully maintained configuration file needed by the whole team

    4. D

      A generated log file that is specific to one developer's machine

    Correct answer
    D

    A 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.

  44. 44

    Where should a project's .gitignore file generally be placed in the example?

    1. A

      Beside each file that should be ignored

    2. B

      Inside the hidden .git directory only

    3. C

      In the user's home directory for every repository

    4. D

      In the root of the project

    Correct answer
    D

    In the root of the project

    Explanation

    The example creates .gitignore in the root of the project and lists files, patterns, or directories to ignore there.

  45. 45

    What does the .gitignore entry logs/ indicate?

    1. A

      Git should rename the logs directory

    2. B

      Git should stage all files beneath logs

    3. C

      Git should ignore the logs directory

    4. D

      Git should ignore only a file named exactly logs

    Correct answer
    C

    Git should ignore the logs directory

    Explanation

    The trailing slash in logs/ indicates a directory to ignore.

  46. 46

    What is an important limitation of adding a file to .gitignore after Git already tracks it?

    1. A

      Git immediately removes the file from both the working directory and the repository

    2. B

      The ignore rule applies only after the next git init

    3. C

      Git turns the file into an untracked file without any other action

    4. D

      The ignore rule alone will not stop Git from tracking changes to that file

    Correct answer
    D

    The ignore rule alone will not stop Git from tracking changes to that file

    Explanation

    .gitignore affects files Git has not already included in the repository; tracked files need to be removed from the index to stop being tracked.

  47. 47

    How can a tracked directory be removed from Git's index while keeping the directory in the working directory?

    1. A

      Use git rm -r on the directory

    2. B

      Use git rm --cached -r on the directory

    3. C

      Add the directory to .gitignore without changing the index

    4. D

      Use rm -r and then commit without staging

    Correct answer
    B

    Use git rm --cached -r on the directory

    Explanation

    git rm --cached -r removes a directory recursively from the index while leaving it in the working directory.

  48. 48

    What does git rm file.txt normally do?

    1. A

      It deletes the file from the latest commit without making a new commit

    2. B

      It removes the file from both the working directory and the staging area

    3. C

      It adds the file to .gitignore and leaves it untouched

    4. D

      It removes the file only from the staging area and keeps it in the working directory

    Correct answer
    B

    It removes the file from both the working directory and the staging area

    Explanation

    git rm stages the removal and removes the file from the working directory, combining both operations.

  49. 49

    What is needed to rename or move a file using ordinary filesystem commands and then have Git record the result?

    1. A

      Make the rename in the working directory, then stage the resulting deletion and addition

    2. B

      Commit the old file first, then create a new repository

    3. C

      Rename the file only in .git, then run git init

    4. D

      Add the new name to .gitignore and leave the old file staged

    Correct answer
    A

    Make 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.

  50. 50

    What does git mv do for a rename compared with using an ordinary move command?

    1. A

      It renames only the commit message while leaving the file in place

    2. B

      It creates a new repository at the destination

    3. C

      It applies the rename to both the working directory and the staging area

    4. D

      It moves the file only in the staging area and not in the working directory

    Correct answer
    C

    It applies the rename to both the working directory and the staging area

    Explanation

    git mv updates both the working directory and staging area for the rename.

  51. 51

    Why might compiled binaries or generated class files be excluded from a repository?

    1. A

      They contain the complete project history and duplicate the .git directory

    2. B

      They cannot be stored in Git because Git tracks only text files

    3. C

      They prevent all team members from creating commits

    4. D

      They are generated by building the project and can unnecessarily increase repository size

    Correct answer
    D

    They 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.

  52. 52

    Which statement about git status is correct?

    1. A

      It reports the state of the working directory and staging area

    2. B

      It permanently stages all modified files

    3. C

      It lists only the remote repositories configured for the project

    4. D

      It displays the full content of every commit

    Correct answer
    A

    It reports the state of the working directory and staging area

    Explanation

    git status reports which changes are staged, unstaged, or untracked.

  53. 53

    In git status --short, what do the two status columns represent?

    1. A

      The left column represents local branches, and the right column represents remote branches

    2. B

      The left column represents the working directory, and the right column represents the repository history

    3. C

      The left column represents the staging area, and the right column represents the working directory

    4. D

      The left column represents file size, and the right column represents file permissions

    Correct answer
    C

    The 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.

  54. 54

    In short status output, what does ?? mean for a file?

    1. A

      The file is modified in both the staging area and working directory

    2. B

      The file has been staged for deletion

    3. C

      The file is ignored by Git

    4. D

      The file is untracked

    Correct answer
    D

    The file is untracked

    Explanation

    Two question marks indicate an untracked file.

  55. 55

    If a file has an M only in the right column of git status --short, what does that indicate?

    1. A

      It has unstaged modifications in the working directory

    2. B

      It is a newly added untracked file

    3. C

      It has been deleted from the last commit

    4. D

      It has staged modifications and no further working changes

    Correct answer
    A

    It 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.

  56. 56

    What does a green M in the left column of short status output indicate?

    1. A

      A modified file has changes staged for the next commit

    2. B

      A file is untracked and ignored

    3. C

      A file has been deleted from the repository history

    4. D

      A modified file has changes only in the working directory

    Correct answer
    A

    A modified file has changes staged for the next commit

    Explanation

    The left column represents the staging area, so an M there indicates staged modifications.

  57. 57

    Which command shows staged changes that are proposed for the next commit?

    1. A

      git log --staged

    2. B

      git diff --staged

    3. C

      git status --staged

    4. D

      git diff

    Correct answer
    B

    git diff --staged

    Explanation

    git diff --staged compares the staged version with the last commit and shows what will go into the next commit.

  58. 58

    What does git diff with no arguments show?

    1. A

      Every change made in the repository's full history

    2. B

      Staged changes between the staging area and the last commit

    3. C

      Only untracked files that are not in .gitignore

    4. D

      Unstaged changes between the working directory and the staging area

    Correct answer
    D

    Unstaged changes between the working directory and the staging area

    Explanation

    Without arguments, git diff compares the working directory with the staging area, showing unstaged changes.

  59. 59

    In the usual diff display, what do - and + lines indicate?

    1. A

      A minus line is staged, and a plus line is untracked

    2. B

      A minus line is from the old version, and a plus line is from the new version

    3. C

      A minus line is ignored, and a plus line is deleted

    4. D

      A minus line is a commit message, and a plus line is an author name

    Correct answer
    B

    A 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.

  60. 60

    Why might a diff show only a chunk of a long file rather than the entire file?

    1. A

      Git shows only lines that are untracked

    2. B

      Git permanently removes unchanged sections from the file

    3. C

      Git cannot compare files with more than a few lines

    4. D

      Git displays sections around the changed lines to provide context without showing the whole file

    Correct answer
    D

    Git 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.

  61. 61

    Why might a developer use a visual diff tool instead of reading diff output in a terminal?

    1. A

      A visual tool can show changes only when the repository is offline

    2. B

      A visual tool automatically commits every displayed change

    3. C

      A visual tool can make differences between old and new copies easier to see

    4. D

      A visual tool is required for Git to save staged changes

    Correct answer
    C

    A 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.

  62. 62

    What is the main purpose of git log?

    1. A

      To open the current commit in a text editor

    2. B

      To stage all modified files and create a commit

    3. C

      To show only the current working directory's untracked files

    4. D

      To display the repository's commits, typically from newest to oldest

    Correct answer
    D

    To display the repository's commits, typically from newest to oldest

    Explanation

    git log displays the commit history, with the newest commit shown first by default.

  63. 63

    What does the --oneline option add to git log output?

    1. A

      A compact summary with a shortened commit identifier and one-line description

    2. B

      A complete file-by-file snapshot for every commit

    3. C

      A graphical view of all working-directory changes

    4. D

      A full list of author emails and commit timestamps

    Correct answer
    A

    A compact summary with a shortened commit identifier and one-line description

    Explanation

    git log --oneline gives a short summary of each commit, including a shortened identifier and its one-line message.

  64. 64

    What effect does git log --oneline --reverse have?

    1. A

      It shows the history of the current file in reverse alphabetical order

    2. B

      It removes commit identifiers from the output

    3. C

      It displays commits from earliest to latest

    4. D

      It displays only commits that changed file names

    Correct answer
    C

    It displays commits from earliest to latest

    Explanation

    The --reverse option reverses the usual ordering so the earliest commit appears first.

  65. 65

    What is a Git commit identifier?

    1. A

      A sequential revision number that increases by one for each commit

    2. B

      A file path that identifies the working directory

    3. C

      A branch name shared by all commits in the repository

    4. D

      A unique hexadecimal identifier generated for a commit

    Correct answer
    D

    A 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.

  66. 66

    When can an abbreviated commit identifier be used to refer to a commit?

    1. A

      When the abbreviation is long enough to identify that commit without ambiguity

    2. B

      Only when the commit has no parent

    3. C

      Only when all 40 hexadecimal characters are included

    4. D

      Only when the commit is the latest one

    Correct answer
    A

    When 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.

  67. 67

    What does HEAD indicate in the branch model described?

    1. A

      The reference to the branch currently being worked on

    2. B

      The next untracked file to be added

    3. C

      The first commit ever made in the repository

    4. D

      The system-level Git configuration

    Correct answer
    A

    The reference to the branch currently being worked on

    Explanation

    HEAD is a reference that tells Git which branch is currently checked out.

  68. 68

    What does HEAD~1 refer to?

    1. A

      The first commit on every branch

    2. B

      The current commit's first changed file

    3. C

      The next commit that will be created

    4. D

      The commit one step before the commit currently referenced by HEAD

    Correct answer
    D

    The commit one step before the commit currently referenced by HEAD

    Explanation

    Starting at HEAD, ~1 moves one commit back to its previous commit.

  69. 69

    What can git show <commit> display?

    1. A

      The contents of every file in the working directory without history

    2. B

      Only the current contents of the staging area

    3. C

      Information about the specified commit and a diff of its changes

    4. D

      A list of ignored files and directory patterns

    Correct answer
    C

    Information about the specified commit and a diff of its changes

    Explanation

    git show can display commit details and the changes introduced by that commit.

  70. 70

    How can git show display the version of one file stored in a particular commit?

    1. A

      Use git show followed by the name of the current branch only

    2. B

      Specify the commit followed by a colon and the file path

    3. C

      Use git show without a commit or a path

    4. D

      Specify the file path followed by --staged

    Correct answer
    B

    Specify 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.

  71. 71

    What does git ls-tree list for a commit?

    1. A

      All Git configuration settings for the repository

    2. B

      Only the unstaged modifications in the working directory

    3. C

      Only the commit messages on the current branch

    4. D

      Files and directories stored in that commit's tree

    Correct answer
    D

    Files and directories stored in that commit's tree

    Explanation

    git ls-tree lists the files and directories represented in a commit's tree.

  72. 72

    How are files and directories represented among Git's stored objects?

    1. A

      Files are represented as blobs, and directories are represented as trees

    2. B

      Files are represented as tags, and directories are represented as blobs

    3. C

      Files are represented as trees, and directories are represented as commits

    4. D

      Files and directories are both represented only as branch names

    Correct answer
    A

    Files 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.

  73. 73

    What does git restore --staged file.js do to a staged modification?

    1. A

      It discards the working-directory change and commits the old version

    2. B

      It permanently deletes the file from both the working directory and repository

    3. C

      It removes the staged version of the modification, leaving the working-directory change unstaged

    4. D

      It restores the file from the latest remote server

    Correct answer
    C

    It removes the staged version of the modification, leaving the working-directory change unstaged

    Explanation

    Restoring a file with --staged restores the staging-area copy from the last commit, leaving any newer working-directory changes unstaged.

  74. 74

    When git restore --staged is used on a newly staged file that has never been committed, what happens?

    1. A

      The file is committed automatically

    2. B

      The file is deleted from the working directory

    3. C

      The file is restored from the previous commit

    4. D

      The file is removed from the staging area and becomes untracked

    Correct answer
    D

    The 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.

  75. 75

    What does git restore file.js do when the file has unstaged local changes?

    1. A

      It adds the local changes to the staging area

    2. B

      It removes the file from the repository and working directory

    3. C

      It replaces the working-directory copy with the version from the staging area

    4. D

      It restores the file from the commit before the last commit

    Correct answer
    C

    It replaces the working-directory copy with the version from the staging area

    Explanation

    Without --staged or a different source, git restore replaces working-directory changes with the version in the staging area.

  76. 76

    Why does git restore file.js not remove a new untracked file?

    1. A

      The command restores untracked files only when a remote is online

    2. B

      The file must first be added to .gitignore

    3. C

      Git automatically stages every untracked file before restoring

    4. D

      Git has no tracked previous version of that file to restore

    Correct answer
    D

    Git 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.

  77. 77

    Which command can remove untracked files after confirming that they are unwanted?

    1. A

      git clean -f

    2. B

      git rm --cached

    3. C

      git log --reverse

    4. D

      git restore --staged

    Correct answer
    A

    git clean -f

    Explanation

    git clean -f forces removal of untracked files. This is dangerous because removed untracked files cannot be recovered from Git.

  78. 78

    What does the -d option add when used with git clean -f?

    1. A

      It allows removal of untracked directories as well as files

    2. B

      It restores deleted directories from the last commit

    3. C

      It deletes the .git directory and all repository history

    4. D

      It displays a diff before staging changes

    Correct answer
    A

    It allows removal of untracked directories as well as files

    Explanation

    The -d option tells git clean to remove whole untracked directories as well.

  79. 79

    How can a tracked file be restored from a commit other than the most recent one?

    1. A

      Use git init <commit> <path>

    2. B

      Use git add --source=<commit> <path>

    3. C

      Use git clean -f <commit> <path>

    4. D

      Use git restore --source=<commit> <path>

    Correct answer
    D

    Use git restore --source=<commit> <path>

    Explanation

    The --source option specifies the commit from which Git should restore the file.

  80. 80

    What does git restore --source=HEAD~1 file.js request?

    1. A

      Stage file.js from the latest commit without changing its contents

    2. B

      Delete file.js from the current branch and all earlier commits

    3. C

      Restore file.js from the working directory into the last commit

    4. D

      Restore file.js from the commit one step before HEAD

    Correct answer
    D

    Restore file.js from the commit one step before HEAD

    Explanation

    HEAD~1 identifies the commit immediately before the one referenced by HEAD, so the command restores the file version from that earlier commit.

  81. 81

    How can a deleted tracked file be restored from the commit before its deletion?

    1. A

      Use git rm --cached <file>

    2. B

      Use git status --short <file>

    3. C

      Use git restore --source=HEAD~1 <file>

    4. D

      Use git clean -fd <file>

    Correct answer
    C

    Use 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.

  82. 82

    Which statement distinguishes restoring a file from undoing a commit?

    1. A

      Restoring a file always creates a new commit without user action

    2. B

      Restoring a file rewrites every branch that contains the commit

    3. 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

    4. D

      Restoring a file automatically removes the commit that deleted it from history

    Correct answer
    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

    Explanation

    The described restore operation retrieves a file version; undoing or reverting the commit itself is a separate operation.

Question 1 of 82
Question 1 of 82

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent