0
0
Gitdevops~30 mins

Reordering commits in Git - Mini Project: Build & Apply

Choose your learning style9 modes available
Reordering Commits with Git
📖 Scenario: You are working on a project using Git. You made three commits in a row, but you realize the order of these commits should be changed to make the history clearer.Imagine you wrote three small changes: first a README update, then a bug fix, and finally a new feature. You want to reorder these commits so the bug fix comes first, then the feature, and the README update last.
🎯 Goal: Learn how to reorder commits in Git using interactive rebase.You will create three commits, then reorder them so the commit history shows the bug fix first, the feature second, and the README update last.
📋 What You'll Learn
Create three commits with exact commit messages: 'Update README', 'Fix bug', 'Add feature'
Use a Git interactive rebase to reorder commits
Verify the new commit order by listing commits
💡 Why This Matters
🌍 Real World
Reordering commits helps keep project history clean and understandable, which is important when collaborating with others.
💼 Career
Many software development and DevOps roles require managing Git histories effectively to maintain code quality and collaboration.
Progress0 / 4 steps
1
Create three commits with exact messages
Create three commits in this exact order with these commit messages: Update README, Fix bug, and Add feature. Use git commit -m with these messages exactly.
Git
Need a hint?

Use git commit -m "message" to create commits with exact messages.

2
Start interactive rebase to reorder commits
Start an interactive rebase for the last three commits using git rebase -i HEAD~3.
Git
Need a hint?

Use git rebase -i HEAD~3 to edit the last three commits.

3
Reorder commits in the interactive editor
In the interactive rebase editor, reorder the commits so the commit with message Fix bug is first, then Add feature, and finally Update README. Save and exit the editor to apply the new order.
Git
Need a hint?

In the editor, move the lines so the commit messages are in the order: Fix bug, Add feature, Update README.

4
Verify the new commit order
Use git log --oneline to display the commit history and verify the commits are now ordered with Fix bug first, Add feature second, and Update README last.
Git
Need a hint?

Run git log --oneline and check the commit messages appear in the new order.