Reset Demystified
3 cards- 01
You committed too early. You run:
git reset --soft HEAD~1What is the state afterwards?
- A
The commit is kept; only the staging area is cleared
- B
The commit is gone; its changes are back in the working tree but unstaged
- C
The commit is gone, and its changes are discarded
- D
The commit is gone from the branch; its changes are still staged, ready to commit again
- A
- 02
git reset HEAD~1With no mode flag, what does
resetdo to the last commit's changes?- A
Nothing: without a flag,
resetonly prints what it would do - B
They are discarded (
--hardis the default) - C
They stay staged (
--softis the default) - D
They are kept in the working tree but unstaged (
--mixedis the default)
- A
- 03
Your working tree has an untracked file
notes.txtand a modified tracked fileapp.js. You run:git reset --hardWhat happens to the two files?
- A
Neither changes:
reset --hardneeds a commit argument - B
app.jsis restored;notes.txtis deleted - C
app.jsis restored to the committed version;notes.txtis left alone - D
Both are restored to the committed version
- A
git-clean
1 card- 04
You want to delete every untracked file and directory, including build output that
.gitignoreexcludes. Which command does that?- A
git clean -fd - B
git stash -u && git stash drop - C
git clean -fdx - D
git reset --hard
- A
git-checkout
2 cards- 05
git checkout a1b2c3d # an old commit # edit, then: git commit -am "fix" git checkout mainWhere is the
fixcommit now?- A
On
main, right aftera1b2c3d - B
On top of
main - C
On no branch: it is reachable only through the reflog until a branch or tag points at it
- D
Lost: checking out
mainfrom a detached HEAD deletes the commit
- A
- 06
git checkout feature -- src/config.jsWhat does this do?
- A
Switches to
featureand openssrc/config.js - B
Creates a branch
featurecontaining only that file - C
Copies
src/config.jsfromfeatureinto the index and working tree, without switching branches - D
Shows the diff of that file between the current branch and
feature
- A
git-reflog
2 cards- 07
You ran
git reset --hard HEAD~3on the wrong branch and lost three commits. What is the quickest way back?- A
There is no way back:
reset --harddeletes the commits - B
git fsck --lost-foundand re-apply the dangling commits by hand - C
git reflogto find the previous HEAD position, thengit reset --hard <that entry> - D
git revert HEAD~3
- A
- 08
Which command lists where
HEADhas pointed, so a commit lost by a reset or rebase can be found again?
git-commit
3 cards- 09
git commit --amend -m "better message"What does this do to the last commit?
- A
Edits the message in place; the hash stays the same
- B
Replaces it with a new commit that has a different hash; the old one is left unreferenced
- C
Creates a second commit containing only the new message
- D
Edits the message and adds the current working tree changes automatically
- A
- 10
git commit -am "add feature"You created a new file for the feature. Is it in the commit?
- A
Yes, unless it matches
.gitignore - B
No, because
-aonly stages files that were already staged once - C
Yes:
-astages everything in the working tree - D
No:
-astages modified and deleted tracked files, not untracked ones
- A
- 11
Which command replaces the last commit with a new one carrying a changed message or extra staged changes?
Basic Branching and Merging
1 card- 12
featurewas branched frommain, has two new commits, andmainhas not moved since. You run:git checkout main git merge featureWhat kind of merge happens?
- A
A fast-forward:
mainsimply moves tofeature's commit and no merge commit is created - B
A three-way merge that creates a merge commit with two parents
- C
A squash merge that combines the two commits into one
- D
A rebase of
featureontomain
- A
Rebasing
1 card- 13
git checkout feature git rebase mainWhat happens to the commits that were on
feature?- A
They are replaced by new commits with new hashes, replayed on top of
main - B
They are combined into one commit on top of
main - C
They are merged into
main - D
They keep their hashes and are moved to point after
main
- A
git-pull
1 card- 14
With default configuration, what does
git pulldo?- A
git fetchfollowed bygit mergeof the upstream branch into the current one - B
Only
git fetch; the merge is left to you - C
git fetchfollowed bygit rebaseonto the upstream branch - D
Downloads the upstream branch and resets the current branch to it
- A
git-fetch
2 cards- 15
git fetch originWhat changes in your repository?
- A
Your working tree is updated with the remote's changes
- B
Nothing until you run
git pull - C
Only the remote-tracking branches such as
origin/main; your local branches and working tree are untouched - D
Your local
mainis updated to match the remote
- A
- 16
A teammate deleted the remote branch
old-feature, butgit branch -rstill listsorigin/old-feature. How do you clean that up?- A
git branch -d old-feature - B
git remote remove originand add it again - C
git fetch --prune - D
git pull
- A
git-push
3 cards- 17
After rebasing a branch you had already pushed, you need to update the remote. Which is the safer command?
- A
git push --force: it is the same thing with a shorter name - B
git push— a rebase does not require force - C
git push --force-with-lease: it refuses if the remote branch has moved since you last fetched - D
git pullfirst, thengit push, which merges the two histories
- A
- 18
Your
git pushis rejected as "non-fast-forward" because a teammate pushed first. What should you do?- A
Fetch, integrate their commits (merge or rebase), then push again
- B
Push with
--force - C
Run
git push --all - D
Delete the remote branch and push again
- A
- 19
Which flag force-pushes only if the remote branch is still where you last fetched it?
Remote Branches
1 card- 20
git statussays "Your branch is up to date with 'origin/main'", yet a colleague pushed tomainten minutes ago. Why?- A
Your branch is set to track the wrong remote
- B
origin/mainis a local record of the remote, updated only when you fetch or pull - C
git statusonly compares the working tree with the last commit - D
The colleague's push has not finished propagating
- A
gitignore
2 cards- 21
You add
config.jsonto.gitignore, butgit statusstill shows changes to it. Why?- A
The pattern needs a leading slash to match a file in the root
- B
The file is already tracked;
.gitignoreonly affects untracked files - C
.gitignoremust be committed before it takes effect - D
Ignore rules are not read until the next clone
- A
- 22
build/ !build/keep.txtIs
build/keep.txttracked aftergit add .?- A
Yes, but only if
build/is written asbuild/* - B
No, because negation patterns must come first
- C
Yes: the
!pattern re-includes it - D
No: once a directory is excluded, Git does not look inside it, so the negation has no effect
- A
git-rm
2 cards- 23
git rm --cached build.logWhat does this do?
- A
Removes the file from the index (stops tracking it) but leaves it in the working tree
- B
Removes the file from both the index and the working tree
- C
Removes the file from the local cache so it is re-downloaded on the next pull
- D
Removes the file from the working tree but keeps it in the index
- A
- 24
Which command stops tracking a file but leaves it in the working tree?
git-add
1 card- 25
Your working tree has a modified tracked file, a deleted tracked file and a new untracked file. Which command stages the first two but not the new file?
- A
git add -u - B
git add . - C
git add -A - D
git add -p
- A
Recording Changes to the Repository
1 card- 26
You create an empty directory
logs/and rungit add .thengit commit. What happens to the directory?- A
Nothing is committed for it: Git tracks files, not directories
- B
It is committed as a directory with a placeholder entry
- C
git addrefuses with an error - D
An empty tree object is committed for it
- A
Stashing and Cleaning
1 card- 27
git stash git statusYou had a modified tracked file and a brand-new untracked file. What does
statusshow after the stash?- A
The modified tracked file:
stashonly saves untracked files - B
The untracked file:
stashleaves untracked files in place unless-uis given - C
Both files, since
stashonly records a snapshot without changing the tree - D
A clean working tree
- A
git-stash
3 cards- 28
What is the difference between
git stash popandgit stash apply?- A
There is none:
popis an alias forapply - B
popapplies the newest stash;applyapplies the oldest - C
popapplies the stash and removes it from the list;applyapplies it and keeps it - D
poprestores the index as well;applyrestores only the working tree
- A
- 29
You had staged
a.jsand leftb.jsmodified but unstaged, then rangit stashand latergit stash pop. What doesgit statusshow?- A
Only
b.js; staged changes are not stashed - B
Both files modified and unstaged:
popdoes not restore the index unless--indexis given - C
a.jsstaged andb.jsunstaged, exactly as before - D
Both files staged
- A
- 30
Which command stashes untracked files along with the tracked changes?
git-cherry-pick
2 cards- 31
git cherry-pick a1b2c3dHow does the resulting commit relate to
a1b2c3d?- A
It is the same commit, now on two branches
- B
It moves
a1b2c3dfrom its branch to the current one - C
It merges
a1b2c3d's branch into the current one - D
It applies the same change as a new commit with a different hash
- A
- 32
Which command applies one commit from another branch onto the current branch as a new commit?
git-revert
2 cards- 33
A bad commit has been on
mainfor a week and others have pulled it. Which command undoes its changes without rewriting history?- A
git checkout <sha>~1and commit - B
git reset --hard <sha>~1followed bygit push --force - C
git revert <sha>: it creates a new commit that applies the inverse change - D
git rebase -iand delete the commit
- A
- 34
Which command undoes a commit that has already been pushed, without rewriting history?
git-restore
4 cards- 35
git restore app.jsWhat does this do?
- A
Unstages
app.js, keeping the changes in the working tree - B
Throws away the uncommitted changes to
app.jsin the working tree — there is no undo - C
Restores
app.jsto the version on the remote - D
Restores
app.jsfrom the stash
- A
- 36
You staged
app.jsby mistake and want it unstaged, but the changes kept. Which commands do that?- A
git rm --cached app.js - B
git restore app.jsorgit checkout -- app.js - C
git restore --staged app.jsorgit reset app.js - D
git stashfollowed bygit stash pop
- A
- 37
Which command discards the unstaged changes to one file?
- 38
Which command removes a file from the index without touching the working tree?
Revision Selection
2 cards- 39
What is the difference between
git log main..featureandgit log main...feature?- A
Two dots: commits on
featurenot onmain. Three dots: commits on either branch but not both - B
Two dots: commits on both branches. Three dots: commits on
featureonly - C
They are the same; three dots is an older spelling
- D
Two dots: a range of exactly two commits. Three dots: three commits
- A
- 40
HEADis a merge commit. What is the difference betweenHEAD~2andHEAD^2?- A
HEAD^2is invalid; only~takes a number - B
HEAD~2is the first parent's first parent;HEAD^2is the merge's second parent - C
They are the same commit
- D
HEAD~2is the second parent;HEAD^2is two commits back
- A
Git Objects
1 card- 41
Two developers each commit an identical change on top of the same parent. Do they get the same commit hash?
- A
Yes: the hash is computed from the tree and the parent
- B
Only if both use
--date=now - C
No: the hash also covers author, committer and timestamps, so the commits differ
- D
Yes, if they use the same commit message
- A
git-log
1 card- 42
git log -- src/api.jsstops at the commit that renamed the file fromsrc/client.js. How do you see the earlier history?- A
git log --renames -- src/api.js - B
git log --follow -- src/api.js - C
You cannot: Git does not store renames
- D
git log --all -- src/api.js
- A
git-branch
1 card- 43
git branch -d experimentGit refuses: "the branch 'experiment' is not fully merged". What does that mean?
- A
experimenthas commits not reachable from the current branch;-Ddeletes it anyway - B
experimenthas uncommitted changes - C
experimentis checked out in another worktree - D
experimentis the branch you are currently on
- A
git-merge
1 card- 44
git merge --squash featureWhat is the state afterwards?
- A
feature's commits are replayed one by one onto the current branch - B
A merge commit has been created and
featurehas been deleted - C
feature's changes are staged as one set; no commit has been made, and the one you make will have a single parent - D
A single merge commit with two parents has been created
- A
Rewriting History
1 card- 45
In an interactive rebase, what is the difference between marking a commit
squashandfixup?- A
squashkeeps the commit;fixupdeletes it - B
fixupruns the tests before melding;squashdoes not - C
Both meld the commit into the previous one;
squashkeeps its message for editing,fixupdiscards it - D
squashcombines commits;fixuponly edits a commit's message
- A
git-rebase
2 cards- 46
git rebase --onto main server clientWhat does this do?
- A
Takes the commits on
clientthat are not onserverand replays them on top ofmain - B
Merges
serverandclientintomain - C
Replays every commit of
clientsince the root ontomain - D
Rebases
mainontoclient, skippingserver
- A
- 47
Which command opens the last five commits for reordering, squashing or editing?
Tagging
1 card- 48
You created a tag
v1.2.0and rangit push origin main. Is the tag on the remote?- A
Yes, if it is an annotated tag; lightweight tags stay local
- B
Yes: tags on pushed commits are pushed with them
- C
No:
pushdoes not send tags unless you push the tag explicitly, use--tags, or use--follow-tags - D
No, tags can only be pushed with
git push --mirror
- A
git-tag
2 cards- 49
You tagged a commit
v1.0onfeature, then rebasedfeatureontomain. Where is the tag?- A
Deleted, because its commit was rewritten
- B
On the tip of
feature - C
On the corresponding rewritten commit
- D
Still on the old, pre-rebase commit; rebasing does not move tags
- A
- 50
Which command creates an annotated tag
v1.0with a message?
git-worktree
2 cards- 51
git worktree add ../hotfix mainmainis already checked out in the current worktree. What happens?- A
mainis moved to the new worktree and the current one becomes detached - B
A second worktree is created on a detached HEAD at
main - C
A second worktree on
mainis created; both update together - D
An error: a branch can be checked out in only one worktree at a time
- A
- 52
Which command checks out a branch in a second working directory beside the current one?
git-switch
1 card- 53
You have uncommitted changes to
app.jsonmainand rungit switch feature.app.jsis identical on both branches. What happens?- A
The changes are discarded
- B
The switch succeeds and the uncommitted changes come along to
feature - C
The switch is refused until you commit or stash
- D
The changes are stashed automatically and restored when you return to
main
- A
Advanced Merging
1 card- 54
During
git rebase mainonfeature, a conflict shows:<<<<<<< HEAD ... ======= ... >>>>>>> a1b2c3d (add validation)Which side is
feature's change?- A
The lower one: during a rebase,
HEADis the branch being rebased onto, and your commits are replayed on top of it - B
The upper one:
HEADis always the branch you were working on - C
Neither:
HEADis the merge base - D
Both sides are from
feature, from two different commits
- A
Git Hooks
1 card- 55
You wrote a
pre-commithook in.git/hooks/that runs the linter. A teammate clones the repository. Does the hook run for them?- A
No:
.git/hooksis not part of the repository and is never cloned or pushed - B
Yes, once they run
git hooks install - C
Only if the hook is committed with
git add .git/hooks - D
Yes: hooks are cloned along with the repository
- A
git-update-index
1 card- 56
You
chmod +x deploy.shon a tracked file and change nothing else. What doesgit statusshow?- A
Nothing: only the file's content is hashed
- B
Nothing: Git does not track file permissions
- C
A modification: the executable bit is part of what Git tracks (as mode
100755versus100644) - D
A rename
- A
git-diff
1 card- 57
What do
git diff,git diff --stagedandgit diff HEADcompare?- A
Index vs last commit; working tree vs index; working tree vs last commit
- B
All three compare the working tree with the last commit, in different formats
- C
Working tree vs last commit; index vs last commit; working tree vs index
- D
Working tree vs index; index vs last commit; working tree vs last commit
- A
git-reset
3 cards- 58
Which command undoes the last commit but leaves its changes staged?
- 59
Which command undoes the last commit and unstages its changes, keeping them in the working tree?
- 60
Which command discards the last commit together with its changes in the working tree?
End of deck · 60 cards