0
0
Gitdevops~30 mins

Interactive rebase (git rebase -i) - Mini Project: Build & Apply

Choose your learning style9 modes available
Interactive Rebase with git rebase -i
📖 Scenario: You are working on a small project with a few commits. You want to clean up your commit history before sharing your work with your team. This means combining some commits and editing commit messages to make the history clearer.
🎯 Goal: Learn how to use git rebase -i to interactively edit, squash, and reorder commits in your local git repository.
📋 What You'll Learn
Have git installed and a local git repository initialized
Have at least 3 commits in your current branch
Use git rebase -i to modify commit history
Understand basic git commands like git log and git commit
💡 Why This Matters
🌍 Real World
Cleaning up commit history before sharing code helps keep project history clear and understandable for everyone.
💼 Career
Using interactive rebase is a common skill for developers and DevOps engineers to maintain clean and professional git histories.
Progress0 / 4 steps
1
Create initial commits
Create three commits in your git repository with these exact commit messages in order: "Add README", "Add LICENSE", and "Update README". Use git commit with the -m option to set the messages.
Git
Need a hint?

Use git commit --allow-empty -m "message" to create commits without changing files.

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

The command git rebase -i HEAD~3 opens the last 3 commits for editing.

3
Edit the rebase todo list
In the opened editor, change the second commit's action from pick to squash to combine it with the first commit. Leave the others as pick. Save and close the editor to continue.
Git
Need a hint?

Change only the second commit's action from pick to squash in the editor that opens after running git rebase -i.

4
View the updated commit history
Run git log --oneline -3 to display the last three commits and verify that the second commit was squashed into the first.
Git
Need a hint?

The output of git log --oneline -3 should show two commits with messages including "Add README" and "Update README" after squashing.