There are a couple different ways to squash commits, and choosing the appropriate one depends on what we need to achieve. (We all learn from our embarrassments, especially the public ones - I’m looking at you, past-Vicky.) If your messy commits currently only exist on your local version, great! We can tidy them up into one clean, well-described commit that we’ll be proud to push, and no one will be the wiser. If you’ve pushed messy commits to a public repository, I say go right ahead and leave them be, instead of complicating things further. It’s kind of like going back in time, where changes you make to your version of the project cause it to look completely different from a version that someone else forked from a point in history that you’ve now erased - I mean, haven’t you seen Back to the Future Part II? (If you’d rather maintain that only one Back to the Future movie was ever made, thus sparing your future self from having to watch the sequels, I get it.) Let’s get one thing out of the way first: rewriting Git history just for the sake of having a pretty tree, especially with public repositories, is generally not advisable. One change per commit: how to squash Git commits I came across these for Sublime Text 3 and language specific settings for VS Code. Other editors have settings that can help us out as well. If you’re curious, you can find my full ~/.vimrc in my dotfiles. " Filetype detection, plugins, and indent rules filetype plugin indent on " Syntax highlighting syntax on " Spell check and line wrap just for git commit messages autocmd Filetype gitcommit setlocal spell textwidth = 72 gitmessage in your home directory), then create the template file with Vim: To set it, configure Git to use a template file (for example. You can set up a commit message template by using the commit.template configuration value. This can be a lot to remember to cover, but there’s a slick way to have these prompts at hand right when you need it. This other classic post also discusses three questions that the body of the commit message should answer: If applied, this commit will your subject line here As very well put in this classic post and the seven rules of a great Git commit message:Ī properly formed Git commit subject line should always be able to complete the following sentence: I think Linus would be very happy if we didn’t use git commit -m "Fix bug" in a public repository ever again. If the majority of your Git commits so far have been created with something like git commit -m "Bug fixes" then this is the article for you! Write great Git commit messages with a template There are some features of Git that can benefit us in these areas, as can harnessing tools like Vim. Other items on this list have to do specifically with making commits in Git. I wrote another article that discusses this in detail, especially the part about code review. Some of the above is achieved through maintaining a short feedback loop that helps you improve your code quality while staying accountable to yourself. Make only one change per commit and avoid including unrelated changes.Use descriptive commit messages that reference related discussion.Write clean code that meets style specifications.Provide and/or use tests to avoid committing bugs or broken builds.From those (really great) threads, I distilled these main points: Being responsible can mean a lot of things to different people, so I enlisted some of mastodon.technology (instance shut down since) and dev.to to help round out my list. Whether our code will be seen by the entire open source community or just future versions of ourselves, either one will be grateful if we commit responsibly today. Here’s how you can create and maintain a clean and orderly Git commit history using message templates, learning how to squash commits, using git stash, and creating annotated commit tags. A history of clean commits can be evidence of a lot of things: attention to detail, good work ethic, and genuine investment in the project.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |