![]() You need to leave at least one commit without "s" because that's where the other commits will "fall onto". S 2ac7ce3 Finishes feature implementation To do that, type "i" to go into "insert mode" and replace "pick" with "s": pick eea6731 wip Adds something Now, you will need to select the commits you want to squash into one, always from the newest to the oldest. # Rebase bde8672.2ac7ce3 onto bde8672 (4 commands) Pick 2ac7ce3 Finishes feature implementation That command will open up the list of commits with pick in front of the hash, like this: pick eea6731 wip Adds something Which means you will rebase interactively (the -i flag) and want to start from the current commit (HEAD) until the fourth commit from that reference, which in this example is eea6731. So, before merging it to the main branch, if you'd like to combine those commits with a meaningful message, you can run: git rebase -i HEAD~4 The latest four commits are part of the feature branch and are together they represent the final feature. If you use git log -pretty=oneline you would have something similar to this: 2ac7ce3 (HEAD -> feature-branch) Finishes feature implementation Let's say you created a feature branch based on the main branch and have many commits already, most of them still work in progress (the feature is still not fully implemented). But, when inevitably merging to the main branch, I like to have only meaningful commits. I'm a big fan of commiting often and with small changes. Today, I'd like to show you a quick tip that can help you during big git merges, future rebases or just to keep your branches and commit list cleaner. ![]()
0 Comments
Leave a Reply. |