Git Rebase -i12
The git rebase -i command allows you to interactively rebase your commits. This means you can edit, reorder, squash, or drop commits before applying them to another branch.
Example
git checkout feature-branch
git rebase -i HEAD~3
This command opens an editor with the last three commits listed. You can then choose actions like pick, reword, edit, squash, or drop for each commit.
Actions
- pick: Use the commit as is.
- reword: Change the commit message.
- edit: Amend the commit.
- squash: Combine this commit with the previous one.
- drop: Remove the commit.
Considerations
-
History Rewriting: Rebasing changes commit history, which can cause issues if others have based work on the original commits.
-
Clean History: It helps in maintaining a cleaner project history by linearizing the commit sequence.
Use git rebase -i to refine your commit history before merging or pushing changes to a shared repository.