1、Git的入門與基本使用(1)

 基於蘇玲老師<玩轉 Git 三劍客>視頻學習的一點總結。——極客時間git

一、版本控制系統的演變
 VCS 出現前
  用目錄拷貝區別不同版本
  公共文件容易被覆蓋
  成員溝通成本很高,代碼集成效率低下
1、Git的入門與基本使用(1)
 集中式 VCS
  有集中的版本管理服務器器
  具有文件版本管理理和分支管理理能力
  集成效率有明顯地提升
  客戶端必須時刻和服務器相連
1、Git的入門與基本使用(1)
 分佈式 VCS
  服務端和客戶端都有完整的版本庫
  脫離服務端,客戶端照樣能夠管理理版本
  查看歷史和版本比較等多數操做,都不須要訪問服務器器,比集中式 VCS 更能提升版本管理理效率
1、Git的入門與基本使用(1)
 Git的特色
  最優的存儲能力、非凡的性能、開源的、很容易作備份、支持離線操做、很容易定製工做流程
二、安裝Git服務器

Git官網:https://git-scm.com/
參考文檔:https://git-scm.com/book/en/v2dom

三、最小配置
配置user.name和user.email分佈式

$ git config --global user.name ‘your_name’
$ git config --global user.email ‘your_email@domain.com’

config 的三個做用域ide

$ git config --local       #local只對倉庫有效,缺省等同於 local
$ git config --global     #global對登陸用戶全部倉庫有效
$ git config --system   #system對系統的全部用戶有效

顯示 config 的配置,加 --list性能

$ git config --list --local
$ git config --list --global
$ git config --list --system

清除,--unset學習

$ git config --unset --local user.name
$ git config --unset --global user.name
$ git config --unset --system user.name

實例:3d

$ git config  --global user.name "Jone"
$ git config  --global user.email "764651475@qq.com"
$ git config  --global --list
sendpack.sideband=false
user.name=Jone
user.email=764651475@qq.com

四、建立第一個倉庫
兩種方式:版本控制

  1. 用 Git 以前已經有項目代碼
    $ git init
    $ cd 某個⽂文件夾
  2. 用 Git 以前尚未項目代碼
    $ cd 項目代碼所在的文件夾
    $ git init your_project      #會在當前路徑下建立和項目名稱同名的文件夾
    $ cd your_project

實例code

$ git init git_learning
Initialized empty Git repository in D:/git_learning/.git/
$ cd git_learning/
$ git status
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

$ echo "hello world!" > first.txt            #添加第一個文件

$ git status                             #顯示當前git狀態
On branch master
No commits yet
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        first.txt
nothing added to commit but untracked files present (use "git add" to track)

$ git add first.txt            #添加到暫存區
warning: LF will be replaced by CRLF in first.txt.
The file will have its original line endings in your working directory.

$ git commit -m"Add first file"    #提交
[master (root-commit) c8588e4] Add first file
 1 file changed, 1 insertion(+)
 create mode 100644 first.txt

$ git status
On branch master
nothing to commit, working tree clean

五、經過幾回commit來認識工做區和暫存區
 在上面添加文件到暫存區時,出現警告信息,是因爲Git的換行符檢查功能。Windows使用回車和換行兩個字符來結束一行,而Mac和Linux只使用換行一個字符。Git能夠在提交時自動地把行結束符CRLF轉換成LF,而在讀取代碼時把LF轉換成CRLF。若是該項目僅運行在Windows上的項目,能夠設置false取消此功能。

$ echo "second file" > second.txt       #建立幾個文件
$ echo "third file" > third.txt
$ echo "fourth file" > fourth.txt

$ git status                  #查看git當前狀態
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        fourth.txt
        second.txt
        third.txt

nothing added to commit but untracked files present (use "git add" to track)

$ git add second.txt     #添加第二個文件到暫存區
warning: LF will be replaced by CRLF in second.txt.
The file will have its original line endings in your working directory.

$ git config --global core.autocrlf false    #關閉換行符檢查功能

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   second.txt

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

        fourth.txt
        third.txt

$ git commit -m"Add second file"#提交第二個文件
[master 0bd98cb] Add second file
 1 file changed, 1 insertion(+)
 create mode 100644 second.txt

$ git log
commit 0bd98cb5d0d969cfc35d8c5a16d33b5924cbc6b0 (HEAD -> master)
Author: Jone <764651475@qq.com>
Date:   Thu Mar 14 16:59:25 2019 +0800

    Add second file

commit c8588e43dd1053684632871fb8aec1945ee6a6ab
Author: Jone <764651475@qq.com>
Date:   Thu Mar 14 16:36:00 2019 +0800

    Add first file

$ git add third.txt
$ git commit -m"Add third file"   #提交第三個文件
[master b843c28] Add third file
 1 file changed, 1 insertion(+)
 create mode 100644 third.txt

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

        fourth.txt

nothing added to commit but untracked files present (use "git add" to track)

$ git add fourth.txt
$ git commit -m"Add fouth file"   #提交第四個文件
[master 1d63ec8] Add fouth file
 1 file changed, 1 insertion(+)
 create mode 100644 fourth.txt

$ echo "Update the file" >> fourth.txt   #修改第四個文件
$ 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:   fourth.txt

no changes added to commit (use "git add" and/or "git commit -a")

$ git add fourth.txt
$ git commit -m"Update fourth file"     #提交修改後的文件
[master 7376bc5] Update fourth file
 1 file changed, 1 insertion(+)

$ git log
commit 7376bc5b2ebc3e13d4c4552ebdef348a17cd4eef (HEAD -> master)
Author: Jone <764651475@qq.com>
Date:   Thu Mar 14 17:03:07 2019 +0800

    Update fourth file

commit 1d63ec82259b237f58e7525ccf856a03fb880fcd
Author: Jone <764651475@qq.com>
Date:   Thu Mar 14 17:01:46 2019 +0800

    Add fouth file

commit b843c287804d2b5886167740f9e6c0d327540ee1
Author: Jone <764651475@qq.com>
Date:   Thu Mar 14 17:00:21 2019 +0800

    Add third file

commit 0bd98cb5d0d969cfc35d8c5a16d33b5924cbc6b0
Author: Jone <764651475@qq.com>
Date:   Thu Mar 14 16:59:25 2019 +0800

    Add second file
...

經過幾回提交文件,能夠總結git工做區、暫存區與歷史版本之間的關係:
1、Git的入門與基本使用(1)

相關文章
相關標籤/搜索