git - 为什么 git add --update 将新文件添加到索引中?
问题描述
-u
标志git add
似乎并没有按照它记录的方式工作;有人可以解释我错过了什么吗?
(-u
或--update
)标志记录如下:
-u, --update
Update the index just where it already has an entry matching <pathspec>. This removes as well as
modifies index entries to match the working tree, but adds no new files.
If no <pathspec> is given when -u option is used, all tracked files in the entire working tree are
updated (old versions of Git used to limit the update to the current directory and its
subdirectories).
根据我的阅读,普通git add -u
文件不应将任何新文件添加到索引中,而应仅重新添加已暂存的任何文件。这是我想要的行为。
但是,如果我修改一个文件然后运行git add -u
. 修改后的文件就像我没有使用过-u
. 我不明白如何将这种行为与“不添加新文件”的文档声明相协调。
解决方案
看来您可能不认为签出提交中的所有内容都存在索引条目;但他们确实如此。并非每个索引条目都由(例如)显示git status
,就像不是列出工作树中的每个文件一样;status
仅显示对索引或工作树的更改。但是“被追踪”和“在索引中”的意思是一样的。
所以,这就是全部-u
- 它可以防止跟踪未跟踪的文件。如果您只想提交已经进行了一些更改的文件,AFAIK 您将需要一个自定义解决方案。
推荐阅读
- adal - 如果在 B2B 场景中的 o-Auth 流程期间传递了租户 ID,则添加到 Azure AD 的来宾(真实帐户)无法登录
- sql - 如何从 Windows 卸载 sql 开发者?
- python-3.x - 如何将代码从 jupyter notebook 共享到安装了 python3 的服务器?
- c# - ASP.NET Razor 页面 - 从表单输入设置其他类变量
- postgresql - 如何在 Postgres 中删除非身份索引?
- swift - Xcode Server bot 构建错误 - 无法加载文件列表的内容:目标支持文件
- c# - 为什么在 ObservableCollection 中引用该属性时,此绑定不起作用?
- flutter - Flutter (Dart) 中的 AES/GCM 加密
- mysql - 数据库 - 如何使用下拉列表填充数据库 - MySQLWorkbench 错误 - OSX 客户端
- python - 点与 cvxopt.glpk 整数规划中的条目一起使用