1Which command allows you to view the changes between the working directory and the staging area?
A.git diff
B.git status
C.git diff --cached
D.git diff HEAD
Correct Answer: git diff
Explanation:
git diff without arguments shows changes in the working directory that are not yet staged. git diff --cached (or --staged) shows staged changes.
Incorrect! Try again.
2In the context of Git objects, what constitutes the unique identifier for a commit?
A.A user-defined tag
B.A 40-character SHA-1 hash
C.The timestamp of the commit
D.A sequential integer ID
Correct Answer: A 40-character SHA-1 hash
Explanation:
Git uses a SHA-1 hash checksum of the content and header information to identify commits and other objects uniquely.
Incorrect! Try again.
3Which command is used to create a new branch and switch to it immediately in a single step?
A.git checkout -b <name>
B.git checkout <name>
C.git branch <name>
D.git switch <name>
Correct Answer: git checkout -b <name>
Explanation:
The command git checkout -b <name> creates a new branch and switches HEAD to point to it. git switch -c <name> is the newer equivalent.
Incorrect! Try again.
4When performing a git merge, what is a 'Fast-forward' merge?
A.A merge where the current branch tip is simply moved up to the target branch tip
B.A merge that creates a new commit object
C.A merge used only for remote repositories
D.A merge that resolves conflicts automatically
Correct Answer: A merge where the current branch tip is simply moved up to the target branch tip
Explanation:
If there are no divergent commits between the current branch and the target branch, Git simply moves the pointer forward. No new merge commit is created.
Incorrect! Try again.
5Which command displays the commit history along with the diffs introduced by each commit?
A.git show
B.git log -p
C.git log --stat
D.git log --oneline
Correct Answer: git log -p
Explanation:
The -p flag (for patch) with git log shows the difference (diff) introduced in each commit.
Incorrect! Try again.
6What is the primary difference between git merge and git rebase?
A.Merge preserves history structure; rebase rewrites history to be linear
B.Merge rewrites history; rebase preserves history
C.There is no functional difference
D.Merge is used for local branches; rebase is for remote branches
Correct Answer: Merge preserves history structure; rebase rewrites history to be linear
Explanation:
Rebasing takes all the changes that were committed on one branch and replays them on a different branch, creating a linear history. Merge creates a special commit that ties two histories together.
Incorrect! Try again.
7How do you view changes that have been staged but not yet committed?
A.git log --staged
B.git diff --staged
C.git diff
D.git show
Correct Answer: git diff --staged
Explanation:
git diff --staged (or git diff --cached) compares the staging area to the HEAD commit.
Incorrect! Try again.
8Which command allows you to temporarily save your changes in the working directory without committing them?
A.git checkout .
B.git stash
C.git commit --amend
D.git reset --soft
Correct Answer: git stash
Explanation:
git stash pushes the current dirty state (modified tracked files and staged changes) onto the stash stack and cleans the working directory.
Incorrect! Try again.
9What is the result of running git stash pop?
A.It applies the most recent stash and removes it from the stack
B.It applies the most recent stash but keeps it in the stack
C.It deletes the most recent stash without applying it
D.It lists all available stashes
Correct Answer: It applies the most recent stash and removes it from the stack
Explanation:
pop applies the top stash changes to the working directory and drops it from the list. apply applies it but keeps it in the list.
Incorrect! Try again.
10Which Git command helps determine who modified a specific line in a file and in which commit?
A.git diff
B.git check-attr
C.git blame
D.git log
Correct Answer: git blame
Explanation:
git blame annotates each line in the given file with information from the revision which last modified the line.
Incorrect! Try again.
11What is the purpose of an 'Annotated Tag' in Git?
A.It is stored as a full object in the database containing the tagger name, email, and date
B.It automatically updates when new commits are added
C.It is just a pointer to a specific commit
D.It allows you to tag a file instead of a commit
Correct Answer: It is stored as a full object in the database containing the tagger name, email, and date
Explanation:
Annotated tags are stored as full objects in the Git database. They are checksummed; contain the tagger name, email, and date; have a tagging message; and can be signed and verified.
Incorrect! Try again.
12Which command is used to delete a local branch that has already been merged?
A.git branch -D <branch_name>
B.git checkout -d <branch_name>
C.git rm <branch_name>
D.git branch -d <branch_name>
Correct Answer: git branch -d <branch_name>
Explanation:
The -d option deletes the branch only if it has been fully merged. If it hasn't, Git will prevent the deletion. -D forces deletion.
Incorrect! Try again.
13When resolving a merge conflict, what must be done after editing the files to fix the conflict?
A.Run git push
B.Stage the files using git add
C.Run git commit immediately
D.Run git rebase --continue
Correct Answer: Stage the files using git add
Explanation:
After manually resolving conflicts in a file, you must run git add to mark them as resolved before finishing the merge commit.
Incorrect! Try again.
14What does the command git rebase -i HEAD~3 allow you to do?
A.Interactively modify, squash, or drop the last 3 commits
B.Merge the last 3 commits into a new branch
C.Stash the last 3 commits
D.Revert the last 3 commits
Correct Answer: Interactively modify, squash, or drop the last 3 commits
Explanation:
The -i flag initiates an interactive rebase, allowing users to edit, squash, reorder, or drop commits in the specified range.
Incorrect! Try again.
15Which command creates a lightweight tag named 'v1.0'?
A.git tag --light v1.0
B.git tag v1.0
C.git tag -a v1.0 -m 'version 1.0'
D.git commit --tag v1.0
Correct Answer: git tag v1.0
Explanation:
Running git tag with just a name creates a lightweight tag, which is simply a pointer to a specific commit, similar to a branch that doesn't change.
Incorrect! Try again.
16During a rebase, if you encounter conflicts, which command allows you to proceed after resolving them?
A.git rebase --continue
B.git rebase --abort
C.git rebase --skip
D.git commit
Correct Answer: git rebase --continue
Explanation:
After resolving conflicts and staging the changes, git rebase --continue is used to proceed to the next commit in the rebase process.
Incorrect! Try again.
17What does the command git diff branchA..branchB do?
A.Shows the common ancestor of both branches
B.Merges branchA into branchB
C.Shows the changes between the tips of branchA and branchB
D.Rebases branchB onto branchA
Correct Answer: Shows the changes between the tips of branchA and branchB
Explanation:
The double dot syntax .. compares the tips of the two specified branches.
Incorrect! Try again.
18Why is it generally advised not to rebase public history?
A.It rewrites history, causing synchronization issues for other developers
B.It deletes the remote repository
C.It creates merge conflicts automatically
D.It consumes too much memory
Correct Answer: It rewrites history, causing synchronization issues for other developers
Explanation:
Rebasing creates new commit objects (new SHAs). If others have based work on the original commits, rebasing public history forces everyone to perform complex manual fixes.
Incorrect! Try again.
19Which option in git log draws a text-based graphical representation of the commit history?
A.git log --graph
B.git log --pretty
C.git log --chart
D.git log --draw
Correct Answer: git log --graph
Explanation:
--graph adds a nice ASCII graph to the log output showing the branching and merging history.
Incorrect! Try again.
20What is the command to list all current stashes?
A.git stash --verbose
B.git stash show
C.git stash list
D.git stash all
Correct Answer: git stash list
Explanation:
git stash list shows all the stashed changes currently stored in the stash stack.
Incorrect! Try again.
21If you want to create a new branch from a specific stash, which command should you use?
A.git stash branch <branchname>
B.git checkout -b <branchname> stash
C.git stash pop <branchname>
D.git branch <branchname> --stash
Correct Answer: git stash branch <branchname>
Explanation:
git stash branch creates a new branch, checks it out, and then applies the stash to it. If successful, it drops the stash.
Incorrect! Try again.
22What is the purpose of git merge --no-ff?
A.It prevents a merge commit from being created
B.It aborts the merge if conflicts are found
C.It performs a dry-run merge
D.It forces the creation of a merge commit even if a fast-forward is possible
Correct Answer: It forces the creation of a merge commit even if a fast-forward is possible
Explanation:
--no-ff (no fast-forward) ensures that a merge commit is created to record the fact that a merge happened, preserving the existence of the feature branch in history.
Incorrect! Try again.
23How do you push a specific tag v1.0 to the remote repository?
A.git push origin --tags
B.git tag push v1.0
C.git commit --push v1.0
D.git push origin v1.0
Correct Answer: git push origin v1.0
Explanation:
By default, git push does not transfer tags. You must explicitly push the tag name to the remote server.
Incorrect! Try again.
24Which command removes untracked files from the working tree?
A.git rm
B.git stash drop
C.git clean
D.git reset
Correct Answer: git clean
Explanation:
git clean is used to remove untracked files from the working directory. It is often used with -f (force) and -d (directories).
Incorrect! Try again.
25In an interactive rebase, what does the squash command do?
A.Deletes the commit
B.Edits the commit message
C.Combines the commit with the previous one
D.Pauses the rebase
Correct Answer: Combines the commit with the previous one
Explanation:
squash (or s) melds the commit into the previous commit (the one above it in the list), allowing you to combine multiple commits into one.
Incorrect! Try again.
26Which of the following describes a 'detached HEAD' state?
A.The repository has no commits
B.HEAD points directly to a commit instead of a branch reference
C.The remote repository is unreachable
D.There are uncommitted changes in the staging area
Correct Answer: HEAD points directly to a commit instead of a branch reference
Explanation:
Normally HEAD points to a branch name. If you checkout a specific commit SHA or a tag, HEAD points directly to that commit, resulting in a detached HEAD.
Incorrect! Try again.
27Which command would you use to view the commit history for a specific file?
A.git show <filename>
B.git diff <filename>
C.git status <filename>
D.git log <filename>
Correct Answer: git log <filename>
Explanation:
Providing a filename to git log filters the history to show only commits that modified that specific file.
Incorrect! Try again.
28What happens when you run git stash apply?
A.The top stash is applied but remains in the stack
B.All stashes are applied
C.The stash is deleted
D.The top stash is applied and removed from the stack
Correct Answer: The top stash is applied but remains in the stack
Explanation:
Unlike pop, apply tries to apply the stash changes to the working directory but keeps the stash in the list for potential future use.
Incorrect! Try again.
29How can you rename the current branch to 'main'?
A.git branch -m main
B.git checkout -b main
C.git branch --new main
D.git rename main
Correct Answer: git branch -m main
Explanation:
The -m (move/rename) flag allows you to rename the current branch (or a different branch if two arguments are provided).
Incorrect! Try again.
30What is the purpose of git reflog?
A.To delete old logs
B.To view the history of branch updates and HEAD movements
C.To reference the logs of a specific tag
D.To view the commit logs of a remote repository
Correct Answer: To view the history of branch updates and HEAD movements
Explanation:
Reflog records when the tips of branches and other references were updated in the local repository. It is essential for recovering 'lost' commits.
Incorrect! Try again.
31Which command deletes the most recent stash entry?
A.git stash drop
B.git stash delete
C.git stash remove
D.git stash pop --no-apply
Correct Answer: git stash drop
Explanation:
git stash drop removes a single stash entry from the list of stash entries. If no argument is given, it removes the latest one.
Incorrect! Try again.
32You have unstaged changes in file.txt and want to discard them. Which command do you use?
A.git checkout -- file.txt
B.git rm file.txt
C.git reset file.txt
D.git stash pop
Correct Answer: git checkout -- file.txt
Explanation:
git checkout -- <file> (or git restore <file>) reverts the file in the working directory to the state of the HEAD commit, discarding local changes.
Incorrect! Try again.
33What does git tag -l 'v1.8*' do?
A.Deletes all tags starting with v1.8
B.Lists all tags matching the pattern v1.8*
C.Pushes tags starting with v1.8
D.Creates a tag named v1.8*
Correct Answer: Lists all tags matching the pattern v1.8*
Explanation:
The -l (list) option allows listing tags, and it supports wildcard patterns to filter the output.
Incorrect! Try again.
34When performing a 3-way merge, which three commits are used?
A.The last three commits on the current branch
B.The two branch tips and their most recent common ancestor
C.The HEAD, the Staging Index, and the Working Directory
D.The local branch tip, the remote branch tip, and the stash
Correct Answer: The two branch tips and their most recent common ancestor
Explanation:
Git uses the tips of the two branches being merged and finds the optimal common ancestor to perform a 3-way merge algorithm.
Incorrect! Try again.
35Which command allows you to stash untracked files as well?
A.git stash save
B.git stash -u
C.git stash --all
D.git stash --force
Correct Answer: git stash -u
Explanation:
By default, stash ignores untracked files. The -u (or --include-untracked) option tells Git to include them in the stash.
Incorrect! Try again.
36In an interactive rebase, what does drop do?
A.Removes the commit entirely from history
B.Stops the rebase process
C.Moves the commit to a new branch
D.Squashes the commit
Correct Answer: Removes the commit entirely from history
Explanation:
Marking a commit as drop (or d) in the interactive rebase todo list prevents that commit from being included in the replayed history.
Incorrect! Try again.
37To force a push after a rebase (since history changed), which command is used?
A.git push --hard
B.git push --overwrite
C.git push --force
D.git push --rebase
Correct Answer: git push --force
Explanation:
Since rebasing rewrites history, the local history diverges from the remote. git push --force (or safer --force-with-lease) is required to update the remote.
Incorrect! Try again.
38What command shows the difference between the staging area and the last commit?
A.git diff HEAD
B.All of the above
C.git status -v
D.git diff --staged
Correct Answer: All of the above
Explanation:
git diff --staged shows it directly. git diff HEAD shows difference between working dir+staged vs HEAD (effectively showing staged changes if working dir is clean). git status -v shows verbose status including diffs.
Incorrect! Try again.
39How do you apply a specific stash from the list, e.g., index 2?
A.git stash apply 2
B.git stash apply stash@{2}
C.git stash pop 2
D.git apply stash#2
Correct Answer: git stash apply stash@{2}
Explanation:
Stashes are referenced as stash@{n}. To apply a specific one, you must provide this reference.
Incorrect! Try again.
40What is the primary usage of git show?
A.To show the remote URL
B.To display metadata and content changes of a specific object (blob, tree, tag, or commit)
C.To show all branches
D.To show the current status of the repository
Correct Answer: To display metadata and content changes of a specific object (blob, tree, tag, or commit)
Explanation:
git show is a versatile command used to inspect specific objects. By default, it shows the last commit.
Incorrect! Try again.
41Which command would you use to verify if a tag is GPG signed?
A.git show --signature <tagname>
B.git verify <tagname>
C.git tag -v <tagname>
D.git tag --check <tagname>
Correct Answer: git tag -v <tagname>
Explanation:
git tag -v verifies the GPG signature of the tag.
Incorrect! Try again.
42If you want to modify the message of the most recent commit, which command is appropriate?
A.git commit --amend
B.git reset
C.git rebase
D.git config commit.message
Correct Answer: git commit --amend
Explanation:
git commit --amend allows you to combine staged changes with the previous commit and/or edit the previous commit message.
Incorrect! Try again.
43What defines the structure of the Git history graph?
A.A Linked List
B.A Binary Search Tree
C.A Stack
D.A Directed Acyclic Graph (DAG)
Correct Answer: A Directed Acyclic Graph (DAG)
Explanation:
Git commits point to their parents, forming a graph where flow is directional (towards parents) and there are no loops (acyclic), forming a DAG.
Incorrect! Try again.
44Which command allows you to view the diff statistics (summary of insertions/deletions) rather than full code changes?
A.git diff --stat
B.git diff --summary
C.git diff --brief
D.git diff --count
Correct Answer: git diff --stat
Explanation:
The --stat option generates a diffstat, showing the names of files changed and the number of insertions and deletions for each.
Incorrect! Try again.
45How do you tag a past commit (not the current HEAD)?
A.You cannot tag past commits
B.git tag v1.0 HEAD~1
C.git tag v1.0 <commit_checksum>
D.git tag --past v1.0
Correct Answer: git tag v1.0 <commit_checksum>
Explanation:
You can tag any commit in history by specifying its checksum (SHA) at the end of the tag command.
Incorrect! Try again.
46Which command is used to discard all local changes in the working directory and staging area, resetting them to the last commit?
A.git reset --hard
B.git reset --mixed
C.git checkout .
D.git reset --soft
Correct Answer: git reset --hard
Explanation:
git reset --hard resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.
Incorrect! Try again.
47What is the equivalent of git merge that results in a cleaner history but modifies commit hashes?
A.git stash
B.git revert
C.git rebase
D.git cherry-pick
Correct Answer: git rebase
Explanation:
Rebase replays commits from one branch onto another, creating a linear history but generating new commit SHAs.
Incorrect! Try again.
48What happens if you delete a branch that has unmerged work using git branch -D?
A.The branch is moved to 'archive'
B.The commits are permanently lost immediately
C.The commits become dangling but can be recovered via reflog for a certain period
D.Git forbids the action
Correct Answer: The commits become dangling but can be recovered via reflog for a certain period
Explanation:
The pointers are removed. The commit objects remain in the database until garbage collected (gc). They can often be found in git reflog.
Incorrect! Try again.
49Which command shows the branches that have not yet been merged into the current branch?
A.git status
B.git branch --diff
C.git branch --no-merged
D.git branch --merged
Correct Answer: git branch --no-merged
Explanation:
git branch --no-merged lists all branches that contain work that is not reachable from the current branch.
Incorrect! Try again.
50In an interactive rebase, what does the reword instruction do?
A.Meld the commit into the previous one
B.Use the commit as is
C.Use the commit, but edit the commit message
D.Remove the commit
Correct Answer: Use the commit, but edit the commit message
Explanation:
reword (or r) keeps the commit contents exactly as they are but pauses the process to allow the user to change the commit message.
Incorrect! Try again.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill.
The rest comes out of a student's own pocket: the domain, the storage,
and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it.
What it pays for →