Git初始化項(xiàng)目
- git 初始化
1.Git init: 創(chuàng)建倉(cāng)庫(kù)并初始化——>終端 cd到代碼根目錄——>git init初始化倉(cāng)庫(kù),add,commit——>重點(diǎn)[git remote add origin 你的遠(yuǎn)程庫(kù)地址] ——>獲取遠(yuǎn)程庫(kù)同步git pull --rebase origin master——>提交git push -u origin mast递鹉;如果Git pull報(bào)錯(cuò): refusing to merge unrelated histories的解決辦法弓候,執(zhí)行下面的命令:git pull origin master --allow-unrelated-histories就可以了郎哭。參考:(https://www.cnblogs.com/xiangxinhouse/p/8254120.html)
- 本地配置git環(huán)境
2.本地配置git環(huán)境,終端創(chuàng)建sshkey: ssh-keygen -t rsa -C "********@163.com”,將創(chuàng)建好的ssh-key菇存,粘貼到git賬戶里的設(shè)置ssh的地方
*. 終端認(rèn)證關(guān)聯(lián)賬戶
git config --global user.name “XXXXX"
git config --global user.email “******@163.com"
常用基礎(chǔ)
1 創(chuàng)建repository夸研,復(fù)制鏈接clone本地,添加內(nèi)容依鸥,add . commit push
2 首次push亥至,git push --set-upstream origin master 或者 git push origin master : master
3 git pull 下拉內(nèi)容
4 創(chuàng)建分支并切換到此分支: git checkout -b newBranch
5 創(chuàng)建分支:git branch newBranch 切換到此分支:git checkout newBranch
6 將新分支合并到master分支 git checkout master,合并: git merge newBranch
7 刪除分支: git branch -d newBranch
8 查看分支 :git branch
遠(yuǎn)程分支管理:
0毕籽、更新遠(yuǎn)程分支列表: git remote update origin --prune
1抬闯、本地分支推送到遠(yuǎn)端:git push origin <local_branch_name>:<remote_branch_name> 如:git push origin 2.6.0 : 2.6.0
2、刪除: git push origin :develop local_branch_name為空就表示刪除
3关筒、clone遠(yuǎn)程分支: git clone -b <branch name> <repository >
git多個(gè)賬戶:
1溶握、當(dāng)使用git config --global user.name “XXXX"
git config --global user.email “********@163.com”關(guān)聯(lián)的是全局賬戶,在user文件夾里會(huì)有一個(gè).gitconfig文件蒸播,可以打開看看
2睡榆、若需要另一個(gè)賬戶管理其他的git工程萍肆,可以在工程文件夾下,終端使用命令:
git config user.name “XXX"
git config user.email “******@163.com”
3胀屿、查看當(dāng)前git工程目錄下的賬戶 git config --list
bogon:AudioPlayerManager Hammer$ git config --list
credential.helper=osxkeychain
user.name=chaozhangkong //全局賬戶
[user.email=juniorchen@yingshibao.com](mailto:user.email=juniorchen@yingshibao.com)
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=https://github.com/xxxx/*****.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
user.name=XXXX //此工程的賬戶
[user.email=******@163.com](mailto:user.email=******@163.com)
bogon:AudioPlayerManager Hammer$
日志log
1.查看最新的commit
git show
2.查看指定commit hashID的所有修改:
git show commitId
3.查看某次commit中具體某個(gè)文件的修改:
git show commitId fileName
Tag標(biāo)簽:
1塘揣、創(chuàng)建標(biāo)簽: git tag v2.7.0 ,帶描述的標(biāo)簽:git tag -a v2.7.0 -m “version2.7.0 released"
2宿崭、查看標(biāo)簽: git tag 或 git tag #亲铡, git show tagName(git show v2.7.0)查看標(biāo)簽描述
3、刪除標(biāo)簽:git tag -d v2.7.0
4葡兑、將本地標(biāo)簽推送到遠(yuǎn)程: git push origin v2.7.0奖蔓,或者,一次性推送全部尚未推送到遠(yuǎn)程的本地標(biāo)簽:git push origin —tags
5讹堤、刪除遠(yuǎn)程標(biāo)簽tag: 先刪本地:git tag -d v2.7.0吆鹤, 遠(yuǎn)程:git push origin :refs/tags/v2.7.0
6、創(chuàng)建本地tag分支:git checkout -b branch_name tag_name
7洲守、切換當(dāng)指定分支 : git checkout v2.7.0
不常見問題
- git push 超過100M解決辦法
1 方法一:可以以命令的形式直接git bash 中直接:git config http.postBuffer 524288000(500M)
對(duì)于部分非二進(jìn)制的文件這樣的可以解決單個(gè)文件過大的問題
如果方法一不可行疑务,git push還是說的是文件過大,那么只有刪除這個(gè)二進(jìn)制文件了梗醇,原因可看碼云
刪除文件后還是同樣的提示的話知允,就直接下面的方法了
2 方法二 git bash 中命令:git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch folder" -- --all
其中folder可以修改成你的文件名字(也就是報(bào)錯(cuò)中的文件名字)
- git pull 提示fatal: refusing to merge unrelated histories
git pull origin master --allow-unrelated-histories
廖雪峰的官方網(wǎng)站:
http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/