Card type

Reset Demystified

3 cards
  1. 01

    You committed too early. You run:

    git reset --soft HEAD~1
    

    What 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

  2. 02
    git reset HEAD~1
    

    With no mode flag, what does reset do to the last commit's changes?

    • A

      Nothing: without a flag, reset only prints what it would do

    • B

      They are discarded (--hard is the default)

    • C

      They stay staged (--soft is the default)

    • D

      They are kept in the working tree but unstaged (--mixed is the default)

  3. 03

    Your working tree has an untracked file notes.txt and a modified tracked file app.js. You run:

    git reset --hard
    

    What happens to the two files?

    • A

      Neither changes: reset --hard needs a commit argument

    • B

      app.js is restored; notes.txt is deleted

    • C

      app.js is restored to the committed version; notes.txt is left alone

    • D

      Both are restored to the committed version

git-clean

1 card
  1. 04

    You want to delete every untracked file and directory, including build output that .gitignore excludes. Which command does that?

    • A

      git clean -fd

    • B

      git stash -u && git stash drop

    • C

      git clean -fdx

    • D

      git reset --hard

git-checkout

2 cards
  1. 05
    git checkout a1b2c3d      # an old commit
    # edit, then:
    git commit -am "fix"
    git checkout main
    

    Where is the fix commit now?

    • A

      On main, right after a1b2c3d

    • 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 main from a detached HEAD deletes the commit

  2. 06
    git checkout feature -- src/config.js
    

    What does this do?

    • A

      Switches to feature and opens src/config.js

    • B

      Creates a branch feature containing only that file

    • C

      Copies src/config.js from feature into the index and working tree, without switching branches

    • D

      Shows the diff of that file between the current branch and feature

git-reflog

2 cards
  1. 07

    You ran git reset --hard HEAD~3 on the wrong branch and lost three commits. What is the quickest way back?

    • A

      There is no way back: reset --hard deletes the commits

    • B

      git fsck --lost-found and re-apply the dangling commits by hand

    • C

      git reflog to find the previous HEAD position, then git reset --hard <that entry>

    • D

      git revert HEAD~3

  2. 08

    Which command lists where HEAD has pointed, so a commit lost by a reset or rebase can be found again?

git-commit

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

  2. 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 -a only stages files that were already staged once

    • C

      Yes: -a stages everything in the working tree

    • D

      No: -a stages modified and deleted tracked files, not untracked ones

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

    feature was branched from main, has two new commits, and main has not moved since. You run:

    git checkout main
    git merge feature
    

    What kind of merge happens?

    • A

      A fast-forward: main simply moves to feature'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 feature onto main

Rebasing

1 card
  1. 13
    git checkout feature
    git rebase main
    

    What 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

git-pull

1 card
  1. 14

    With default configuration, what does git pull do?

    • A

      git fetch followed by git merge of the upstream branch into the current one

    • B

      Only git fetch; the merge is left to you

    • C

      git fetch followed by git rebase onto the upstream branch

    • D

      Downloads the upstream branch and resets the current branch to it

git-fetch

2 cards
  1. 15
    git fetch origin
    

    What 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 main is updated to match the remote

  2. 16

    A teammate deleted the remote branch old-feature, but git branch -r still lists origin/old-feature. How do you clean that up?

    • A

      git branch -d old-feature

    • B

      git remote remove origin and add it again

    • C

      git fetch --prune

    • D

      git pull

git-push

3 cards
  1. 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 pull first, then git push, which merges the two histories

  2. 18

    Your git push is 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

  3. 19

    Which flag force-pushes only if the remote branch is still where you last fetched it?

Remote Branches

1 card
  1. 20

    git status says "Your branch is up to date with 'origin/main'", yet a colleague pushed to main ten minutes ago. Why?

    • A

      Your branch is set to track the wrong remote

    • B

      origin/main is a local record of the remote, updated only when you fetch or pull

    • C

      git status only compares the working tree with the last commit

    • D

      The colleague's push has not finished propagating

gitignore

