Introduction
Version control is an essential discipline for any developer, but it often comes with its own set of challenges. The Git version control system, while powerful, can lead to what some refer to as "Git rigour fatigue." This is where Jujutsu comes in, offering an alternative approach to managing commits in a more seamless and intuitive way.
What is Git Rigour Fatigue?
When developing a large feature, it's crucial to maintain clear and concise commits. "Good commits" are those that allow easy review and clear understanding of changes. However, in practice, developers often end up with disorganized commits, where changes overlap and errors accumulate.
Concrete Example
Let's take an example of developing a complex feature. Ideally, you would split the work into several commits:
- Define types
- Add database functions
- Implement server CRUD
- Create client API
- Develop user interface
However, in reality, commits often look like this:
- Define types
- Add database functions
- WIP (Work In Progress) test code
- Server CRUD
- Client API and UI
- Fix DB function
- UI bug fix
This disorganization can make code review tedious and complex.
Jujutsu: A Solution to Fatigue
Jujutsu (jj) is a version control system that simplifies hopping between commits and quickly iterating on compartmentalized change sets. It offers commands like jj absorb and jj squash, which, though imperfect, help reorganize commits.
The "Laundry" Technique
An effective approach is to first create an ideal commit history, then reorganize the changes. Here's how:
- Create an initial commit with
jj new -B messy-first -m 'description'. - Add subsequent changes and use
jj squash --from messy-first..messy-last --into messy-firstto merge these commits into one. - Use
jj squash -i --from messy-first --into [color]to sort changes by type.
This method allows increased flexibility, reducing the need to maintain strict rigour throughout development.
Why Does This Approach Work?
Unlike the jj split method, this technique allows easier organization of changes from the start, without worrying about the effect on commit sequencing. Moreover, performing this reorganization at the end provides clarity on the final state of the feature.
Conclusion
Version control doesn't have to be a burden. With tools like Jujutsu, it's possible to significantly reduce Git rigour fatigue and simplify the development process. Ready to optimize your version control management?
Let's discuss your project in 15 minutes.