Git 提交风格:一次更改所有文件还是一次一个? [英] Git commit style: All changed files at once or one at a time?

查看:36
本文介绍了Git 提交风格:一次更改所有文件还是一次一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在晚上保存我的工作,对多个文件进行一次提交.我想知道为每个文件提交是否会更好,但这似乎需要做更多的工作.

I am saving my work at night with a single commit for many files. I wonder if it would be better to commit for each file but this seems like a lot more work.

我对现在的情况没有问题,但我打算将我的代码放在 GitHub 上,我希望它易于理解.

I have no problem with the way things are now but I plan to put my code on GitHub and I want it to be easy to understand.

我想知道其他使用 git 的人在做什么.另外,如果你能帮我把它拼出来.我是 Git 的新手,我一直在 Windows 中使用 TortoiseGit 和 gitk.

I'm wondering what the rest of you who use git are doing. Also if you could kind of spell it out for me. I'm new to Git and I've been using TortoiseGit and gitk in Windows.

推荐答案

何时提交以及提交什么是一门艺术,没有非黑即白的规则.话虽如此,有些习惯比其他习惯更容易理解.

When to commit and what to commit is an art, and there are no black-and-white rules. That being said, there are habits that are easier to understand than others.

总的来说,我认为你应该优化你的提交以提高可理解性——如果你回去阅读提交的差异,你能弄清楚你在更改中取得了什么吗?

In general, I think you should optimize your commits for understandability - if you go back and read the diff for the commit, can you figure out what you accomplished in the changes?

如果你想更具体,这里有一长串我认为应该做和不应该做的事情:

If you want to be more specific, here's a long list of what I think are do's and don'ts:

  • 不要在每一个小改动之后提交——每一行都发生了变化,每个文件都发生了变化,等等.
  • 不要工作一整天,并在一天结束时做出一个巨大的承诺.
  • 对不同的功能进行单独的提交 - 例如开发功能 foo 与修复错误 #2.
  • 为移动/重命名文件做一个单独的提交,因为这样 Git 更容易跟踪.
  • 一定要考虑针对可恢复性进行优化:如果您不喜欢所做的更改,即使在新的更改堆积在上面之后,是否也可以轻松撤消它?

这篇关于Git 提交风格:一次更改所有文件还是一次一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