With dvcs/git, is a single commit preferred over multiple, small, thematic commits?

折月煮酒 提交于 2019-12-01 21:03:55

One criteria that can help you make the right "amount" of commit is git bisect or git blame: would a large commit be a nuisance when trying to git bisect in order to detect a bug?

That is what describes the "Understanding the Git Workflow" blog post, when it describes "checkpoint commits" (too little commits capturing the code in a unstable state), or "no-ff commits" (which represents too many modification bundled together in one large commit).

Its preferable to make commits atomic. That is, a commit represents one logical change to the project in question, and can stand alone.

This allows

  1. Easy code inspection
  2. git bisect to work correctly

It can be difficult, and there are many differing views about "the one best workflow". Where possible it is better to

  1. separate concerns - use a number of short lived separate branches, one per concern. You can always squash your commit sequence before the final merge and publishing to a more senior branch.
  2. commit often - smaller steps make it easier to find where mistakes happened and why, and to align merges. Again you can squash after it works.
  3. use the staging area and git stash to partition which work you place in each commit.
  4. Don't worry too much about minor slip ups. Foresight only happens if you walk backwards..
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!