下面我们就来讨论一下文件的修改和提交,其实git 跟踪的非文件而是文件的修改,新增文件、删除文件、文件增加或删除行都是属于文件的修改
现在我们先来编辑一个文件
vim test.txt
然后随便添加一些内容
bogon:lishuangshuang shuang$ vim test.txt
bogon:lishuangshuang shuang$ cat test.txt
ceshi wenjian
然后我们通过git status
查看一下文件的状态
bogon:lishuangshuang shuang$ 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: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
然后,添加:
$ git add readme.txt
提交后,用 git diff HEAD -- test.txt
命令可以查看工作区和版本库里面最新版本的区别
bogon:lishuangshuang shuang$ git diff HEAD -- test.txt
diff --git a/test.txt b/test.txt
index 58c9bdf..f28a8ac 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1 @@
-111
+ceshi wenjian
现在可以提交了
$ git commit -m "git tracks changes"[master d4f25b6] git tracks changes 1 file changed, 1 insertion(+)
提交后,再看看状态:
bogon:lishuangshuang shuang$ 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: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
** Git管理的是修改,当你用git add命令后,是将修改被放入暂存区,准备提交,执行git commit是负责把暂存区的修改提交了**
最后我们可以 通过git push
把我们得修改提交到 远程版本库
也就是说我们从修改文件到提交到远程分支 需要git add
git commit
git push
三个操作