简体   繁体   English

不提交暂存(git)

[英]Staging without committing (git)

We know that, in git, when we stage a file with 我们知道,在git中,当我们使用

git add readme.txt

the "readme.txt" file is not committed, and it remains so until we use “ readme.txt”文件未提交,并且保持不变,直到我们使用

git commit readme.txt -m "..."

But I cannot imagine that such a situation is useful. 但是我无法想象这样的情况是有用的。 In what situation do we ever need to stage a file without committing it? 在什么情况下我们需要暂存文件而不提交文件?

It is useful if you want to commit it later . 如果你想稍后提交它是有用的。

You could for example, stage it today, and continue to work on the project tomorrow (you think the modified file is okay, but still have to fix others and add unit tests). 例如,您可以在今天暂存它,然后在明天继续进行该项目(您认为修改后的文件还可以,但仍然必须修复其他文件并添加单元测试)。 Having staged the file gives you a "savepoint" of sorts. 暂存文件后,将为您提供各种“保存点”。 You can then do things like diff against the staged version. 然后,您可以针对暂存版本执行diff之类的操作。

A common workflow is to immediately stage new files (even though they are still empty), so that they show up as "modified" instead of "untracked" and you don't later forget to include them in the commit. 常见的工作流程是立即上载新文件(即使它们仍然为空),以使它们显示为“已修改”而不是“未跟踪”,并且您以后不会忘记将它们包括在提交中。 Many IDE do that automatically when you create new source code files. 创建新的源代码文件时,许多IDE都会自动执行此操作。

git commit readme.txt -m "..." git commit readme.txt -m“ ...”

Actually, you would probably not be saying "commit readme.txt". 实际上,您可能不会说“ commit readme.txt”。 You can commit without listing any files, and it will commit everything that was staged before. 您可以提交而不列出任何文件,并且它将提交之前已暂存的所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM