Git commit style:一次或一次更改所有文件? [英] Git commit style: All changed files at once or one at a time?

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

问题描述

我在晚上节省了我的工作,并为许多文件提供了一次提交。我想知道是否为每个文件提交更好,但这似乎还有很多工作要做。



我现在的方式没有问题,但我打算把我的代码放在GitHub上,我希望它很容易理解。



我想知道你们其他人使用git的情况。另外,如果你能为我拼出来。我是Git的新手,我一直在Windows中使用TortoiseGit和gitk。 解决方案

何时提交和提交什么是一门艺术,没有黑白规则。这就是说,有些习惯比其他人更容易理解。



一般而言,我认为您应该优化您的提交以便理解 - 如果您回头阅读差异的提交,你能弄清楚你在改变中完成了什么?



如果你想要更具体一些,这里有一长串我认为是做什么的和不要在每一个小小的变化之后提交 - 每行改变,每个文件改变等等。

  • 不要在整天工作,并在一天结束时进行一次巨大的提交。

  • 分离出不同功能的提交 - 例如开发功能foo与修复bug#2。

  • 为移动/重命名文件做一个单独的提交,因为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.

    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.

    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:

    • Don't commit after every single little change - every line changed, every file changed, etc.
    • Don't work for an entire day and make one gigantic commit at the end of the day.
    • Do separate out commits for different features - e.g. developing feature foo vs. fixing bug #2.
    • Do a separate commit for moving/renaming files, because it's easier for Git to track this way.
    • Do think about optimizing for revertability: If you dislike a change that you made, is it easy to undo it even after new changes have been piled on top?

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

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