Challenge your understanding of key Git command line operations with practical questions designed to enhance your workflow efficiency and version control skills. This quiz covers crucial commands, option usage, staging, branching, and commit management within cli-tools, tailored to boost your command line expertise.
Which Git command stages all modified and new files in the current directory and its subdirectories for the next commit?
Explanation: The command 'git add .' stages every changed and new file in the current directory and below, preparing them for commit. 'git push all' is not a valid command and would result in an error. 'git commit -a' commits changes to tracked files but does not include new untracked files. 'git init .' initializes a new repository, not stage files for commit.
If you want to see a concise list of previous commits with their messages and short hash values, which Git command should you use?
Explanation: 'git log --oneline' provides a shortened, one-line-per-commit view of the commit history, making it easy to scan. 'git history -short' and 'git commit --list' are not valid Git commands. 'git status -l' does not exist in Git; 'git status' is used to show the state of the working directory, not the commit history.
Suppose you modified 'config.txt' but haven’t staged it yet; which command will discard your local changes and restore the file to its last committed state?
Explanation: 'git checkout -- config.txt' reverts the file to its last committed version, discarding uncommitted changes. 'git remove config.txt' deletes the file from the working directory and stages the deletion, which is not a safe way to discard edits. 'git ignore config.txt' has no meaning in Git. 'git revert config.txt' is not a valid command; 'git revert' works on commits, not individual files.
To simultaneously create and switch to a new branch named 'feature-xyz', which Git command should you use?
Explanation: 'git checkout -b feature-xyz' creates a new branch and switches to it in one step. 'git create-branch feature-xyz' is not a valid Git command. 'git branch -sw feature-xyz' is incorrect as it combines unrelated and invalid options. 'git switch --new feature-xyz' is not a recognized Git command; while 'git switch' with '-c' can create a branch, the exact option here is not correct.
After committing, you realize you forgot to include a staged file in your last commit; which command allows you to add it to the previous commit without creating a new one?
Explanation: 'git commit --amend' allows you to modify the most recent commit, integrating additional staged changes or updating the commit message. 'git save --append' and 'git add-amend' are not Git commands, and 'git modify commit' does not exist in Git. Only 'git commit --amend' properly updates the last commit as described.