一、Git的入門(mén)與基本使用(1)-創(chuàng)新互聯(lián)

基于蘇玲老師<玩轉(zhuǎn) Git 三劍客>視頻學(xué)習(xí)的一點(diǎn)總結(jié)?!獦O客時(shí)間

駐馬店網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、APP開(kāi)發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開(kāi)發(fā),運(yùn)營(yíng)維護(hù)。創(chuàng)新互聯(lián)于2013年成立到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專(zhuān)注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。

1、版本控制系統(tǒng)的演變
VCS 出現(xiàn)前
用目錄拷貝區(qū)別不同版本
公共文件容易被覆蓋
成員溝通成本很高,代碼集成效率低下
一、Git的入門(mén)與基本使用(1)
集中式 VCS
有集中的版本管理服務(wù)器?
具備文件版本管理理和分支管理理能力
集成效率有明顯地提高
客戶(hù)端必須時(shí)刻和服務(wù)?相連
一、Git的入門(mén)與基本使用(1)
分布式 VCS
服務(wù)端和客戶(hù)端都有完整的版本庫(kù)
脫離服務(wù)端,客戶(hù)端照樣可以管理理版本
查看歷史和版本比較等多數(shù)操作,都不需要訪問(wèn)服務(wù)器?,比集中式 VCS 更能提高版本管理理效率
一、Git的入門(mén)與基本使用(1)
Git的特點(diǎn)
最優(yōu)的存儲(chǔ)能力、非凡的性能、開(kāi)源的、很容易做備份、支持離線操作、很容易定制工作流程
2、安裝Git

Git官網(wǎng):https://git-scm.com/
參考文檔:https://git-scm.com/book/en/v2

3、最小配置
配置user.name和user.email

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

config 的三個(gè)作用域

$ git config --local       #local只對(duì)倉(cāng)庫(kù)有效,缺省等同于 local
$ git config --global     #global對(duì)登錄用戶(hù)所有倉(cāng)庫(kù)有效
$ git config --system   #system對(duì)系統(tǒng)的所有用戶(hù)有效

顯示 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

實(shí)例:

$ 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

4、創(chuàng)建第一個(gè)倉(cāng)庫(kù)
兩種方式:

  1. 用 Git 之前已經(jīng)有項(xiàng)目代碼
    $ git init
    $ cd 某個(gè)?文件夾
  2. 用 Git 之前還沒(méi)有項(xiàng)目代碼
    $ cd 項(xiàng)目代碼所在的文件夾
    $ git init your_project      #會(huì)在當(dāng)前路徑下創(chuàng)建和項(xiàng)目名稱(chēng)同名的文件夾
    $ cd your_project

實(shí)例

$ 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            #添加第一個(gè)文件

$ git status                             #顯示當(dāng)前git狀態(tài)
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            #添加到暫存區(qū)
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

5、通過(guò)幾次commit來(lái)認(rèn)識(shí)工作區(qū)和暫存區(qū)
在上面添加文件到暫存區(qū)時(shí),出現(xiàn)警告信息,是由于Git的換行符檢查功能。Windows使用回車(chē)和換行兩個(gè)字符來(lái)結(jié)束一行,而Mac和Linux只使用換行一個(gè)字符。Git可以在提交時(shí)自動(dòng)地把行結(jié)束符CRLF轉(zhuǎn)換成LF,而在讀取代碼時(shí)把LF轉(zhuǎn)換成CRLF。如果該項(xiàng)目?jī)H運(yùn)行在Windows上的項(xiàng)目,可以設(shè)置false取消此功能。

$ echo "second file" > second.txt       #創(chuàng)建幾個(gè)文件
$ echo "third file" > third.txt
$ echo "fourth file" > fourth.txt

$ git status                  #查看git當(dāng)前狀態(tài)
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     #添加第二個(gè)文件到暫存區(qū)
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    #關(guān)閉換行符檢查功能

$ 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"#提交第二個(gè)文件
[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"   #提交第三個(gè)文件
[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"   #提交第四個(gè)文件
[master 1d63ec8] Add fouth file
 1 file changed, 1 insertion(+)
 create mode 100644 fourth.txt

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

通過(guò)幾次提交文件,可以總結(jié)git工作區(qū)、暫存區(qū)與歷史版本之間的關(guān)系:
一、Git的入門(mén)與基本使用(1)

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。

網(wǎng)頁(yè)題目:一、Git的入門(mén)與基本使用(1)-創(chuàng)新互聯(lián)
分享地址:http://muchs.cn/article4/deejie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、做網(wǎng)站、企業(yè)網(wǎng)站制作自適應(yīng)網(wǎng)站、電子商務(wù)、品牌網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)