$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: file1
# modified: file2
# modified: file3
#
no changes added to commit (use "git add" and/or "git commit -a")
添加file1到file2索引:
$ git add file1 file2
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: file1
# modified: file2
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: file3
#
做出承诺:
$ git commit -m 'добавили изменения в file1 и file2'
...
$ git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: file3
#
no changes added to commit (use "git add" and/or "git commit -a")
将文件添加到索引(也称为stage、stage area或cache)然后提交。
现在修改了三个文件:
添加
file1到file2索引:做出承诺:
现在我们可以对文件继续相同的 (
add+commit)file3。Git 允许您非常灵活地提交。您甚至可以提交“文件的一半”。
首先,我们编写
git add -i并进入将文件添加到提交的交互模式。会输出这样的东西
选择 5(或 p)并按回车键。接下来,git 将显示一个文件列表,通过输入它们的编号,您可以选择那些将被“添加”的文件。最后按回车。
之后,一种特殊模式将打开,您将看到一个小变化(它们被称为大块或大块)。对于这些更改中的每一个,您可以立即添加 (y) 或拒绝 (n) 或要求 git 拆分成更小的部分 (s)
成功通过所有棋子后,退出(q)即可。
现在我们需要看看将提交什么。git status 并将在这里提供帮助
git diff --staged(它只会显示提交中的内容)。如果一切正常,那么你就可以执行
git commit -m "text"并提交了。此外,重复此过程,直到获得所需的提交数量和质量。
用俄语阅读更多相关信息
这种方法非常方便,因为它允许您不提交一些您不想删除的临时代码(例如,出于调试目的)。
要提交多个文件,您需要列出它们的名称:
git commit file1.txt file2.txt file3.txt一些文件是这样添加的:
可能通过面具:
git add .- 添加所有文件,git add m*- 将添加以 . 开头的所有文件m。