版本管理札記整理

GIT

環境變量 PATH添加 D:\Program Files\Git\bin(某些工具例如brower從此處讀取git路徑)
HTTPS代碼記住密碼

git config --global credential.helper store
## git文件名識別大小寫, 防止大小寫更名不顯示變動
git config core.ignorecase false

提交時也不轉換(應對可能需要提交crlf時的場景),檢出時不轉換

git config --global core.autocrlf false 

提交包含混合換行符的文件時給出警告

git config --global core.safecrlf warn

下載自簽名證書,並設置路徑

http://mirrors.d.com/ssl/ca-bundle.crt  >> D:\Program Files\Git\mingw64\ssl\certs\ca-bundle.crt
git config --global http.sslCAInfo "D:\Program Files\Git\mingw64\ssl\certs\ca-bundle.crt"

遠端管理

## 遠端管理和查看
# 【增】加遠端倉庫
git remote add remote-name git-remote-url
# 【刪】除遠程倉庫
git remote rm remote-name
# 【改】修改遠程倉庫名
git remote rename remote-name remote-name-new
# 【查】看有哪些遠端倉庫
git remote -v
# 【查】看遠端倉庫的分支情況
git remote show remote-name


## 遠端通信
# 將遠程倉庫中的分支數據取回本地,git branch -a查看是以remotes/remote-name/branch-name形式顯示
git fetch remote-name branch-name  

##分支管理
# 查看本地分支
git branch
# 查看所有分支(包含遠端已經tracks的分支)
git branch -a
# 創建新的分支(本地分支不要帶/避免和遠程分支重名)
git branch branch-name
# 刪除本地分支
git branch -D branch-name
# 切換工作分支到指定分支,可切換到已跟蹤的遠程分支查看文件,但不建議直接修改遠程分支
git checkout branch-name
=====簡寫形式======
# 創建並切換工作分支到指定分支
git checkout -b branch-name

提交合並

git誤上傳大文件的處理

## 服務器端執行
## 查找倉庫中的大文件  輸出格式 SHA-1 type size size-in-packfile offset-in-packfile
git verify-pack -v objects/pack/pack-*.idx | sort -k 3 -g | tail -5
## 根據sha-1查看文件的信息
git rev-list --objects --all | grep <SHA-1>
## 查看一下相關的提交
git log --oneline --branches -- Oracle集羣搭建/oracle_rac/linux.x64_11gR2_grid.zip

## --index-filter --tree-filter
## --prune-empty 表示如果修改後的提交如果爲空則扔掉不要
## --ignore-unmatch 指定當你試圖刪除的內容並不存在時不顯示錯誤
## --cached 從索引刪除而不是從硬盤刪除
git filter-branch --force --index-filter \
  'git rm --cached --ignore-unmatch MySQL環境搭建/RPM安裝包/MySQL-server-5.6.34-1.el6.x86_64.rpm' \
  --prune-empty --tag-name-filter cat -- --all

## 刪除變量歷史中的引用以使得gc可以生效
rm -rf refs/original
rm -rf logs
## 重新打包pack
git gc

## 從鬆散對象中移出
git prune --expire now
## 再查看一下對象統計
git count-objects -v

參考文章: https://git-scm.com/book/zh/v2/Git-內部原理-維護與數據恢復

Git Hook

客戶端Hook

pre-commit
prepare-commit-msg
commit-msg
pre-rebase
post-merge
post-rewrite
pre-push

服務端Hook

pre-receive
update
post-receive

git目錄結構

config          ## git倉庫級別的配置
description     ## gitweb程序使用的描述信息,未使用gitweb則無用
HEAD            ## 用於指示目前被檢出的分支(當前正在使用的分支) 內部格式 ref: refs/heads/master
hooks           ## git鉤子
info            ## 目錄
  exclude       ## 全局排除文件, 不希望記錄在.gitignore中的配置文件
  refs
objects         ## 存儲GIT object的目錄 object=zlib(類型頭部+空格+長度+空字節+原始數據)
  xx/xx         ## 一個object一個文件,以object的40位sha-1命名,前2位作爲文件夾名,後38位作爲文件名
  info          ## 已打包的對象(包內對象索引)
  pack          ## 已打包的對象(包內對象數據)
refs            ## 目錄 引用指針
  head          ## 分支的引用
  tags          ## 標籤的引用

內部命令

