Bird
Raised Fist0
Gitdevops~20 mins

Recovering from bad rebase in Git - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Rebase Recovery Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Output of git reflog after a bad rebase
You performed a rebase that caused conflicts and you want to see the previous HEAD states to recover. What will be the output of git reflog immediately after the bad rebase?
Git
git reflog
AShows only the commits that were rebased, excluding previous HEAD states
BShows only the current branch commit history without any rebase info
CShows an error: 'fatal: no reflog found' because reflog is disabled by default
DShows a list of recent HEAD changes including the rebase start and commits before rebase
Attempts:
2 left
💡 Hint
Think about what reflog tracks in Git.
🔀 Workflow
intermediate
2:00remaining
Steps to abort a bad rebase safely
You started a rebase but realize it is causing too many conflicts. Which sequence of commands correctly aborts the rebase and returns your branch to the state before the rebase?
A1, 4, 2, 3
B1, 2, 3, 4
C2, 1, 4, 3
D4, 2, 1, 3
Attempts:
2 left
💡 Hint
You need to check status before aborting and verify after abort.
❓ Troubleshoot
advanced
1:30remaining
Recovering lost commits after a failed rebase
After a rebase gone wrong, some commits seem lost from your branch history. Which command helps you find and recover those lost commits?
Agit reflog
Bgit reset --hard HEAD~3
Cgit clean -fd
Dgit stash pop
Attempts:
2 left
💡 Hint
Think about where Git tracks all recent HEAD movements.
✅ Best Practice
advanced
1:30remaining
Best practice to avoid losing work during rebase
Which practice best helps prevent losing commits during a complex rebase?
AUse 'git push --force' immediately after rebase
BCreate a backup branch before starting the rebase
CDelete local branches before rebasing
DRun 'git clean -fd' before rebase
Attempts:
2 left
💡 Hint
Think about how to save your current work safely before risky operations.
🧠 Conceptual
expert
1:30remaining
Understanding the effect of git rebase --continue after conflict resolution
After resolving conflicts during a rebase, what does git rebase --continue do?
AIt applies the next commit in the rebase sequence and updates HEAD
BIt aborts the entire rebase and resets to original branch state
CIt skips the current commit and moves to the next one
DIt merges the current branch into the target branch
Attempts:
2 left
💡 Hint
Think about how rebase processes commits one by one.

Practice

(1/5)
1. What is the safest way to stop a rebase process if you realize it is going wrong?
easy
A. Use git rebase --abort to cancel the rebase
B. Use git reset --hard HEAD to cancel the rebase
C. Use git commit --amend to fix the rebase
D. Use git push --force to undo the rebase

Solution

  1. Step 1: Understand the rebase abort command

    The command git rebase --abort safely stops and cancels the ongoing rebase process, restoring the branch to its original state before the rebase started.
  2. Step 2: Compare with other commands

    Other commands like git reset --hard HEAD or git commit --amend do not cancel a rebase safely. git push --force is for pushing changes, not aborting rebase.
  3. Final Answer:

    Use git rebase --abort to cancel the rebase -> Option A
  4. Quick Check:

    Cancel rebase safely = git rebase --abort [OK]
Hint: Abort rebase with git rebase --abort to safely cancel [OK]
Common Mistakes:
  • Using git reset --hard HEAD which may lose changes
  • Trying to amend commits during rebase to fix errors
  • Forcing push without fixing rebase issues
2. Which of the following commands correctly shows the history of recent HEAD positions to help recover from a bad rebase?
easy
A. git reflog
B. git branch -a
C. git status
D. git log --oneline

Solution

  1. Step 1: Identify the command to view HEAD history

    git reflog shows a log of where HEAD and branches have pointed recently, including before and after rebases.
  2. Step 2: Understand why other commands don't help here

    git log --oneline shows commit history but not HEAD movements. git status shows current state. git branch -a lists branches.
  3. Final Answer:

    git reflog -> Option A
  4. Quick Check:

    View HEAD history = git reflog [OK]
Hint: Use git reflog to find commits before rebase [OK]
Common Mistakes:
  • Using git log which doesn't show HEAD moves
  • Confusing git status with reflog
  • Looking at branches instead of commit history
3. After a bad rebase, you find the commit hash abc1234 from git reflog. What does the command git reset --hard abc1234 do?
medium
A. Creates a new branch at commit abc1234
B. Moves the current branch to commit abc1234 and discards all changes after it
C. Starts a new rebase from commit abc1234
D. Shows the differences between HEAD and abc1234

Solution

  1. Step 1: Understand git reset --hard with a commit

    The command git reset --hard abc1234 moves the current branch pointer to the commit abc1234 and resets the working directory and index to match that commit, discarding any changes after it.
  2. Step 2: Clarify what the other options do not do

    This command does not create a new branch, start a rebase, or show differences. It forcibly resets the branch state.
  3. Final Answer:

    Moves branch to abc1234 and discards later changes -> Option B
  4. Quick Check:

    Reset hard to commit = move branch and discard changes [OK]
Hint: Reset hard to commit to undo bad rebase changes [OK]
Common Mistakes:
  • Thinking reset creates a new branch
  • Confusing reset with diff or rebase commands
  • Using reset without knowing it discards changes
4. You started a rebase but got conflicts and want to cancel it. You run git reset --hard HEAD instead of git rebase --abort. What is the likely result?
medium
A. The rebase is safely canceled and branch restored
B. The rebase continues but changes are lost
C. The working directory resets but rebase metadata remains, causing issues
D. Git shows an error and stops

Solution

  1. Step 1: Understand difference between reset and rebase abort

    git reset --hard HEAD resets files but does not clear rebase state files, so the rebase process is still active.
  2. Step 2: Consequence of not aborting rebase properly

    This causes Git to think rebase is ongoing, leading to confusion and possible errors until git rebase --abort is run.
  3. Final Answer:

    Working directory resets but rebase metadata remains, causing issues -> Option C
  4. Quick Check:

    Reset hard ≠ abort rebase; rebase metadata stays [OK]
Hint: Always use git rebase --abort to cancel rebase, not reset [OK]
Common Mistakes:
  • Using reset hard to cancel rebase
  • Assuming reset clears rebase state
  • Ignoring rebase metadata files causing errors
5. You performed a bad rebase and want to recover your branch to the state before the rebase started. Which sequence of commands correctly recovers your branch?
hard
A. git checkout master -> git merge --abort
B. git reset --hard HEAD~1 -> git rebase --abort
C. git rebase --continue -> git reset --soft HEAD~1
D. git reflog -> find commit before rebase -> git reset --hard <commit>

Solution

  1. Step 1: Use git reflog to find the commit before the bad rebase

    git reflog lists recent HEAD positions, so you can identify the commit hash before the rebase started.
  2. Step 2: Reset branch to that commit to undo the bad rebase

    Using git reset --hard <commit> moves the branch pointer back and resets files to that safe commit, effectively undoing the bad rebase.
  3. Final Answer:

    git reflog -> find commit before rebase -> git reset --hard <commit> -> Option D
  4. Quick Check:

    Recover bad rebase = reflog + reset hard [OK]
Hint: Find pre-rebase commit with reflog, then reset hard to it [OK]
Common Mistakes:
  • Trying to abort after rebase finished
  • Using reset soft which keeps changes
  • Confusing merge abort with rebase abort
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard