gpt4 book ai didi

git - 如何在 git 中重新添加添加的文件(仅更新暂存文件)?

转载 作者:行者123 更新时间:2023-12-04 21:52:16 26 4
gpt4 key购买 nike

我们在 path/to/another/ 中修改了文件和 path/to/main/ .path/to/main/ 中的文件已添加到 git 缓存中,但我们已更新 path/to/main/Bar.php文件 再次 .我们现在有以下情况:

$ git status
[...]
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: path/to/main/Foo.php
modified: path/to/main/Bar.php

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: path/to/main/Bar.php
modified: path/to/another/Aaa.php
modified: path/to/another/Bbb.php

(注意 path/to/main/Bar.php 出现了两次)

我需要一个可以读取之前添加的文件而不使用特定路径的命令。

附言 git add --update将添加所有这些文件。它不起作用。

P.P.S.此命令应该能够读取 modified:new file:类型。

UPD1

感谢@AyonNahiyan,是的,它可以在 bash 中工作。但也许有一个不使用 bash 技巧(子命令)的命令。

最佳答案

这显示了仅暂存的文件列表:

git diff --name-only --cached
现在使用它们的新更改暂存这些文件(它将在 bash 中工作)
git add $(git diff --name-only --cached)
PS:(前提条件)运行这些命令时,您需要位于 git repo 的根目录下。在任何子文件夹中运行都不起作用

关于git - 如何在 git 中重新添加添加的文件(仅更新暂存文件)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39477305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com