我有一个存储库,其中有两个文件:file1.txt 和 file2.txt
当我调用 git status 时,我得到以下信息:
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: file2.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# file3.txt
因此,如果我想提交 file2.txt 更改和 file3.txt 我可以执行以下操作:
git add file2.txt
git add file3.txt
git commit
这将同时提交新文件和对 file2.txt 所做的更改
如果但是,我使用 git commit -a 仅提交 file2.txt 更改,而新文件 (file3.txt) 将被忽略。
因此,为了获得相同的效果,我也可以这样做:
git add file3.txt
git commit -a
在这种情况下,我不必添加更改的文件,因为提交的 -a 选项将处理该问题。
注意:如果您在没有“暂存”任何文件的情况下调用 git commit,则不会发生任何事情。
There are two parts to the git committing process. First you "stage" individual files and then you do the "commit" command which actually adds the "staged" files to the repository. So if you want to "stage" files you first will use the "git add" command:
git add myfile1
You can do that for as many files as you like. When you call "git status" you should see list of the staged files. You can "add" files that are already in your repository but have changes, and you can also "add" files that aren't yet in your repository. New files will come up as new in the staged area and other ones will just come up as modified, but when you finally call "git commit", you will commit everything that is staged. The "-a" option to git commit means automatically stage all modified files, and also commit them (Note: this does not include files that are not already in the repository ).
Here is an example:
I have a repository where I have two files: file1.txt and file2.txt
When I call git status I get the following:
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: file2.txt
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# file3.txt
So if I want to commit both file2.txt changes, and file3.txt I can do the following:
git add file2.txt
git add file3.txt
git commit
That will commit both the new file and the changes made to file2.txt
If however, I used git commit -a only file2.txt changes would have been commited and the new file (file3.txt) would have been ignored.
So to get the same effect, I could also do:
git add file3.txt
git commit -a
In this case I don't have to add the changed file because the -a option to commit will take care of that.
Note: If you call git commit without any files "staged", nothing will happen.
发布评论
评论(1)
git 提交过程分为两个部分。首先,“暂存”单个文件,然后执行“提交”命令,该命令实际上将“暂存”文件添加到存储库中。因此,如果您想“暂存”文件,您首先将使用“git add”命令:
您可以对任意数量的文件执行此操作。当您调用“git status”时,您应该看到暂存文件的列表。您可以“添加”存储库中已存在但已更改的文件,也可以“添加”存储库中尚未存在的文件。新文件将在暂存区域中作为新文件出现,而其他文件将按修改后的状态出现,但是当您最终调用“git commit”时,您将提交暂存的所有内容。 git commit 的“-a”选项意味着自动暂存所有修改的文件,并提交它们(注意:这不包括存储库中尚未存在的文件)。
这是一个示例:
我有一个存储库,其中有两个文件:file1.txt 和 file2.txt
当我调用 git status 时,我得到以下信息:
因此,如果我想提交 file2.txt 更改和 file3.txt 我可以执行以下操作:
这将同时提交新文件和对 file2.txt 所做的更改
如果但是,我使用 git commit -a 仅提交 file2.txt 更改,而新文件 (file3.txt) 将被忽略。
因此,为了获得相同的效果,我也可以这样做:
在这种情况下,我不必添加更改的文件,因为提交的 -a 选项将处理该问题。
注意:如果您在没有“暂存”任何文件的情况下调用 git commit,则不会发生任何事情。
There are two parts to the git committing process. First you "stage" individual files and then you do the "commit" command which actually adds the "staged" files to the repository. So if you want to "stage" files you first will use the "git add" command:
You can do that for as many files as you like. When you call "git status" you should see list of the staged files. You can "add" files that are already in your repository but have changes, and you can also "add" files that aren't yet in your repository. New files will come up as new in the staged area and other ones will just come up as modified, but when you finally call "git commit", you will commit everything that is staged. The "-a" option to git commit means automatically stage all modified files, and also commit them (Note: this does not include files that are not already in the repository ).
Here is an example:
I have a repository where I have two files: file1.txt and file2.txt
When I call git status I get the following:
So if I want to commit both file2.txt changes, and file3.txt I can do the following:
That will commit both the new file and the changes made to file2.txt
If however, I used git commit -a only file2.txt changes would have been commited and the new file (file3.txt) would have been ignored.
So to get the same effect, I could also do:
In this case I don't have to add the changed file because the -a option to commit will take care of that.
Note: If you call git commit without any files "staged", nothing will happen.