Git History and Change Tracking Essentials Quiz

Explore key concepts of Git history, logs, and change tracking with practical questions covering commands, commit inspection, and revision navigation. This quiz is designed to help developers solidify understanding of how Git records, displays, and manages project changes through its ecosystem of tools.

  1. Examining Git Commit History

    Which Git command shows the history of commits for the current branch in a reverse chronological order, displaying author information and commit messages?

    1. git log
    2. git revert
    3. git diff
    4. git fetch

    Explanation: The 'git log' command displays a list of commits for the current branch, including author details and messages, in reverse order. 'git revert' is used for reverting a previous commit and does not show the history. 'git diff' is designed to show changes between commits or staging, not the commit history itself. 'git fetch' updates remote-tracking branches but does not output commit history.

  2. Understanding Commit Identifiers

    When you want to reference a specific commit in Git, which of the following is commonly used for unique identification within the repository?

    1. Short or full SHA-1 hash
    2. Branch nickname
    3. File path
    4. Tagline

    Explanation: Each commit in Git is identified by a unique SHA-1 hash (either full or short form), making it possible to reference individual commits precisely. A branch nickname points to the tip of a branch, not a single commit. A file path only refers to a location in the directory, not a commit itself. A tagline is not a Git concept for identifying commits.

  3. Viewing Changes Introduced by a Commit

    You need to see which changes were introduced in a specific commit with the hash 'abc1234'; which Git command is the most appropriate?

    1. git show abc1234
    2. git remove abc1234
    3. git branch abc1234
    4. git add abc1234

    Explanation: 'git show abc1234' displays information about the 'abc1234' commit, including what changes it introduced. 'git remove' is not a Git command, and therefore cannot display changes. 'git branch' is used to create or list branches, not view commit details. 'git add' stages files before committing and is unrelated to inspecting commits.

  4. Comparing Working Directory and Last Commit

    If you want to check the differences between your working directory and the last committed state, which Git command should you use?

    1. git diff
    2. git blame
    3. git log --decorate
    4. git merge

    Explanation: 'git diff' is used to compare the changes in your working directory with the most recent commit, helping you see what is unstaged. 'git blame' shows line-by-line commit history for files, not unstaged differences. 'git log --decorate' modifies log output to include branch and tag names but does not compare contents. 'git merge' combines changes from two branches, not directories.

  5. Tracking File Changes Over Time

    Which Git command allows you to see the entire history of changes made to a particular file, such as 'main.py'?

    1. git log -- main.py
    2. git stage main.py
    3. git fork main.py
    4. git status --file main.py

    Explanation: 'git log -- main.py' displays the full commit history of changes affecting 'main.py', making it essential for tracking specific file modifications. 'git stage' is not an actual Git command; the correct command is 'git add' for staging. 'git fork' is not used in core Git for file or commit history. 'git status --file main.py' is not a valid way to view change history for an individual file.