Starting this week, I began cleaning up my project by reorganizing my repo and learning how to use git rebase to make my commits look neater.
I usually make many "work in progress" (wip) commits while working on a branch because I want to keep track of all my experimental changes. But before making my final commit, my git log is full of these "wip" messages, which can be annoying and not helpful for others.
Before, I used to do this:
Use "git log" to find the last meaningful commit.
Use "git reset" to go back to that commit or the branch point.
Then commit everything again to create a clean history without the "wip" commits.
git log
git reset --soft xxxxx
git commit -m "meaningful message"
It worked, but using git reset was risky because it temporarily removed all my changes from Git. If I didn’t have a remote repository to back up my work, I could have lost everything.
A better choice is to use git rebase. I use lazygit to make it easier and smoother to manage and edit my commit history.
I can remove the unnecessary commit.
These commits are no longer part of the history line.
Or squash several commit into one.
The file changes and commit messages are combined into a single commit so I can keep a clear and easy-to-follow history.
Top comments (0)