0
0
Gitdevops~20 mins

Reordering commits in Git - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Commit Reordering Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🔀 Workflow
intermediate
2:00remaining
Reordering commits using interactive rebase
You want to reorder the last 4 commits in your branch so that the oldest commit becomes the newest. Which command sequence correctly starts this process?
Agit rebase -i HEAD~5
Bgit rebase -i HEAD~1
Cgit rebase -i HEAD~3
Dgit rebase -i HEAD~4
Attempts:
2 left
💡 Hint
Remember that HEAD~N means the commit N steps before HEAD, and you want to include exactly 4 commits.
💻 Command Output
intermediate
2:00remaining
Result of reordering commits in interactive rebase
After running 'git rebase -i HEAD~3' and swapping the order of the last two commits in the editor, what will be the effect on the commit history?
AThe rebase will fail with a conflict error
BThe last two commits will swap places in the history
CThe commit messages will be swapped but the order stays the same
DThe commits will be merged into one commit
Attempts:
2 left
💡 Hint
Interactive rebase allows you to reorder commits by changing their order in the editor.
Troubleshoot
advanced
3:00remaining
Resolving conflicts during commit reordering
During an interactive rebase to reorder commits, you encounter a conflict. What is the correct sequence of commands to resolve the conflict and continue the rebase?
AFix the conflict, git add <files>, git rebase --continue
BFix the conflict, git commit, git rebase --skip
CFix the conflict, git reset, git rebase --abort
DFix the conflict, git stash, git rebase --continue
Attempts:
2 left
💡 Hint
After fixing conflicts, you need to stage the changes before continuing the rebase.
🧠 Conceptual
advanced
2:00remaining
Understanding the effect of reordering commits on commit hashes
What happens to the commit hashes of the reordered commits after completing an interactive rebase that changes their order?
AAll reordered commits get new hashes because their parent commits changed
BCommit hashes remain the same since content is unchanged
COnly the first commit in the reordered list gets a new hash
DHashes change only if commit messages are edited
Attempts:
2 left
💡 Hint
Commit hashes depend on the commit content and its parent commit hash.
Best Practice
expert
3:00remaining
Best practice when reordering commits on a shared branch
You want to reorder commits on a branch that others have already pulled. What is the best practice to avoid problems?
AForce push immediately after reordering to update remote
BDelete the remote branch and push a new one with reordered commits
CAvoid reordering commits on shared branches to prevent rewriting history
DRebase and merge the branch into main without pushing
Attempts:
2 left
💡 Hint
Rewriting history on shared branches can cause confusion and conflicts for others.