本文介绍了为什么我会在Git中提交之前想要舞台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的版本控制人员,我知道提交本质上是在更新新版本的当前版本时创建备份。



我不明白的是从实践的角度来看,正在升级只存在于名称中的东西还是用于某种目的?无论如何,它会继续承诺一切,对吗?

编辑:我想我可能会混淆术语。 'staged'文件与'tracked'文件一样吗?

解决方案

当您提交它只会提交索引中的更改(分阶段文件)。这有很多用途,但最明显的是将你的工作改变分解成更小的,独立的部分。也许你在实现某个功能时修复了一个错误。您可以 git add 只是该文件(或 git add -p 来添加文件的一部分!),然后在提交所有内容之前提交bugfix。如果您使用的是 git commit -a ,那么您只需在提交之前立即强制执行 add 。如果您想利用分段文件,请勿使用 -a



您也可以处理暂存文件作为与 - 缓存的许多命令的中间工作副本。例如, git diff --cached 会告诉你舞台与 HEAD 的不同之处,因此你可以看到你的'在你的其他工作变化中不会混淆的情况下重新提交。


I'm new to version control and I understand that "committing" is essentially creating a backup while updating the new 'current' version of what you're working on.

What I don't understand is what staging for is from a practical perspective. Is staging something that exists in name only or does it serve a purpose? When you commit, its going to commit everything anyway, right?

Edit: I think I may be confusing the terminology. Is a 'staged' file the same thing as a 'tracked' file?

解决方案

When you commit it's only going to commit the changes in the index (the "staged" files). There are many uses for this, but the most obvious is to break up your working changes into smaller, self-contained pieces. Perhaps you fixed a bug while you were implementing a feature. You can git add just that file (or git add -p to add just part of a file!) and then commit that bugfix before committing everything else. If you are using git commit -a then you are just forcing an add of everything right before the commit. Don't use -a if you want to take advantage of staging files.

You can also treat the staged files as an intermediate working copy with the --cached to many commands. For example, git diff --cached will show you how the stage differs from HEAD so you can see what you're about to commit without mixing in your other working changes.

这篇关于为什么我会在Git中提交之前想要舞台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 20:16