git使用(二)----創建版本庫


創建版本庫(操作都是在linux環境下)

什么是版本庫呢?版本庫又名倉庫,英文名repository,其實就是一個目錄,可以進行增刪查改

創建一個目錄,這里在根目錄下創建一個git_home目錄
mkdir /git_home
cd git_home
git init

這樣就創建好了一個倉庫,當然目前是一個空倉庫

這個時候在當前目錄通過ls -a可以看到多了一個.git的目錄

 

把文件添加到版本庫

版本控制系統可以告訴你每次的改動,比如在第5行加了一個單詞“Linux”,在第8行刪了一個單詞“Windows”。而圖片、視頻這些二進制文件,雖然也能由版本控制系統管理,但沒法跟蹤文件的變化,只能把二進制文件每次改動串起來,也就是只知道圖片從100KB改成了120KB,但到底改了啥,版本控制系統不知道,也沒法知道。

我們在git_home目錄下創建一個文件,並填寫如下內容
git is a version control system
git is fee software

把文件放到git需要兩步:
1. git add 文件名
2. git commit -m "說明"

下面我們把readme.txt放到git,操作如下:

 1 [root@centos-linux git_home]# git add readme.txt
 2 [root@centos-linux git_home]# git commit -m "wrote a readme file"
 3 [master (root-commit) 8a044aa] wrote a readme file13 1 file changed, 2 insertions(+)
14 create mode 100644 readme.txt
15 [root@centos-linux git_home]#

第一步執行git add成功后是沒有任何提示的
第二步git commit命令中 -m 后面輸入的是本次提交的說明,一般輸入的對當前提交記錄的一個簡單說明,這樣在歷史記錄里查看的時候,就可以看到這個說明,從而知道每次提交的意義
並且這里需要知道git commit可以一次提交多個文件,也就是說你可以add 多次,但是只需要一次commit

 1     [root@centos-linux git_home]# touch file1.txt file2.txt file3.txt
 2     [root@centos-linux git_home]# ls
 3     file1.txt  file2.txt  file3.txt  readme.txt
 4     [root@centos-linux git_home]# git add file1.txt
 5     [root@centos-linux git_home]# git add file2.txt file3.txt
 6     [root@centos-linux git_home]# git status
 7     On branch master
 8     Changes to be committed:
 9       (use "git reset HEAD <file>..." to unstage)
10             new file:   file1.txt
11             new file:   file2.txt
12             new file:   file3.txt
13     [root@centos-linux git_home]# git commit -m "add 3 files"
14     [master 4d0b5e2] add 3 files
15      3 files changed, 0 insertions(+), 0 deletions(-)
16      create mode 100644 file1.txt
17      create mode 100644 file2.txt
18      create mode 100644 file3.txt
19     [root@centos-linux git_home]#

 

總結

 

上面一共有學了三個命令
初始化一個git倉庫:git init
添加文件到git倉庫:
1. git add 文件名
2. git commit -m "說明"

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM