11 git
我执行了一个新的克隆并将工作目录复制/粘贴到克隆目录中。现在有一个更改文件的列表:
$ git status --short | grep -v "??" | cut -d " " -f 3
GNUmakefile
Readme.txt
base32.h
base64.h
...
Run Code Online (Sandbox Code Playgroud)
当我尝试让 Git 添加它们时,会导致错误(我不在乎一次添加 1):
$ git status --short | grep -v "??" | cut -d " " -f 3 | git add
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
Run Code Online (Sandbox Code Playgroud)
添加-
:
$ git status --short | grep -v "??" | cut -d " " -f 3 | git add -
fatal: pathspec '-' did not match any files
Run Code Online (Sandbox Code Playgroud)
并且--
:
$ git status --short | grep -v "??" | cut -d " " -f 3 | git add --
Nothing specified, nothing added.
Maybe you wanted to say 'git add .'?
Run Code Online (Sandbox Code Playgroud)
尝试使用手册页中的交互似乎使事情变得更加混乱:
$ git status --short | grep -v "??" | cut -d " " -f 3 | git add -i
staged unstaged path
1: unchanged +1/-1 GNUmakefile
2: unchanged +11/-11 Readme.txt
...
*** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
Huh (GNUmakefile)?
What now> *** Commands ***
1: status 2: update 3: revert 4: add untracked
5: patch 6: diff 7: quit 8: help
Huh (Readme.txt)?
Run Code Online (Sandbox Code Playgroud)
(我已经删除了 Git 弄乱的目录,所以我不想解决这个问题)。
我如何告诉 Git 添加通过管道传输到其中的文件?
Dav*_*ing 14
git add
期望文件被列为参数,而不是通过管道传输到stdin
. 尝试
git status --short | grep -v "??" | cut -d " " -f 3 | xargs git add
Run Code Online (Sandbox Code Playgroud)
或者
for file in $(git status --short | grep -v "??" | cut -d " " -f 3); do
git add $file;
done
Run Code Online (Sandbox Code Playgroud)