git添加所有跟踪的文件-也包括父目录中的文件

git添加所有跟踪的文件-也包括父目录中的文件,git,git-add,Git,Git Add,假设我有一个git根文件夹mine\u git,其中有一个子目录subdir。所以我做了一点工作,现在处于subdir-git状态列出了所有更改的文件: subdir$ git status -uno # On branch master # ... # # modified: mysubdirfile.txt # modified: ../a-main-file.txt # no changes added to commit (use "git add" and/or "gi

假设我有一个git根文件夹
mine\u git
,其中有一个子目录
subdir
。所以我做了一点工作,现在处于
subdir
-
git状态
列出了所有更改的文件:

subdir$ git status -uno
# On branch master
# ...
#
#   modified:   mysubdirfile.txt
#   modified:   ../a-main-file.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
K、 所以我想将所有这些被跟踪和修改的文件添加到暂存区(或者缓存?索引?不确定名称),以便以后提交;因此,我提出:

subdir$ git add -u
。。。然后我再次检查:

subdir$ git status -uno
# On branch master
# Changes to be committed:
#   ...
#
#   modified:   mysubdirfile.txt
#
# Changes not staged for commit:
#   ...
#
#   modified:   ../a-main-file.txt
#
# Untracked files not listed (use -u option to show untracked files)
因此,只有我当前位置下的文件是
git add
ed,而不是父/同级文件夹中的文件-即使这些文件被这个git存储库跟踪,并显示在
git status

然后我通常必须手动复制粘贴文件名,以便执行
git add../a-main-file.txt
。显然,这是一个痛苦的问题-因此是否有一些命令将添加
git status-uno
列出的所有文件,无论它们是否位于当前级别以下?

最新版本的git(
2.4.3
)应该已经这样做了。从
man1git添加

   -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).
-u,--update
仅在索引已具有匹配项的位置更新索引。
这将删除和修改索引项以匹配工作树,
但不添加新文件。
如果使用-u选项时给出“否”,则整个系统中的所有跟踪文件
更新工作树(使用Git的旧版本将更新限制为
当前目录及其子目录)。
也就是说,您可以尝试类似于
git add-u--../relative/path/to/project/root
。我手边没有一个较旧的git版本,所以我无法测试它。

最新版本的git(
2.4.3
)应该已经做到了。从
man1git添加

   -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).
-u,--update
仅在索引已具有匹配项的位置更新索引。
这将删除和修改索引项以匹配工作树,
但不添加新文件。
如果使用-u选项时给出“否”,则整个系统中的所有跟踪文件
更新工作树(使用Git的旧版本将更新限制为
当前目录及其子目录)。

也就是说,您可以尝试类似于
git add-u--../relative/path/to/project/root
。我手边没有一个较旧的git版本,所以我无法测试它。

git add-u
在这里运行良好谢谢@maggick-正如下面的答案所指出的,它对我不起作用,因为我有一个旧版本的git;干杯
git add-u
在这里运行良好谢谢@maggick-正如下面的答案所指出的,它对我不起作用,因为我有一个旧版本的git;干杯谢谢@suvayu-我用的是1.7.9.5,我猜那里没有这样的功能。。。谢谢你的建议,但这也需要手动复制粘贴文件名。。。不过,如果有人能想出一个处理旧行为的脚本,那就太好了。。再次感谢-干杯@SDAOU为什么说它需要文件名的复制粘贴?我认为只有顶级目录的路径就足够了,不需要所有路径。谢谢@suvayu-我使用1.7.9.5,我想那里没有这样的功能。。。谢谢你的建议,但这也需要手动复制粘贴文件名。。。不过,如果有人能想出一个处理旧行为的脚本,那就太好了。。再次感谢-干杯@SDAOU为什么说它需要文件名的复制粘贴?我认为只有顶级目录的路径就足够了,不需要所有路径。