我不是git的专家,但我知道版本控制的整个想法是要能够记录文件的历史。如果我们可以通过提交(commit)来跟踪工作目录中文件的更改,则为什么我需要执行
我阅读了这个 SO线程并找到以下内容:
“I use git add when I think a file is ready to be committed, even if I know I won't make the commit until some time later. All else apart, git diff reports on the differences between what is in the index (staging area) and what is out in the working directory.”
这说明在
抱歉如果我的问题听起来很愚蠢。提前感谢您的回答!
git add
来记录文件的记录,而不是直接进行 git commit
?我阅读了这个 SO线程并找到以下内容:
“I use git add when I think a file is ready to be committed, even if I know I won't make the commit until some time later. All else apart, git diff reports on the differences between what is in the index (staging area) and what is out in the working directory.”
这说明在
git commit
之前执行git add
的好处。是否还有其他类似的好处,或者git add
只是应该遵循的普遍约定(但为什么?),或者在不执行git add
的情况下执行git commit
始终有效?抱歉如果我的问题听起来很愚蠢。提前感谢您的回答!
git add -i
命令,你可以告诉 Git 在下一个版本中包括哪些修改文件的_部分_。 - eftshift0git add
是回答问题#1的一部分,而问题#2需要诉诸哲学、形而上学、心理学或其他更模糊和/或动荡的思想领域。 - torekgit commit
不使用工作树中的内容。它提交的是Git的索引(或暂存区)中的内容。因此,在提交之前,必须将某些内容从工作树复制到暂存区。使用git commit -a
会先为您运行一个单独的复制到暂存区步骤,但它的工作方式存在一些缺陷;有时您需要使用git add
。 - torek