Thank you git rebase –interactive!

By Greg Turnquist

Greg L. Turnquist worked on the Spring team for over thirteen years and is a senior staff technical content engineer at Cockroach Labs. He was the lead for Spring Data JPA and Spring Web Services. He wrote Packt's best-selling title, Learning Spring Boot 2.0 2nd Edition, and its 3rd Edition follow-up along many others.


September 16, 2011

Today I had the good fortune to read The article perfectly served my needs.

I’ve been working on a new feature for several days. At first, I build some buttons and new pages, and had all the functionality working. I had also committed the changes. Before pushing them to origin, I sent a diff report to one of my co-workers, and asked him to inspect my handy work. Based on feedback, it was suggested that I put the functionality on another part of the screen. It looked nicer there, and the feedback was built using Ajax instead of a new page.
This meant that some of my pages could be thrown away. After getting the new screen parts working, I removed the old ones. In fact, I removed an edit I had made to a global CSS file. After all this was working, I made some more commits.
What I wanted to avoid was having a commit history showing me adding and then immediately removing some new files as well as adding and removing lines from certain files. Basically, I wanted to compress all this work into a single commit.
As it turns out, this is a piece of cake. git rebase -i HEAD~3 allowed me to look at the three latest commits, keep the first, and squash the other two into it, forming one commit. I did that. Next I was prompted to rewrite the commit log entry. When I realized I had forgotten to delete two files that I had added, I simply removed them and created another commit. I repeated the process by typing git rebase -i HEAD~2, and squashed it all into one commit. Inspecting things, everything appears to be in order.
I can certainly testify that Subversion never offered me anything like this, nor did Rational ClearCase.


Submit a Comment

Your email address will not be published. Required fields are marked *