## --- 對象管理
## 查看object的內容,以sha-1作爲參數查看 
[root@git]# git cat-file -p 843aa11fb692f4dabca56ce741c7ff15d9576973
100644 blob af20b7f652740e999f3d7f0f6b85ba736a14aea3    build.gradle
040000 tree 956a888343b3d451bbf50b0a765e66e8b30319d0    src
[root@git]# git cat-file -p cb353d0889c6e4e2245a5086c51fdfd7d7301ab2
/.idea
/.gradle
*/target/*
/target
/auth.properties
## 查看object的類型 blob (binary large object)  tree(tree object) commit (commit object) (tag object)
[root@git]# git cat-file -t 843aa11fb692f4dabca56ce741c7ff15d9576973
tree
[root@git]# git cat-file -t cb353d0889c6e4e2245a5086c51fdfd7d7301ab2
blob
[root@git tags]# git cat-file -t c00bb68a4429ca223848270488f75be2e1559655
tag
## 查看對象的大小
[root@git tags]# git cat-file -s c00bb68a4429ca223848270488f75be2e1559655
158
## 列出所有提交的對象的sha 及相關聯的文件路徑
git rev-list --objects --all
## 統計object
[root@git]# git rev-list --objects --all | wc -l
2417
[root@git]# git count-objects -v
count: 1522
size: 6132
in-pack: 898
packs: 1
size-pack: 238
prune-packable: 0
garbage: 0
size-garbage: 0
## 查看包含某個文件的所有提交
[root@git]# git log --oneline --branches -- build.gradle
381ae1a add outher run and change maven
76ec061 (refs/keep-around/76ec0618217b2cb0fefb32b1fbfbec28e3f7d9b7) chore: 調試sonartube
371873f (refs/keep-around/371873f69f8e107cc230f97b947f8b4559344fc5) chore: 修復構建腳本依賴錯誤
00cef8e (refs/keep-around/00cef8ebf8eae16286de36d27486c3c5fd1f0a2a) chore:構建腳本優化 增加gitignore文件
0bf5615 chore: 最新插件默認爲java-9 與spring兼容有問題 重置爲java-8
4b018c0 chore: 排除iml項目文件 更新構建依賴 修復gradle重複下載等問題
faebf75 chore: update app plugins 0.1.7
9ab63b3 chore: optimize gradle configuration
51ed5a1 change yml file
882f10d initial commit



## 新建object, 返回object的sha-1值
echo 'PortList' | git hash-object -w --stdin  

## --- 引用管理
## 查看HEAD引用的值
git symbolic-ref HEAD
## 設置HEAD引用的值 (相當於執行git checkout test)
git symbolic-ref HEAD refs/heads/test
## 更改引用的值(相當於修改tag的位置) 如果引用的是一個tag object則是一個標籤引用(通常的情況) 如果引用的是一個commit object 則是一個輕量引用 
git update-ref refs/tags/v1.0 cac0cab538b970a37ea1e769cbbde608743bc96d

[root@git tags]# git cat-file -p c00bb68a4429ca223848270488f75be2e1559655
object eaeba8b7550b9c281128a2df17bc0e4fb35374da
type commit
tag V1.0
tagger zhenghuanbo <[email protected]> 1539942421 +0800

## --- 包管理
## 查看已經被打進包的對象列表
[root@git pack]# git verify-pack -v pack-0ca5542ba83c2c217db1bc8307af5153980d072f.idx
2ceb6f6a2d5406e1ef80e8774b6f8a6349594d5b commit 255 192 12
371873f69f8e107cc230f97b947f8b4559344fc5 commit 250 199 204
00cef8ebf8eae16286de36d27486c3c5fd1f0a2a commit 259 206 403
87375e1c00c8a957b3cc55c2d87ed66f61b647e5 commit 355 237 609
5d8e5df0b54c3de44718430fa26ff2ff88f98396 commit 390 272 846
7cdfdda13f22c7ae30999cdea712b3ee0c185dd2 commit 389 295 1118
21778ac5ba5da2fe94170f75755d1018faf79761 commit 233 159 1413
1fb2a3d494b0afb8bf008583397b53dfb6097c18 commit 233 157 1572
3eaafa17603a865b4973a0d7672633008f5e94d8 commit 233 159 1729
2f4b26fdcf55f5ddf7f5abac0452e37f54939911 commit 233 159 1888
45a4c92e793d04362820a56fd9ea8b4931f2981b commit 233 158 2047
## 手動重新打包
git gc

分支設置與開發模式

分支分類

按分支的聲明週期分類

  • 常設分支
  • 臨時分支

按分支的使用目的分類

開發模式

  • 先鋒主幹多穩定分支(主幹開發模式) 適合產品線的發佈管理,案例:freebsd
  • 守護主幹多先鋒分支(分支開發模式) 適合持續發佈,方便研發管理
  • 主幹無分支(主幹開發模式) 緊急項目最高效,配合每日集成
  • 守護主幹單分支(分支開發模式)

http://thinkernel.bokee.com/4518935.html
http://nvie.com/posts/a-successful-git-branching-model/
https://blog.csdn.net/zhangmike/article/details/38613429
https://www.cnblogs.com/sloong/p/5868292.html

SVN

SVN與GIT相互轉換

SVN=>GIT

## 1. 將SVN轉換爲GIT
# 克隆SVN倉庫,此步驟速度很慢,只適合一次性導入
git svn clone http://svnurl --username username -r initial:HEAD --authors-file=users.txt
# 添加GIT遠程倉庫
git remote add remote-name git-remote-url
# 提交到GIT倉庫
git push remote-name branch-name

## users.text內容
[svn的名字] = [git上的名字] <[git上的email]>
例如:
aa=bb<[email protected]>
tt=ee<[email protected]>

## 2. GIT做爲主庫,GTI定時向SVN同步
# 獲取GIT最新更新並和本地master分支合併
git pull remote-name branch-name
# 向svn提交差異
git svn dcommit

## 3. SVN做爲主庫,定時想GIT同步
# 從SVN倉庫獲取更新
git svn rebase
# 向git推送
git push 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章