Git 添加所有已修改、已删除和未跟踪的文件?
有没有一种方法可以添加所有文件,无论您对它们执行什么操作,无论是删除、取消跟踪等?就像提交一样。我只是不想每次提交时都必须 git add
或 git rm
所有文件,尤其是当我正在开发大型产品时。
Is there a way to add all files no matter what you do to them whether it be deleted, untracked, etc? like for a commit. I just don't want to have to git add
or git rm
all my files every time I commit, especially when I'm working on a large product.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
尝试:
警告:从 git 2.0(2013 年中)开始,这将始终在整个工作树上暂存文件。
如果你想将文件暂存到工作树的当前路径下,你需要使用:
另请参阅:
git add 的区别-A
和git add .
Try:
Warning: Starting with git 2.0 (mid 2013), this will always stage files on the whole working tree.
If you want to stage files under the current path of your working tree, you need to use:
Also see: Difference of
git add -A
andgit add .
尝试
“
u
”选项代表更新。这将更新存储库并实际从存储库中删除您已在本地副本中删除的文件。仅对一个文件进行删除。推送后,该文件将不再位于存储库中。
或者,
git add -A .
相当于
注意额外的“.”关于
git add -A
和git add -u
警告:从 git 2.0(2013 年中)开始,这将始终阶段文件。
如果你想将文件暂存到工作树的当前路径下,你需要使用:
另请参阅:
git add 的区别-A
和git add .
Try
The "
u
" option stands for update. This will update the repo and actually delete files from the repo that you have deleted in your local copy.to stage a delete to just one file. Once pushed, the file will no longer be in the repo.
Alternatively,
git add -A .
is equivalent to
Note the extra '.' on
git add -A
andgit add -u
Warning: Starting with git 2.0 (mid 2013), this will always stage files on the whole working tree.
If you want to stage files under the current path of your working tree, you need to use:
Also see: Difference of
git add -A
andgit add .
以下答案仅适用于 Git 版本 1.x,但适用于 Git 版本 2.x。
您需要 git add -A :
git add -A 阶段全部;
git add .
阶段新建和修改,不删除;git add -u
阶段已修改和删除,没有新的。The following answer only applies to Git version 1.x, but to Git version 2.x.
You want
git add -A
:git add -A
stages All;git add .
stages new and modified, without deleted;git add -u
stages modified and deleted, without new.git add --all
或git add -A
或git add -A .
> 全部阶段git add .
新建阶段和阶段已修改但未删除git add -u
阶段已修改&已删除但没有新的git commit -a
意味着git add -u
和git commit -m "message"
编写此命令后,请按照下列步骤操作:-
git add <文件列表>
添加特定文件git add *.txt
添加当前目录下的所有txt文件git add docs/*/txt
添加docs目录下的所有txt文件git add docs/
添加docs目录下的所有文件git add "*.txt"
或git add '*.txt'
添加整个项目中的所有文件git add --all
orgit add -A
orgit add -A .
Stages Allgit add .
Stages New & Modified But Without Deletedgit add -u
Stages Modified & Deleted But Without Newgit commit -a
Meansgit add -u
Andgit commit -m "message"
After writing this command follow these steps:-
git add <list of files>
add specific filegit add *.txt
add all the txt files in current directorygit add docs/*/txt
add all txt files in docs directorygit add docs/
add all files in docs directorygit add "*.txt"
orgit add '*.txt'
add all the files in the whole project我不确定它是否会添加已删除的文件,但是根目录中的 git add . 将添加所有未跟踪的文件。
I'm not sure if it will add deleted files, but
git add .
from the root will add all untracked files.对于 Git 的新版本。
我尝试了 git add -A 并提示,
然后我尝试了下面的方法有效。
For newer version of Git.
I tried
git add -A
and this prompted,Then I tried below which worked.
这是我的替代方案(在任何bash中):
重置
This is my alternative (in any bash):
To reset
我编写了 G2 项目,一个对命令行 git 爱好者来说友好的环境。
请从 github 获取该项目 - G2 https://github.com/orefalo/g2
它有一堆方便的命令,其中之一正是您正在寻找的:
freeze
freeze - 将存储库中的所有文件(添加、删除、修改)冻结到暂存区域,从而暂存该内容以包含在下一次提交中。还接受特定路径作为参数
I authored the G2 project, a friendly environment for the command line git lover.
Please get the project from github - G2 https://github.com/orefalo/g2
It has a bunch of handy commands, one of them being exactly what your are looking for:
freeze
freeze - Freeze all files in the repository (additions, deletions, modifications) to the staging area, thus staging that content for inclusion in the next commit. Also accept a specific path as parameter
我使用以下行来添加暂存所有已修改和新创建的文件,不包括 .gitignore 中列出的文件:(
语法 $() 用于 bash shell)。我猜想命令行选项 -mod 还应该添加已删除的文件...或者,如果您的文件名中嵌入了空格,则以下一行应该可以解决问题:
I use the following line to add for staging all the modified and newly created files, excluding the ones listed in .gitignore:
(the syntax $() is for the bash shell). I guess that the command line option -mod should add also the deleted files... Or, if you have file names with embedded blanks, the following one-liner should do the trick:
从版本 2.0 开始的 Git 文档:
要为整个树添加内容,请运行:
或
要将命令限制为当前目录,请运行:
或
From Git documentation starting from version 2.0:
To add content for the whole tree, run:
or
To restrict the command to the current directory, run:
or