2 cards
  1. 21

    You add config.json to .gitignore, but git status still 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; .gitignore only affects untracked files

    • C

      .gitignore must be committed before it takes effect

    • D

      Ignore rules are not read until the next clone

  2. 22
    build/
    !build/keep.txt
    

    Is build/keep.txt tracked after git add .?

    • A

      Yes, but only if build/ is written as build/*

    • 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

git-rm

2 cards
  1. 23
    git rm --cached build.log
    

    What 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

  2. 24

    Which command stops tracking a file but leaves it in the working tree?

git-add

1 card
  1. 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

Recording Changes to the Repository

1 card
  1. 26

    You create an empty directory logs/ and run git add . then git 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 add refuses with an error

    • D

      An empty tree object is committed for it

Stashing and Cleaning

1 card
  1. 27
    git stash
    git status
    

    You had a modified tracked file and a brand-new untracked file. What does status show after the stash?

    • A

      The modified tracked file: stash only saves untracked files

    • B

      The untracked file: stash leaves untracked files in place unless -u is given

    • C

      Both files, since stash only records a snapshot without changing the tree

    • D

      A clean working tree

git-stash

3 cards
  1. 28

    What is the difference between git stash pop and git stash apply?

    • A

      There is none: pop is an alias for apply

    • B

      pop applies the newest stash; apply applies the oldest

    • C

      pop applies the stash and removes it from the list; apply applies it and keeps it

    • D

      pop restores the index as well; apply restores only the working tree

  2. 29

    You had staged a.js and left b.js modified but unstaged, then ran git stash and later git stash pop. What does git status show?

    • A

      Only b.js; staged changes are not stashed

    • B

      Both files modified and unstaged: pop does not restore the index unless --index is given

    • C

      a.js staged and b.js unstaged, exactly as before

    • D

      Both files staged

  3. 30

    Which command stashes untracked files along with the tracked changes?

git-cherry-pick

2 cards
  1. 31
    git cherry-pick a1b2c3d
    

    How does the resulting commit relate to a1b2c3d?

    • A

      It is the same commit, now on two branches

    • B

      It moves a1b2c3d from 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

  2. 32

    Which command applies one commit from another branch onto the current branch as a new commit?

git-revert

2 cards
  1. 33

    A bad commit has been on main for a week and others have pulled it. Which command undoes its changes without rewriting history?

    • A

      git checkout <sha>~1 and commit

    • B

      git reset --hard <sha>~1 followed by git push --force

    • C

      git revert <sha>: it creates a new commit that applies the inverse change

    • D

      git rebase -i and delete the commit

  2. 34

    Which command undoes a commit that has already been pushed, without rewriting history?

git-restore

4 cards
  1. 35
    git restore app.js
    

    What does this do?

    • A

      Unstages app.js, keeping the changes in the working tree

    • B

      Throws away the uncommitted changes to app.js in the working tree — there is no undo

    • C

      Restores app.js to the version on the remote

    • D

      Restores app.js from the stash

  2. 36

    You staged app.js by mistake and want it unstaged, but the changes kept. Which commands do that?

    • A

      git rm --cached app.js

    • B

      git restore app.js or git checkout -- app.js

    • C

      git restore --staged app.js or git reset app.js

    • D

      git stash followed by git stash pop

  3. 37

    Which command discards the unstaged changes to one file?

  4. 38

    Which command removes a file from the index without touching the working tree?

Revision Selection

2 cards
  1. 39

    What is the difference between git log main..feature and git log main...feature?

    • A

      Two dots: commits on feature not on main. Three dots: commits on either branch but not both

    • B

      Two dots: commits on both branches. Three dots: commits on feature only

    • C

      They are the same; three dots is an older spelling

    • D

      Two dots: a range of exactly two commits. Three dots: three commits

  2. 40

    HEAD is a merge commit. What is the difference between HEAD~2 and HEAD^2?

    • A

      HEAD^2 is invalid; only ~ takes a number

    • B

      HEAD~2 is the first parent's first parent; HEAD^2 is the merge's second parent

    • C

      They are the same commit

    • D

      HEAD~2 is the second parent; HEAD^2 is two commits back

Git Objects

1 card
  1. 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

git-log

1 card
  1. 42

    git log -- src/api.js stops at the commit that renamed the file from src/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

git-branch

1 card
  1. 43
    git branch -d experiment
    

    Git refuses: "the branch 'experiment' is not fully merged". What does that mean?

    • A

      experiment has commits not reachable from the current branch; -D deletes it anyway

    • B

      experiment has uncommitted changes

    • C

      experiment is checked out in another worktree

    • D

      experiment is the branch you are currently on

git-merge

1 card
  1. 44
    git merge --squash feature
    

    What 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 feature has 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

Rewriting History

1 card
  1. 45

    In an interactive rebase, what is the difference between marking a commit squash and fixup?

    • A

      squash keeps the commit; fixup deletes it

    • B

      fixup runs the tests before melding; squash does not

    • C

      Both meld the commit into the previous one; squash keeps its message for editing, fixup discards it

    • D

      squash combines commits; fixup only edits a commit's message

git-rebase

2 cards
  1. 46
    git rebase --onto main server client
    

    What does this do?

    • A

      Takes the commits on client that are not on server and replays them on top of main

    • B

      Merges server and client into main

    • C

      Replays every commit of client since the root onto main

    • D

      Rebases main onto client, skipping server

  2. 47

    Which command opens the last five commits for reordering, squashing or editing?

Tagging

1 card
  1. 48

    You created a tag v1.2.0 and ran git 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: push does 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

git-tag

2 cards
  1. 49

    You tagged a commit v1.0 on feature, then rebased feature onto main. 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

  2. 50

    Which command creates an annotated tag v1.0 with a message?

git-worktree

2 cards
  1. 51
    git worktree add ../hotfix main
    

    main is already checked out in the current worktree. What happens?

    • A

      main is 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 main is created; both update together

    • D

      An error: a branch can be checked out in only one worktree at a time

  2. 52

    Which command checks out a branch in a second working directory beside the current one?

git-switch

1 card
  1. 53

    You have uncommitted changes to app.js on main and run git switch feature. app.js is 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

Advanced Merging

1 card
  1. 54

    During git rebase main on feature, a conflict shows:

    <<<<<<< HEAD
    ...
    =======
    ...
    >>>>>>> a1b2c3d (add validation)
    

    Which side is feature's change?

    • A

      The lower one: during a rebase, HEAD is the branch being rebased onto, and your commits are replayed on top of it

    • B

      The upper one: HEAD is always the branch you were working on

    • C

      Neither: HEAD is the merge base

    • D

      Both sides are from feature, from two different commits

Git Hooks

1 card
  1. 55

    You wrote a pre-commit hook in .git/hooks/ that runs the linter. A teammate clones the repository. Does the hook run for them?

    • A

      No: .git/hooks is 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

git-update-index

1 card
  1. 56

    You chmod +x deploy.sh on a tracked file and change nothing else. What does git status show?

    • 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 100755 versus 100644)

    • D

      A rename

git-diff

1 card
  1. 57

    What do git diff, git diff --staged and git diff HEAD compare?

    • 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

git-reset

3 cards
  1. 58

    Which command undoes the last commit but leaves its changes staged?

  2. 59

    Which command undoes the last commit and unstages its changes, keeping them in the working tree?

  3. 60

    Which command discards the last commit together with its changes in the working tree?

End of deck · 60 cards

Save