Git 添加所有已修改、删除和未跟踪的文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3498035/
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
Git add all files modified, deleted, and untracked?
提问by INSANENEIVIESIS
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.
有没有办法添加所有文件,无论您对它们做什么,是否删除、未跟踪等?就像提交一样。我只是不想每次提交时都必须git add
或git rm
我的所有文件,尤其是当我在处理大型产品时。
回答by Kilanash
Try:
尝试:
git add -A
Warning:Starting with git 2.0 (mid 2013), this will alwaysstage files on the whole working tree.
If you want to stage files under the current path of your working tree, you need to use:
警告:从 git 2.0(2013 年中)开始,这将始终在整个工作树上暂存文件。
如果要在工作树的当前路径下暂存文件,则需要使用:
git add -A .
Also see: Difference of git add -A
and git add .
回答by Matt Kneiser
Try
尝试
git add -u
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.
“ u
”选项代表更新。这将更新存储库并实际从存储库中删除您在本地副本中删除的文件。
git add -u [filename]
to stage a delete to just one file. Once pushed, the file will no longer be in the repo.
暂存删除到一个文件。推送后,该文件将不再位于 repo 中。
Alternatively,
或者,
git add -A .
git add -A .
is equivalent to
相当于
git add .
git add -u .
Note the extra '.' on git add -A
and git add -u
注意额外的“.” 在git add -A
和git add -u
Warning:Starting with git 2.0 (mid 2013), this will alwaysstage files on the whole working tree.
If you want to stage files under the current path of your working tree, you need to use:
警告:从 git 2.0(2013 年中)开始,这将始终在整个工作树上暂存文件。
如果要在工作树的当前路径下暂存文件,则需要使用:
git add -A .
Also see: Difference of git add -A
and git add .
回答by thebr0ken
The following answer only applies to Git version 1.x, but to Git version 2.x.
以下答案仅适用于 Git 1.x 版,但适用于 Git 2.x 版。
You want git add -A
:
你想要git add -A
:
git add -A
stages All;
git add -A
阶段全部;
git add .
stages new and modified, without deleted;
git add .
新的和修改的阶段,没有被删除;
git add -u
stages modified and deleted, without new.
git add -u
阶段修改和删除,没有新的。
回答by akshay_rahar
git add --all
orgit add -A
orgit add -A .
Stages All
git add --all
或git add -A
或git add -A .
阶段全部
git add .
Stages New & ModifiedBut Without Deleted
git add .
阶段新和修改,但不删除
git add -u
Stages Modified & DeletedBut Without New
git add -u
修改和删除但没有新的阶段
git commit -a
Means git add -u
And git commit -m "message"
git commit -a
手段git add -u
和git commit -m "message"
After writing this command follow these steps:-
编写此命令后,请按照下列步骤操作:-
- press i
- write your message
- press esc
- press :wq
- press enter
- 按 i
- 写下你的信息
- 按 esc
- 按 :wq
- 按 enter
git add <list of files>
add specific file
git add <list of files>
添加特定文件
git add *.txt
add all the txt files in current directory
git add *.txt
添加当前目录下的所有txt文件
git add docs/*/txt
add all txt files in docs directory
git add docs/*/txt
在 docs 目录中添加所有 txt 文件
git add docs/
add all files in docs directory
git add docs/
添加 docs 目录中的所有文件
git add "*.txt"
or git add '*.txt'
add all the files in the whole project
git add "*.txt"
或git add '*.txt'
添加整个项目中的所有文件
回答by bcherry
I'm not sure if it will add deleted files, but git add .
from the root will add all untracked files.
我不确定它是否会添加已删除的文件,但会git add .
从根目录添加所有未跟踪的文件。
回答by Olivier Refalo
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
我编写了 G2 项目,这是一个适合命令行 git 爱好者的友好环境。
请从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- 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
冻结- 将存储库中的所有文件(添加、删除、修改)冻结到暂存区,从而暂存该内容以包含在下一次提交中。还接受特定路径作为参数
回答by Giacomo Tesio
This is my alternative (in any bash):
这是我的选择(在任何 bash 中):
$ git status -s|awk '{ print }'|xargs git add
To reset
重置
$ git status -s|awk '{ print }'|xargs git reset HEAD
回答by Parag Tyagi -morpheus-
For newer versionof Git.
对于较新版本的 Git。
I tried git add -A
and this prompted,
我试过了git add -A
,这提示,
warning: The behavior of 'git add --all (or -A)' with no path argument from a subdirectory of the tree will change in Git 2.0 and should not be used anymore. To add content for the whole tree, run:
git add --all :/ (or git add -A :/)
To restrict the command to the current directory, run:
git add --all . (or git add -A .)
With the current Git version, the command is restricted to the current directory.
警告: 'git add --all (or -A)' 没有来自树的子目录的路径参数的行为将在 Git 2.0 中改变,不应再使用。要为整个树添加内容,请运行:
git add --all :/ (或 git add -A :/)
要将命令限制为当前目录,请运行:
git add --all 。(或 git add -A 。)
对于当前的 Git 版本,命令仅限于当前目录。
Then I tried below which worked.
然后我尝试了下面的工作。
git add --all :/
回答by HOKBONG
From Git documentation starting from version 2.0:
从版本 2.0 开始的 Git 文档:
To add content for the whole tree, run:
要为整个树添加内容,请运行:
git add --all :/
or
或者
git add -A :/
To restrict the command to the current directory, run:
要将命令限制为当前目录,请运行:
git add --all .
or
或者
git add -A .
回答by Maurizio Loreti
I use the following line to add for staging all the modified and newly created files, excluding the ones listed in .gitignore:
我使用以下行添加用于暂存所有已修改和新创建的文件,不包括 .gitignore 中列出的文件:
git add $(git ls-files -mo --exclude-standard)
(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:
(语法 $() 用于 bash shell)。我想命令行选项 -mod 还应该添加已删除的文件...或者,如果您的文件名带有嵌入的空格,则以下单行代码应该可以解决问题:
git ls-files -z --deleted --modified --others --exclude-standard | xargs -0 git add