Pegah Einaliyan
Jul 21, 2017 · 2 min read

WHAT MAKES A GOOD GIT COMMIT?

WHY git commit?

Git commit is important for communication between team members and for the life cycle of the team: its past and its future.

Having a story in your git log will make a huge difference in how you and others perceive your project. By taking great care in commit messages, as you do in your code, you will help to increase overall quality.

THE WHY, NOT THE HOW:

Try to explain why you did this changes in the short form instead of explaining how you change that.Because later you understand how you did you code but finding why you did this code it may get a long time .

Therefore, first and foremost add context (the why, not the how) with your commit message (e.g. “frobnize the message to enable persistence”) instead of “added frob() function”). It’s more effort (you have to reflect and think), but it is worth so much more.

GOOD commit:

At least three important purposes:

  • To speed up the reviewing process.
  • To help us write a good release note.
  • To find out why a particular change was made to the code or why a specific feature was added

TO get the purposes:

1)The first line should always be 50 character or less

2 )If it seems difficult to summarize what your commit does, it may be because it includes several logical changes or bug fixes, and are better split up into several commits using git add -p.

3)Never use the -m <msg> / --message=<msg> flag to git commit.

It gives you a poor mindset right off the bat as you will feel that you have to fit your commit message into the terminal command, and makes the commit feel more like a one-off argument than a page in history:

git commit -m "Fix login bug"

A more useful commit message might be:

Redirect user to the requested page after login
)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade