添加⽂件--场景⼆
添加⽂件–场景⼆
学习到这⾥,我们已经清楚了如何向仓库中添加⽂件,并且对于⼯作区、暂存区、版本库也有了⼀定的认识。那么我们再展⽰⼀种添加⽂件的场景,能加深对⼯作区、暂存区、版本库的理解,⽰例如下:
root@hcss-ecs-a74f:~/gitcode# la
file1 file2 file3 .git ReadMe
root@hcss-ecs-a74f:~/gitcode# touch file4 #1. 新增file4⽂件
root@hcss-ecs-a74f:~/gitcode# git add file4 #2. 将file4添加到暂存区
root@hcss-ecs-a74f:~/gitcode# touch file5 #3. 新增file5⽂件
root@hcss-ecs-a74f:~/gitcode# git commit -m "add file" #4. 提交修改
[master 0bba9d8] add file1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 file4
提交后发现打印了 1 file changed, 0 insertions(+), 0 deletions(-) ,意思是只有⼀个⽂件改变了,这时我们提出了疑问,不是新增了两个⽂件吗?
再来回忆下, git add 是将⽂件添加到暂存区, git commit 是将暂存区的内容添加到本地仓库中。由于我们并没有使⽤ git add file5 ,file5 就不在暂存区中维护,所以我们 commit 的时候其实只是把已经在暂存区的 file4 提交了,⽽遗漏了⼯作区的 file5。如何提交 file5 呢?很简单,再次add , commit 即可。