git 命令仅在文件夹中添加/暂存修改过的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3901099/
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-19 04:38:13  来源:igfitidea点击:

git command to add/stage modified files in folders only

gitdvcs

提问by lurscher

I've modified several files in a folder and subfolders. I could add the top folder recursively but then i have several subfolders that are untracked, so every time I do the recursive add to stage changes, I have to untrack the subfolders with git rm -r --cached. Is there a better way to just stage the modifications that show up in git status, without tracking already explicitly untracked files?

我修改了文件夹和子文件夹中的几个文件。我可以递归添加顶级文件夹,但是我有几个未跟踪的子文件夹,所以每次我对阶段更改进行递归添加时,我都必须使用git rm -r --cached. 有没有更好的方法来暂存显示在 git status 中的修改,而不跟踪已经明确未跟踪的文件?

meta-question: is it really a good idea that git addmeans two (or more) things? in this context, if the command to track files (git add) were not the same used for stage modifications (git add) then i would not have this problem in the first place

元问题:这真的是一个好主意,git add意味着两件事(或更多)吗?在这种情况下,如果跟踪文件的命令 ( git add) 与用于阶段修改 ( git add) 的命令不同,那么我首先不会遇到这个问题

回答by max

git add -uadds only modifications. Also consider adding files which you don't want to track to .gitignorefile.

git add -u仅添加修改。还可以考虑将您不想跟踪的.gitignore文件添加到文件中。

回答by Nigel

I think what you're looking for is

我想你要找的是

git commit -a

This will let you commit changes only.

这将让您只提交更改。