Location>code7788 >text

Reviewbot Open Source | Some git commits are really bad, I recommend every engineer to use git rebase and git commit --amend.

Popularity:800 ℃/2024-11-18 10:26:40

Reviewbot Is a seven cattle cloud open source project , aims to provide a self-hosted code review service , easy to do code review/static check , as well as custom engineering specifications of the landing .


In day-to-day programming collaboration, the quality of Git commit records often reflects the engineering quality of an engineer. However, I often see commit records that are not very standardized. Sometimes, it's just not good enough.

Like this.

In this case, it's likely that you've made a commit, and then you've made a change, so you're just going to reuse the last git commit command as you go along.

This kind of logging might be fine if it occurs in a personal warehouse . But if it's a multi-person collaborative warehouse, it's a bit unprofessional.

In my opinion, these commit logs are completely unnecessary and a very bad habit that can be completely avoided.

Luckily, Git has an elegant solution for us. If you don't need to generate a new commit, you can just use thegit commit --amend It can be avoided.

use sparinglygit merge multipurposegit rebase

Like this.

Merge branch 'feature-A' of /qiniu/reviewbot into feature-B

This is about merging the code from the remote branch feature-A into feature-B. In this case, feature-A is usually the master branch.

This kind of commit message is completely unnecessary if it appears in your PR, which should contain only useful information for this change.

I personally hardly use it on a daily basisgit mergeEven for synchronizing remote branches, I generally use thegit rebase

For example.

In addition to the above benefits, git rebase also keeps the commit history of your main repository very clean. So it is highly recommended to use it.

Reviewbot's git commit check

In order to better regulate these two behaviors, Reviewbot has also added a git commit check capability, which is used to check whether git commit records are compliant with the specification.

If it doesn't meet the specification, Reviewbot will prompt you to.

More git flow specifications and tips

Of course, there are a lot of practical tips for git operation, so I suggest that you study them if you are interested. When I was in the 1024 bootcamp, I shared this with the students: "I'm not sure if you're going to be able to do this, but I'm sure you'll be able to do it.

Practical! Git Collaboration from a Usage Perspective, Say Goodbye to Rote Memorization!

There is a link to the video inside the document for those interested.

Finally, as professional engineers, we should always pursue excellent engineering practices. A good commit record is not only a reflection of one's professionalism, but also an important cornerstone for enhancing the efficiency of teamwork.

By using git rebase and git commit --amend wisely, we can maintain a clearer and more professional code commit history. This not only makes code review easier, but also facilitates maintenance and issue tracking.

What do you think?