简体   繁体   English

Git 添加所有修改、删除和未跟踪的文件?

[英]Git add all files modified, deleted, and untracked?

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 addgit rm我的所有文件,尤其是当我在处理大型产品时。

Try:尝试:

git add -A

Warning: Starting with git 2.0 (mid 2013), this will always stage files on the whole working tree .警告:从 git 2.0(2013 年中)开始,这将始终在整个工作树上暂存文件。
If you want to stage files under the current path of your working tree, you need to use:如果要在工作树的当前路径下暂存文件,则需要使用:

git add -A .

Also see: Difference of git add -A and git add.另请参阅: git add -Agit add.

Try尝试

git add -u

The " u " option stands for update. u ”选项代表更新。 This will update the repo and actually delete files from the repo that you have deleted in your local copy.这将更新存储库并实际从存储库中删除您在本地副本中删除的文件。

git add -u [filename]

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相当于

git add .

git add -u .

Note the extra '.'注意额外的“。” on git add -A and git add -ugit add -Agit add -u


Warning: Starting with git 2.0 (mid 2013), this will always stage files on the whole working tree .警告:从 git 2.0(2013 年中)开始,这将始终在整个工作树上暂存文件。
If you want to stage files under the current path of your working tree, you need to use:如果要在工作树的当前路径下暂存文件,则需要使用:

git add -A .

Also see: Difference of git add -A and git add.另请参阅: git add -Agit add.

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 -u stages modified and deleted, without new. git add -u阶段修改和删除,没有新的。

git add --all or git add -A or git add -A. git add --allgit add -Agit add -A. Stages All所有阶段

git add. Stages New & Modified But Without Deleted阶段新的和修改没有删除

git add -u Stages Modified & Deleted But Without New git add -u阶段修改和删除没有新的

git commit -a Means git add -u And git commit -m "message" git commit -a表示git add -ugit commit -m "message"

After writing this command follow these steps:-编写此命令后,请按照下列步骤操作:-

  1. press i
  2. write your message写下你的信息
  3. press escesc
  4. press : w q: w q
  5. press 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'添加整个项目中的所有文件

I'm not sure if it will add deleted files, but git add.我不确定它是否会添加已删除的文件,但是git add. from the root will add all untracked files.从根目录将添加所有未跟踪的文件。

For newer version of 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.警告:'git add --all(或 -A)' 没有来自树的子目录的路径参数的行为将在 Git 2.0 中发生变化,不应再使用。 To add content for the whole tree, run:要为整棵树添加内容,请运行:

git add --all:/ (or git add -A:/) git add --all:/(或 git add -A:/)

To restrict the command to the current directory, run:要将命令限制在当前目录,请运行:

git add --all. git 添加——全部。 (or git add -A.) (或 git add -A。)

With the current Git version, the command is restricted to the current directory.在当前的 Git 版本中,该命令仅限于当前目录。


Then I tried below which worked .然后我尝试了下面的工作

git add --all :/

I authored the G2 project, a friendly environment for the command line git lover.我编写了 G2 项目,这是命令行 git 爱好者的友好环境。
Please get the project from github - G2 https://github.com/orefalo/g2请从 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. freeze - 将存储库中的所有文件(添加、删除、修改)冻结到暂存区,从而暂存该内容以包含在下一次提交中。 Also accept a specific path as parameter还接受特定路径作为参数

This is my alternative (in any bash):这是我的替代方案(在任何 bash 中):

$ git status -s|awk '{ print $2 }'|xargs git add

To reset重置

$ git status -s|awk '{ print $2 }'|xargs git reset HEAD

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). (语法 $() 适用于 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:我想命令行选项 -mod 也应该添加已删除的文件...或者,如果您的文件名中嵌入了空格,则以下单行代码应该可以解决问题:

git ls-files -z --deleted --modified --others --exclude-standard | xargs -0 git add

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 .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM