建立一個文件夾用做本地Git倉庫(repository)git
$ mkdir repository
cd到該目錄,初始化該目錄,以後可用Git管理json
$ cd repository $ git init
在該目錄可用 ls -ah看到隱藏的文件夾.git ,該文件夾用於管理倉庫3d
在repository的本地目錄或子目錄下,加入hello.jsoncode
$ git add hello.json
此時已經將文件添加到了暫存區,再用git commit命令提交it
$ git commit -m "add hello.json" [master (root-commit) 2743d73] add hello.json 1 file changed, 1 insertion(+) create mode 100644 hello.json
其中,commit時須要添加commit信息,指令爲io
git commit -m "要添加的信息"
一般,要添加的信息爲本次提交作了些什麼ast
當hello.json被更改時,能夠用 git status查看更改概要date
$ 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: hello.json
可見hello.json已經被修改,而要查看修改詳情,使用 git diff便可file
$ git diff hello.json diff --git a/hello.json b/hello.json index 2889c67..0261296 100644 --- a/hello.json +++ b/hello.json @@ -1 +1,2 @@ -Hello,world! \ No newline at end of file +Hello,world! +add a line \ No newline at end of file
再次提交更改過的hello.json,並查看狀態di
git add hello.json