为什么在git中有一个临时过程? [英] Why is there a staging process in git?

查看:159
本文介绍了为什么在git中有一个临时过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在git add和git commit之间存在分区?
我理解这个概念,但在实际提交之前没有看到在将文件添加到暂存区域中的意义。为什么不跳过这一步?

Why is there the staging area between "git add" and "git commit"? I understand the concept, but fail to see the sense in adding files to the staging area before actually commiting. Why not skip this step?

推荐答案

事实是:索引是一个暂存区域。每个SCM都有它,但git向你展示并有效地使用它。

一个主要原因是你不必提交整个工作目录。您可以将其中的部分内容移至索引并提交。

One main reason is so you don't have to commit your entire working directory. You can move portions of it to the index and commit just those.

例如,您正在处理两种不同的事情,现在您的代码看起来像

For example, you're working on two different things, and now your code looks like

//random code

//bug fix

//new feature

您可以只修改 //错误修正行和提交,并阶段 //新功能行并提交。

You can stage just the //bug fix line and commit that, and than stage the //new feature line and commit that.

您现在有两个每个提交不同的提交。后来在测试中发现新特性提交失败了,你可以删除新特性提交, t必须重新提交bugfix

You now have two different commits for each. Later on in testing you realize the new feature commit broke something, you can delete the new feature commit, but don't have to recommit the bugfix

正如Dickon Reed在他的回答中指出的那样,您现在也可以获得性能 git commit 现在只需要将索引中的内容添加到提交中。它不需要通过搜索树来查找所有更改。

As Dickon Reed noted in his answer, you also gain performance as git commit now only needs to add what is in the index to the commit. It doesn't need to search through your tree to find all the changes.

这篇关于为什么在git中有一个临时过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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