本文git為1.9.6版本:
10年積累的網(wǎng)站制作、做網(wǎng)站經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認識你,你也不認識我。但先制作網(wǎng)站后付款的網(wǎng)站建設(shè)流程,更有錫林郭勒盟免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
一、git全局配置
二、git初始化本地倉庫
三、git文件狀態(tài)詳解
四、git文件撤銷、恢復(fù)操作
git提交流程層次如下:
git repository 視為線上code集中管理服務(wù)器;也就是我們的code最后的位置;
git staging area 視為我們本地的code集中管理服務(wù)器,可認為code的中間的暫留區(qū)(以相對repository來說);
git working directory 視為我們本地編輯的code,也就是代碼編輯處;
1:全局配置
leo@LEO-PC /d/User/leo/Desktop/git (master) $ git config --global user.name "lansgg" leo@LEO-PC /d/User/leo/Desktop/git (master) $ git config --global user.email "[email protected]"
這里配置 --global選項其實就是在修改家目錄下的.getconfig文件
如我的:
C:\Users\leo\.getconfig
內(nèi)容:
[user] name = lansgg email = [email protected] [color] ui = true [core] autocrlf = true excludesfile = C:\\Users\\leo\\Documents\\gitignore_global.txt
當(dāng)我們修改此文件,比如將name=test (內(nèi)容已經(jīng)修改)
$ git config --get user.name
這里的用戶名及郵件地址都是在提交代碼的時候進行標識的,顯示提交人的信息;
2:初始化本地git倉庫
本地新建一個目錄;執(zhí)行g(shù)it init ;
$ mkdir git $ git init
執(zhí)行后的變化就是多了一個.git目錄;
leo@LEO-PC /d/User/leo/Desktop/git (master) $ ls -a .git . COMMIT_EDITMSG config hooks info objects .. HEAD description index logs refs leo@LEO-PC /d/User/leo/Desktop/git (master) $
.git 目錄,其中存放的是我們所提交的文檔索引內(nèi)容,Git 可基于文檔索引內(nèi)容對其所管理的文檔進行內(nèi)容追蹤,從而實現(xiàn)文檔的版本控制。.git目錄位于工作目錄內(nèi)。
index(索引):將工作目錄下所有文件(包含子目錄)生成快照,存放到一個臨時的存儲區(qū)域,Git 稱該區(qū)域為索引。
3、git文件狀態(tài)詳解
3.1、現(xiàn)在新建我們的code;
leo@LEO-PC /d/User/leo/Desktop/git (master) $ touch README.txt leo@LEO-PC /d/User/leo/Desktop/git (master) $ cat hello.rb puts "hello world!"
我們要將he.rb 、README 提交到本地git repository;
3.2、首先查看文件的狀態(tài)
$ git status
或
$ git status -s
根據(jù)輸出信息可以看出,README.txt hello.rb 兩個文件處于master branch(主分支),這兩個文件處于未追蹤文件,也就當(dāng)我們執(zhí)行g(shù)it commit(用于提交到圖中的倉庫)命令的時候不會將他們提交到git repository;
上圖 -s 表示簡要信息;( ?? )兩個問號也有很重要的意義;
第一個 ? 主要表示staging area 和 repository 兩個區(qū)域間的文件變化,一般會有兩個字母來表示(A、M <綠色>);A 表示此文件已經(jīng)是在追蹤文件,M 表示此文件已經(jīng)在staging area區(qū)域修改,還沒有提交到repository。
第二個 ? 主要表示working directory 和 staging area 兩個區(qū)域間的文件變化,M <紅色> 表示此文件已經(jīng)working directory區(qū)域修改,還沒有提交到staging area
下面開始演示:git add 表示將文件進行追蹤;
$ git add README.txt $ git add hello.rb
再次查看文件狀態(tài)
$ git status -s
可以看到兩個文件已經(jīng)處于 A 狀態(tài) (追蹤)現(xiàn)在這兩個文件處于staging area區(qū)域; changes to be committed 可以進行提交了;輸出信息提示,可以使用git reset HEAD <file> 將文件恢復(fù)于未追蹤狀態(tài);
恢復(fù)到已經(jīng)追蹤的狀態(tài),進行提交測試;
$ git commit -m "first commit" #-m 表示提交此代碼時進行描述;我們這里描述為“first commit”
可以看到wording directory clean 已經(jīng)將此兩個文件提交到repository;(從staging area區(qū)域),并查看文件狀態(tài)時,不在輸出任何東西
3.2 修改本地code,再查看文件狀態(tài)
$ echo 'puts "hello world!" '>> hello.rb
$ git status -s
第二個 ? 的地方出現(xiàn)了M <紅色> 表示此文件已經(jīng)在working directory區(qū)域修改;輸出信息提示,hello.rb文件已經(jīng)modified ; 命令 git add && git checkout && git commit -a (圖示都有) 下面講;
如何將此文件提交到repository
$ git add hello.rb $ git commit -m "second commit" hello.rb
或者使用:
$ git commit -a -m "second commit"
此命令將跳過git add 這一步~
4、撤銷、恢復(fù)
4.1、修改本地working directory 的code ;然后撤銷修改,也就說從staging area區(qū)域取出此code覆蓋當(dāng)前working directory的code;
測試如下:
$ echo 'puts "hello world!"' >> hello.rb #修改本地code $ git status -s #查看文件的狀態(tài),有差異 $ git checkout hello.rb #從staging area區(qū)域取出此code $ git status -s #再次查看該文件的狀態(tài),無差異,并且代碼恢復(fù)到了之前的代碼
4.2、修改本地working directory的code,并且進行追蹤(add 到 staging area區(qū)域);然后我們想撤銷本地code的修改,那我們可以從repository倉庫拉出此code覆蓋到staging area,然后再從staging area區(qū)域取出覆蓋到working directory區(qū)域;測試如下:
$ echo 'puts "hello world!"' >> hello.rb $ git status -s $ git add hello.rb $ git status -s $ git reset hello.rb $ git status -s $ git checkout hello.rb $ git status -s # 每一步都進行了文件狀態(tài)差異的核對;
我們也可以不用這么麻煩,可以直接從 repository 區(qū)域拉取出來直接覆蓋到 working directory 區(qū)域:
$ echo 'puts "hello world!"' >> hello.rb $ git status -s $ git add hello.rb $ git status -s $ git checkout HEAD hello.rb $ git status -s
可以看到已經(jīng)從git repository 拉取此文件并進行了覆蓋~
標題名稱:git全局配置及文件改變狀態(tài)詳解
路徑分享:http://m.2m8n56k.cn/article46/iesdeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、微信小程序、品牌網(wǎng)站制作、建站公司、響應(yīng)式網(wǎng)站、服務(wù)器托管
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)