git rebase with squash
Git is a very powerful tool for source code version control. Often we do POCs and no one whats to waste time while you are doing a POC so often people dont pay much attention to their commit messages(including myself). However the POC grows and you reach the point to productionize the solution, all great but what you do with your poor commit messages? Good messages are critical for good configuration management, release management, and code hygiene. So what can we do? Well git rebase can rescue us. Git rebase is also useful in other use cases where you need to have a specific format of messages because your CI/CD tool does some validations or you are hunting a bug down and you want to drop a bad commit or you are cherry-picking commits to doing a chirurgical release. So I made a short video showing rebase commands in action. We also will use squash which is an interesting way to combine your commits in one for better trackability. So Let's get started.
The Video
The Commands
git log
###
### Commit RANGE from Older to Newer
### OLDER commit NEW COMMIT
git rebase 1483870be2e905111234c4a9ce654c3108dcfdbc b9f14b69ba7f62dd6bbcbb986dc0de75a643b14a -i
You will see something like this:
pick fbb89b1 This is a dummy message
pick fbb89b2 This is a dummy message
pick fbb89b3 .
pick fbb89b4 .
Change it to be all "s"(squash) but the first commit "p"(pick):
p fbb89b1 This is a dummy message
s fbb89b2 This is a dummy message
s fbb89b3 .
s fbb89b4 .
Them you will write a commit message:
ARCH-12345: This is a git commit POC
git rebase -i --root
You will see something like this:
```bash
pick fbb89b1 This is a dummy message
pick fbb89b2 This is a dummy message
pick fbb89b3 .
pick fbb89b4 .
Change it to be all "s"(squash) but the first commit "p"(pick):
p fbb89b1 This is a dummy message
s fbb89b2 This is a dummy message
s fbb89b3 .
s fbb89b4 .
Them you will write a commit message:
ARCH-12345: This is a git commit POC
git push origin -f
git rebase --abort
Cheers,
Diego Pacheco