git checkout是否更新所有文件? [英] Does git checkout update all files?

查看:1105
本文介绍了git checkout是否更新所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我 git checkout< revision> ,那么这会将整个项目返回到它的状态,还是只重新创建那个特定修订版中更改的文件?



例如:如果我的文件夹除了.git repo和I git checkout master 之外完全是空的,那么生成的文件将是其中的项目整体,还是只有在最近的提交中更改过的文件?



我问,因为我在各个点(从头开始)检查我的项目,该项目的规模正在缓慢增长,正如人们所预料的那样,每个结账的规模都有很大的不同。

$ b

当我 git checkout< revision> 时,它是否会将整个项目返回到当时的状态,或者它只是重新创建更改的文件如果您的工作树 > staging区域是完全空的(当然除了 .git 子目录)并且运行

  git checkout< revision> 

那么您的工作树和临时区域将完美地反映出特定 git checkout 时你的工作树不是空的,发生的事情要微妙得多,可能会被分解为三种情况:


  1. 结帐没有问题,Git可以在没有打击的情况下执行eyelid:将特定修订版的内容复制到工作树中(如果需要,则覆盖已存在的内容)。或

  2. 结账,如果执行结账,将导致本地变更的损失;因此,Git(假设您没有使用 -f 标志)会告诉您并中止结帐。或
  3. 更复杂的情况可能出现在只有部分检出的东西中,并且一些本地未提交的更改会保留在您的工作树和/或索引中。关于这种情况的更多细节可以在我对为什么在检出不同的分支后依然存在未分离的更改?




每次结帐的大小相差很多。

您是否考虑到未跟踪的文件?你提交了,然后删除大文件?根据您在问题中提供的信息,我们可以做的不过是推测尺寸差异很大的原因。


Newb question, I want to make sure I understand this.

When I git checkout <revision>, does this return the entire project to its state at that moment, or does it only recreate the files changed in that particular revision?

For example: If my folder was completely empty besides the .git repo, and I git checkout master, will the resulting files be the project in its entirety, or only the files changed in the most recent commit?

I ask, because I am checking out my project at various points (starting from the beginning), and instead of the project slowly growing in size as one would expect, the size of each checkout is varying quite a lot.

解决方案

When I git checkout <revision>, does this return the entire project to its state at that moment, or does it only recreate the files changed in that particular revision?

If your working tree and staging area are completely empty (besides the .git subdirectory, of course) and you run

git checkout <revision>

then your working tree and staging area will perfectly reflect the contents of that particular revision.

On the other hand, if your working tree is not empty when you run git checkout, what happens is much more subtle, and may be broken down into three cases:

  1. The checkout is not problematic and Git carries it out without batting an eyelid: the contents of that particular revision get copied to your working tree (and overwrite stuff already present there, if needed). Or
  2. The checkout, if it were carried out, would result in a loss of local changes; therefore, Git (under the assumption that you didn't use the -f flag) tells you off and aborts the checkout. Or
  3. A more complicated situation may arise in which stuff is only partially checked out, and some local, uncommitted changes are kept in your working tree and/or index. More details about that situation can be found in my answer to Why are unstaged changes still present after checking out a different branch?.

[...] the size of each checkout is varying quite a lot.

Are you taking into account untracked files? Did you commit, then later remove large files? On the basis of the information given in your question alone, we can do little more than hypothesize about the reason why the size varies a lot.

这篇关于git checkout是否更新所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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