我们在path/to/another/和中修改了文件path/to/main/.已添加到git缓存中的
文件,path/to/main/但我们已更新path/to/main/Bar.php文件AGAIN.我们现在有以下情况:
$ 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
Run Code Online (Sandbox Code Playgroud)
(注意路径/到/ main/Bar.php出现两次)
我需要一个可以读取之前添加的文件而不使用特定路径的命令.
PS git add --update将添加所有这些文件.它不起作用.
PPS此命令应该能够读取modified:和输入new file:类型.
UPD1
感谢@AyonNahiyan,是的,它可以在bash中运行.但也许有一个命令没有使用bash技巧(子命令).
这显示了仅暂存的文件列表:
git diff --name-only --cached
Run Code Online (Sandbox Code Playgroud)
现在使用他们的新更改暂存这些文件(它将在bash中工作)
git add $(git diff --name-only --cached)
Run Code Online (Sandbox Code Playgroud)
git update-index --again
Run Code Online (Sandbox Code Playgroud)
会做你想做的事。请注意,默认情况下,此命令对当前工作目录(以及子目录,递归地)进行操作。如果要将命令应用于整个存储库,请添加路径规范:
git update-index --again :/:
Run Code Online (Sandbox Code Playgroud)
:/:这里的意思是“工作树的根”。
PS您可以将此命令的别名添加到您的.gitconfig文件中,例如:
[alias]
readd = update-index --again :/:
Run Code Online (Sandbox Code Playgroud)
小智 5
git update-index 可用于此目的。
特别是,
git update-index --again
Run Code Online (Sandbox Code Playgroud)
应该管用。
该--again选项选择索引中已经与HEAD不同的文件。
的实际操作update-index是将这些文件的新内容放入索引。
| 归档时间: |
|
| 查看次数: |
2674 次 |
| 最近记录: |