簡體   English   中英

git添加所有跟蹤的文件-也在父目錄中

[英]git add all tracked files - also those in parent directory

可以說我有一個git根文件夾mine_git ,那里有一個子目錄subdir 所以我做了一些工作,我在subdirsubdir 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 add ed,而不是父/兄弟文件夾中的文件-即使這些文件被此git存儲庫跟蹤並以git status顯示!

然后我通常必須手動復制粘貼文件名,以便進行git add ../a-main-file.txt 顯然這很git status -uno -有沒有什么命令可以添加git status -uno列出的所有文件,而不管它們是否位於當前級別之下?

最新版本的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版本,因此無法測試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM