在日本怎樣做網(wǎng)站網(wǎng)站建設(shè)詳細(xì)方案
文章目錄
- 1. GIT介紹
- 2. 使用GIT的好處
- 3. GIT 安裝
- 4. GIT 配置
- 4.1 GIT 初始化設(shè)置、命令別名設(shè)置
- 4.2 如果終端安裝了oh-my-zsh,會帶一堆git命令別名
- 4.3 GIT配置文件介紹
- 4.3.1 Linux、Mac OS系統(tǒng)
- 4.3.2 windows系統(tǒng)
- 5. git設(shè)置遠(yuǎn)程倉庫賬號密碼(拉取、上傳代碼不用輸入用戶名密碼)
- 6. git文件夾詳解
- 7. 圖形軟件操作工具
1. GIT介紹
git是一個分布式版本控制軟件,與常用的版本控制工具如CVS、Subversion不同,支持離線開發(fā),離線存儲。強(qiáng)大的分支功能,適合多個獨(dú)立開發(fā)者協(xié)作。速度塊。
用戶從遠(yuǎn)端GIT倉庫下載一個工程(project)時,這個工程的所有文件,包括版本歷史,文件改動都會下載下來,這時 候本地GIT就演變成了一個服務(wù)器,所有的提交(check-in)、提出(check-out)都會在這個本地服務(wù)器上執(zhí)行,當(dāng)你確定一項修改之后,可 以再和遠(yuǎn)端倉庫進(jìn)行合并和同步(merge)。所以,GIT的安裝和配置步驟無論在本機(jī)還是服務(wù)器上都是完全一樣的。
2. 使用GIT的好處
- 更順暢的工作流程,開發(fā)過程中,完全可以離線操作
- 快速,Git分布式架構(gòu)使得本地倉庫包含所有的歷史版本信息,你可以在不同的版之間快速切換
- 彈性的本地分支,在svn下,你建一個分支需要把源代碼復(fù)制到另外一個文件夾,而在Git下,創(chuàng)建分支的代價是非常小的,只需一條命令
- 倉庫目錄結(jié)構(gòu)簡潔,用Git復(fù)制一個項目,只會在項目根目錄創(chuàng)建一個.git的目錄,而其他目錄很干凈
- 內(nèi)容按原數(shù)據(jù)方式存儲,所有的版本信息都位于.git目錄下
- 完整性好,更易于協(xié)作開發(fā)
- 用戶群大,現(xiàn)在已經(jīng)有成千上萬個開源項目采用Git來做項目管理,github上更是有無數(shù)個代碼倉庫
參考鏈接: http://blog.csdn.net/fyx708711/article/details/52606252
3. GIT 安裝
https://git-scm.com/book/zh/v2/起步-安裝-Git
1、 linux系統(tǒng)的centos7.2安裝:
sudo yum update
sudo yum install -y git
2、ubuntu 安裝(一般系統(tǒng)默認(rèn)就安裝了)
# http://www.linuxidc.com/Linux/2016-09/135527.htm
sudo apt-get install git
3、Mac OS蘋果系統(tǒng)(一般默認(rèn)就安裝了,需要事先安裝了homebrew )
brew install git
4、windows系統(tǒng),安裝git終端:
https://git-for-windows.github.io/
安裝教程:https://jingyan.baidu.com/article/20095761b48041cb0721b4fc.html
4. GIT 配置
linux、mac系統(tǒng)打開終端進(jìn)行下面配置。
window系統(tǒng)打開git bash終進(jìn)行下面端配置。
4.1 GIT 初始化設(shè)置、命令別名設(shè)置
下面操作linux, Mac OS, window 都適用。
設(shè)置用戶名和郵箱:
# https://git-scm.com/book/zh/v2/起步-初次運(yùn)行-Git-前的配置
# https://git-scm.com/book/zh/v2/自定義-Git-配置-Git
git config --global user.name name # 設(shè)置GIT的用戶名
git config --global user.email you_email_addr@gmail.com # 設(shè)置GIT的郵箱
必須要的配置:
git config --global core.mergeoptions --no-edit # 關(guān)閉git pull產(chǎn)生的merge信息
git config --global commit.template ~/.gitmessage.txt # git 提交時編輯里面的模板
# 終端內(nèi)容顯示顏色:false:關(guān)閉, auto:自動,有的顏色會忽略, always:忽略掉管道和終端的不同,即在任何情況下著色輸出
git config --global color.ui false# 使用VIM編輯器編輯作為GIT的默認(rèn)編輯器
git config --global core.editor vim
# 存儲credential(憑證),自動保存遠(yuǎn)程倉庫賬號密碼
git config --global credential.helper store
# https://git-scm.com/book/zh/v2/Git-工具-憑證存儲
# 關(guān)閉對0x80以上的字符進(jìn)行quote, 解決git的中文亂碼問題。
git config --global core.quotepath false
# 自動轉(zhuǎn)換LF和CRLF(不同操作系統(tǒng)換行不同問題)。
git config --global core.autocrlf true
# 把CRLF自動轉(zhuǎn)換警告取消
git config --global core.safecrlf false
# 設(shè)置git識別大小寫
git config core.ignorecase false
# 修改git log中時間的顯示格式為 2021-07-14 10:13:17 +0800
git config --global log.date iso8601
git config --global --replace-all log.date format:'%Y-%m-%d %H:%M:%S'# 查看上面的配置
git config --list
# 查看git路徑
which git
# 刪除一個配置項
git config --global --unset log.date
# 編輯配置文件
git config --global --edit
GIT命令別名 方便操作快捷(頻繁git操作的時候,命令簡化。):
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global alias.hist 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short'
git config --global alias.type 'cat-file -t'
git config --global alias.dump 'cat-file -p'
# log 只顯示修改的文件
git config --global alias.ls 'log --stat'
# log 只用一行顯示信息
git config --global alias.one 'log --pretty=oneline'
4.2 如果終端安裝了oh-my-zsh,會帶一堆git命令別名
Mac 用戶和 Linux 用戶通過在您的終端中運(yùn)行以下命令來安裝oh-my-zsh:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
oh-my-zsh帶的git命令別名:
g - git
gst - git status
gl - git pull
gup - git pull --rebase
gp - git push
gd - git diff
gdc - git diff --cached
gdv - git diff -w "$@" | view
gc - git commit -v
gc! - git commit -v --amend
gca - git commit -v -a
gca! - git commit -v -a --amend
gcmsg - git commit -m
gco - git checkout
gcm - git checkout master
gr - git remote
grv - git remote -v
grmv - git remote rename
grrm - git remote remove
gsetr - git remote set-url
grup - git remote update
grbi - git rebase -i
grbc - git rebase --continue
grba - git rebase --abort
gb - git branch
gba - git branch -a
gcount - git shortlog -sn
gcl - git config --list
gcp - git cherry-pick
glg - git log --stat --max-count=10
glgg - git log --graph --max-count=10
glgga - git log --graph --decorate --all
glo - git log --oneline --decorate --color
glog - git log --oneline --decorate --color --graph
gss - git status -s
ga - git add
gm - git merge
grh - git reset HEAD
grhh - git reset HEAD --hard
gclean - git reset --hard && git clean -dfx
gwc - git whatchanged -p --abbrev-commit --pretty=medium
gsts - git stash show --text
gsta - git stash
gstp - git stash pop
gstd - git stash drop
ggpull - git pull origin $(current_branch)
ggpur - git pull --rebase origin $(current_branch)
ggpush - git push origin $(current_branch)
ggpnp - git pull origin $(current_branch) && git push origin $(current_branch)
glp - _git_log_prettily
參考資料:
https://segmentfault.com/a/1190000007145316
https://www.hinjin.com/2018/04/13/%E5%A6%82%E4%BD%95%E5%8A%A0%E5%BF%AB%E4%BD%A0%E7%9A%84git%E6%93%8D%E4%BD%9C%EF%BC%9F/
4.3 GIT配置文件介紹
4.3.1 Linux、Mac OS系統(tǒng)
Git 使用一系列配置文件來保存你自定義的行為。
它首先會查找 /etc/gitconfig 文件,該文件含有系統(tǒng)里每位用戶及他們所擁有的倉庫的配置值。 如果你傳遞 --system 選項給 git config,它就會讀寫該文件。
接下來 Git 會查找每個用戶的 ~/.gitconfig 文件(或者 ~/.config/git/config 文件)。 你可以傳遞 --global 選項讓 Git 讀寫該文件。
最后 Git 會查找你正在操作的版本庫所對應(yīng)的 Git 目錄下的配置文件(.git/config)。 這個文件中的值只對該版本庫有效。
以上三個層次中每層的配置(系統(tǒng)、全局、本地)都會覆蓋掉上一層次的配置,所以 .git/config 中的值會覆蓋掉 /etc/gitconfig 中所對應(yīng)的值。
4.3.2 windows系統(tǒng)
windows7系統(tǒng): C:\Documents and Settings\用戶名,其中有一個.gitconfig的文件。
windows8系統(tǒng): C盤 -> 用戶(Users) -> 用戶名 文件夾下,有個.gitconfig的文件。
在上述那個目錄底下, 可發(fā)現(xiàn)另外一個文件.git-credentials,里面記錄的就是用戶名密碼了。
5. git設(shè)置遠(yuǎn)程倉庫賬號密碼(拉取、上傳代碼不用輸入用戶名密碼)
- github Personal access tokens
使用token可以不需要密碼就可以讀取遠(yuǎn)程倉庫代碼,如果你的遠(yuǎn)程倉庫網(wǎng)站提供了賬戶訪問token,那么設(shè)置一個access tokens。
github網(wǎng)站登陸后, 點(diǎn)擊右上角的用戶圖標(biāo) -> settings -> 選擇 Developer settings -> 選擇 Personal access tokens,或者打開鏈接https://github.com/settings/tokens
使用:
git clone https://github.com/username/repo.git
username: your email
Password: your access tokens
由于github在2021-08-13禁止了用戶名、密碼形式,所以需要使用如下形式:
# git clone https://oauth2:[access tokens]@github.com/user/repo
git clone https://oauth2:ghp_GjguOh******KZm@github.com/user/repo
# 修改倉庫
git remote set-url origin https://oauth2:ghp_GjguOh******ThzKZm@github.com/user/repo
碼云倉庫有類似的:碼云 私人令牌
- git-credentials git讀取賬號密碼文件
這里是為了你在拉取代碼的時候不用在輸入用戶名密碼了,
但是這里會暴露你遠(yuǎn)程倉庫的用戶名密碼,注意保密,如果電腦不用了記得刪除這個文件。
# 打開文件,如果沒有則會自動創(chuàng)建文件
$ vim ~/.git-credentials
# 編輯好文件后運(yùn)行g(shù)it命令來讓文件生效
$ git config --global credential.helper store
里面文件內(nèi)容:
http://用戶名:密碼或token@倉庫地址
http://yulilong:password@192.168.102.9
https://yulilong:password@bitbucket.org
http://yulilong:password@bitbucket.org
https://yulilong:5199818388420@github.com
http://yulilong:github_Personal_access_tokens@github.com
6. git文件夾詳解
-
探索.git目錄
-
.git文件夾詳解
-
Git 內(nèi)部原理
7. 圖形軟件操作工具
有的可能不適應(yīng)命令行的復(fù)雜, 所以有一款圖形化操作軟件,并且?guī)ЫK端的軟件。
網(wǎng)址:https://git-scm.com/
下載地址:https://git-scm.com/downloads
這個軟件在window下自帶命令行工具, 可以直接在打開文件夾中鼠標(biāo)右鍵用命令行打開這個文件夾,使用非常方便。b