如何使用 repo 子目录暂存 git 中的所有更改

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9457753/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:03:12  来源:igfitidea点击:

How to stage all changes in git from with a repo subdirectory

git

提问by Shaun Dychko

So the command to stage all changes for git is git add -A.

因此,为 git 暂存所有更改的命令是git add -A.

Is there a way to execute this from within a repository subdirectory, and capture all changes anywhere in the repo, without having change the directory back to the repo root?

有没有办法从存储库子目录中执行此操作,并捕获存储库中任何位置的所有更改,而无需将目录更改回存储库根目录?

Example:

例子:

$pwd
/reporoot/

modify the file: /reporoot/a-file

修改文件:/reporoot/a-file

$cd /a-subdir

$git 'magic variation of add -A which I'm looking for'

and the change to /reporoot/a-file will be staged.

并且将暂存对 /reporoot/a-file 的更改。

I find that I'm often in one place in the terminal, but editing a file somewhere else with the IDE, so the answer to this question would be a helpful way for avoiding lots of cd'ing.

我发现我经常在终端的一个地方,但在其他地方用 IDE 编辑文件,所以这个问题的答案将是避免大量 cd'ing 的有用方法。

回答by Andrew Marshall

Use the following (only works in newer versions of Git):

使用以下内容(仅适用于较新版本的 Git):

git add $(git rev-parse --show-toplevel)

You may wish to create a Git aliasfor this to make running it easier.

您可能希望为此创建一个 Git 别名以使其更容易运行。

Note that, if you plan on committing, doing the following will stage all changed files already in the working tree (i.e., not untracked files):

请注意,如果您计划提交,执行以下操作将暂存工作树中已有的所有更改文件(即,不是未跟踪的文件):

git commit -a

回答by Echsecutor

You are looking for git add -u, see the nice explanation here Difference between "git add -A" and "git add ."or the manual http://git-scm.com/docs/git-add. If you are going to commit next anyway, use git commit -aas mentioned by Andrew.

你正在寻找 git add -u,在这里看到很好的解释 “git add -A”和“git add”之间的区别。或手册 http://git-scm.com/docs/git-add。如果您仍然要提交下一步,请使用git commit -aAndrew 提到的方法。