git基本操作二-創建一個提交

創建一個提交通常會有兩個操作,git add 和 git commit

另外,通常還有附加兩個操作會用到 git status 和 git log。下面分別介紹。

先創建一個普通文本文件 a.txt。

z@ubuntu:~/gitdemos
$ echo hello > a.txt

git status

status 命令用於查看當前git倉庫的狀態。

git status提示有一個未跟蹤的文件 a.txt (默認情況下 git status 會將未跟蹤的文件標記爲紅色)

Untracked files: (use "git add <file>..." to include in what will be committed)

仔細讀一下這句話,可以看出來在倉庫裏的文件有三種狀態。

- Untracted files  未被跟蹤的文件

- Files which will be commited  將被提交的文件

- Commited files 已提交的文件

git倉庫中的文件的三個狀態之間的流轉正是今天要介紹的兩個命令 git add 和 git commit

git add

先用 git add 將文件從 Untracted   狀態變爲  will be commited 

git add a.txt

再用 git status 觀察一下 a.txt的狀態。現在a.txt  變成了 to be commited了。

(默認情況下 git status 會將 to be commited 的文件標記爲綠色)

接下來試一下將文件變爲 commited的狀態。

git commit

git commit -m "add a.txt" 

-m "add a.txt"    -m 之後的字符串是這個提交的標題。

是的,提交有各種屬性,比如標題,正文,時間,提交人員等等。

可以用 git log 來觀察提交的屬性,及所有提交歷史。

git log

 

最後說明一下常見的 工作區,暫存區,版本庫的概念:

通過 man git add  可以看到如下描述

DESCRIPTION
       This command updates the index using the current content found in the working tree, to
       prepare the content staged for the next commit

Untracted files 的集合被稱爲 working tree ,通常被翻譯爲 工作區

Files which will be commited  的集合被稱爲 index,通常被翻譯爲  暫存區

Commited files 已提交的文件的集合通常被稱爲版本庫

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章