【问题标题】:git add all tracked files - also those in parent directorygit 添加所有跟踪的文件 - 也包括父目录中的文件
【发布时间】:2015-09-02 14:48:40
【问题描述】:

假设我有一个 git 根文件夹 mine_git,其中有一个子目录 subdir。所以我工作了一点,我在subdir - git status 列出了所有更改的文件:

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 added,而 不是 那些在父/兄弟文件夹中的文件 - 即使这些文件被这个 git 存储库跟踪,并显示在 @ 987654329@!

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

【问题讨论】:

  • git add -u 在这里工作正常
  • 谢谢@maggick - 正如下面的答案所指出的,它对我不起作用,因为我有一个旧版本的 git;干杯!

标签: git git-add


【解决方案1】:

最新版本的 git (2.4.3) 应该已经这样做了。来自man 1 git-add

   -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 -- ../relative/path/to/project/root 之类的方法。我手边没有旧的 git 版本,所以无法测试。

【讨论】:

  • 谢谢@suvayu - 我使用1.7.9.5,猜想那里没有这样的功能......也感谢您的建议,但这也需要手动复制粘贴文件名......将是不过,如果有人能想出一个处理旧行为的脚本,那就太好了。再次感谢 - 干杯!
  • @sdaau 为什么说它需要复制粘贴文件名?我认为只有顶级目录的路径就足够了,不需要所有路径。
猜你喜欢
  • 1970-01-01
  • 2018-01-28
  • 1970-01-01
  • 2017-01-16
  • 2011-03-30
  • 2017-12-30
  • 1970-01-01
  • 2011-04-08
  • 2016-12-19
相关资源
最近更新 更多