一、创建版本库
//创建文件夹
$ mkdir intco
//到当前目录
$ cd intco
//显示当前目录
$ pwd
/intco/project
//将此目录变成Git可以管理的仓库
$ git init
Initialized empty Git repository in D:/Code/Git/intco/project/.git/
在intco文件夹下创建readme.txt文件,内容为:
Git is a version control system.
Git is free software.
//使用git add,把文件添加到仓库
$ git add readme.txt
//使用git commit把文件提交给仓库,
$ git commit -m "Add two rows"
[master 7e5b09e] Add two rows
1 file changed, 2 insertions(+), 1 deletions(-)
Git添加文件需要add、commit两步操作,由于commit可以一次提交很多文件,所以可以多次add不同的文件。
$ git add file1.txt
$ git add file2.txt file3.txt
$ git commit -m "add 3 files."
二、操作流程
//查看当前仓库的状态
$ git status
//查看具体修改的内容
$ git diff readme.txt
diff --git a/readme.txt b/readme.txt
index d8976ef..013b5bc 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,8 +1,2 @@
-Git is a version control system.
-Git is free software.
-111
-2222
-333
-22
-33
-22
\ No newline at end of file
+Git is a distributed version control system.
+Git is free software.
//先提交文件
$ git add readme.txt
//查看变更
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: readme.txt
//最后提交变更
$ git commit -m "add distributed"
[master c316fa3] add distributed
1 file changed, 2 insertions(+), 8 deletions(-)
//查看状态
$ git status
On branch master
nothing to commit, working tree clean