天天看點

005_git專題

一、倉庫管理

➜ gittest git:(master) git config --local user.name "arunguang"
➜ gittest git:(master) git config --local user.email "[email protected]"

➜ gittest git:(master) git config --local --list
user.name=arunguang
[email protected]

--global < --local(local優先級最高)
      

  

005_git專題

解釋及實操:

(1)
git add readme.md    #把該檔案放入git暫存區,通過git管理起來.
git add -u                  #all tracked files in the entire working tree are updated,即把所有已經加到暫存區的檔案的更新一塊添加更新

git reset --hard  #清理掉自commit以後暫存區的所有改變(非常危險)
--hard   Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.
(2)變更檔案名
git mv readme.md README.md  
(3)git log詳解
git log                        #git log後面不加任何分支,預設是檢視目前分支的修改曆史
git log --all                 #檢視所有分支的修改曆史
git log --oneline          #以簡短的方式檢視git送出的曆史記錄
git log -n 2                 #限制顯示檢視git log送出曆史記錄的最近幾條
(3)分支管理
git checkout -b temp c6d9fd798e3cb652bd2977663b9e7fcc391b711a   #基于git log的某個點建立分支
git commit -am"second"  #-a, --all  Tell the command to automatically stage files that have been modified and deleted
git log --all --graph --oneline       #以圖形化的方式檢視更改曆史
* fe6b335 (HEAD -> temp) second
| * 3538299 (master) mv readme to README.md
|/
* c6d9fd7  On branch master  Changes to be committed:   modified:   readme.md
* 621445a xxx1
(4)檢視幫助
git help -web log                         #以網頁方式檢視幫助
(5)gitk                        #圖形管理工具      

二、.git目錄解密

(1)
➜  .git git:(temp) cat HEAD
ref: refs/heads/temp                               #指向目前的所在分支
cat .git/config
[core]
	repositoryformatversion = 0
....
[user]
	name = arun6688                           #更改git的user.name的配置
	email = [email protected]
➜  gittest git:(master) git config --local user.name      #再次檢視已經更改了
arun6688
➜  gittest git:(master) git config --local user.name 'arunold'      #再次檢視config檔案也已經更改了
(2).git/refs/ 目錄
➜  heads git:(master) cat master
3538299062b25ce5e36e9467d0c204837f273fcb
➜  heads git:(master) cat temp
fe6b335bcca87443dd907668bd2ce388f14eddc2
➜  heads git:(master) git cat-file -t 3538299062b25ce5e36e9467d0c204837f273fcb  #-t檢視對象指令
commit
➜  heads git:(master) git cat-file -t fe6b335bcca87443dd907668bd2ce388f14eddc2
commit
➜  heads git:(master) git branch -av
* master 3538299 mv readme to README.md
  temp   fe6b335 second
➜  tags git:(master) git cat-file -p 293406d5c363001f169321e3008053c445e1b521  #-p檢視對象内容
object 3538299062b25ce5e36e9467d0c204837f273fcb
type commit
tag test1.0
tagger arunold <[email protected]> 1544517262 +0800

this is tag test
(2)
➜  35 git:(master) pwd
.git/objects/35
➜  35 git:(master) ls
38299062b25ce5e36e9467d0c204837f273fcb
➜  35 git:(master) git cat-file -t 3538299062b25ce5e36e9467d0c204837f273fcb  #目錄+檔案名即是git對象的hash值
commit
➜  35 git:(master) git cat-file -p 3538299062b25ce5e36e9467d0c204837f273fcb
tree 9a522cb3bad21d631a84b9264ffb315602fbb079
parent c6d9fd798e3cb652bd2977663b9e7fcc391b711a
author arunguang <[email protected]> 1544512480 +0800
committer arunguang <[email protected]> 1544512480 +0800

mv readme to README.md
      

三、commit tree  blob是git中主要的對象

005_git專題

tree對應的是檔案夾.

四、常見的企業中使用的git寫作方式

https://en.wikipedia.org/wiki/Rolling_release

https://www.git-tower.com/learn/git/ebook/cn/command-line/advanced-topics/git-flow

常用:https://guides.github.com/introduction/flow/

------------------------------------------------------------------------

一、檔案管理

(1)git恢複删除檔案

➜  git:(master) ✗ git ls-files --deleted
camel-agent-deploy-update.sh
➜  git:(master) ✗ git checkout -- camel-agent-deploy-update.sh
➜  git:(master) ls    #看到已經恢複了
camel-agent-deploy-update.sh
           

(2)

git log             #檢視git整個的送出目錄日志
git log -p files    #檢視某個檔案的詳細修改記錄
           

參考:http://blog.csdn.net/whu_zhangmin/article/details/18596665

三、分支管理

git branch -a看下ansible分支的名稱
git checkout -b ansible分支  eg:git checkout -b ansible2 origin/ansible
pip install -e `pwd`        #-e, --editable <path/url>   Install a project in editable mode (i.e. setuptools "develop mode") from a local project path or a VCS url.      

四、開發nginx代碼的良好使用方式

為了不污染nginx本身的代碼,是以一般開發人員會用git diff生成差異的patch檔案,然後到真正編譯上線的時候再根據diff出的patch檔案apply到現有的代碼上,這樣新添加的代碼就會添加到原有nginx代碼上,再進行編譯即可

git diff > add-ssl-status.patch       #生成patch檔案
git apply add-ssl-status.patch        #把patch檔案的git差異變更代碼加入到現有的nginx中