一、git如何切換分支
# 切換到名為v0.4.0的tag分支
git checkout v0.4.0
# 切換到main主干分支
git checkout main
一、git如何使用命令打tag
先可以使用git tag命令查看下當(dāng)前有哪些tag,然后在原有tag的基礎(chǔ)上增加版本號(hào),并提交tag信息,例如:
git tag -a v2.0.0 -m "語(yǔ)音識(shí)別版本"
git push origin v2.0.0
二、git如何使用命令刪除tag
git tag -d v1.0.0
git push origin :refs/tags/v1.0.0
二、git status顯示中文亂碼怎么辦
git config --global core.quotepath false
即可
三、如何使用git-lfs
如果有個(gè)項(xiàng)目是用git的lfs管理的,那么首先需要安裝git-lfs
yum install git-lfs
然后執(zhí)行:
git lfs install
最后,git clone
git lfs clone git@git.your-company.com:ai/text-models.git
四、git管理分支
- 如何刪除本地某個(gè)分支:
在刪除你想刪除的那個(gè)分支前,需要先切換到其他分支,然后再執(zhí)行g(shù)it的刪除命令:
git branch -D branch_name
- 是否可以在某個(gè)分支的基礎(chǔ)上再拉取分支?
答案是可以
例如,你有個(gè)分支名為dev-0506,現(xiàn)在想在該分支基礎(chǔ)上再拉取分支dev-xgboost,那么操作如下:
1). 首先切換到分支dev-0506:git checkout dev-0506
2). 創(chuàng)建新分支dev-xgboost:git checkout -b dev-xgboost
3). 把新分支push到遠(yuǎn)程git:git push -u origin dev-xgboost
六、配置git的ssh,免密碼push或者pull
git config --global user.name "yourname"
git config --global user.email "yourname@your_company.com"
ssh-keygen -t rsa -b 4096 -C "yourname@your_company.com"
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub,并把其復(fù)制到git的網(wǎng)頁(yè)中去
#測(cè)試:ssh -T git@git.lianjia.com
#以后就不要這樣去操作了:
#git clone https://git.your_company.com/your_path/your_name/your_project.git
#應(yīng)該用下面的方式:
#git clone git@git.your_company.com:your_path/your_name/your_project.git
七、git如何回滾代碼版本
簡(jiǎn)單來(lái)講就兩步:
git reset --hard <commit_id>
git push origin HEAD --force
八、git剛剛add完就后悔了,還沒(méi)commit
比如剛剛git add yourfile.cpp
想撤銷(xiāo)的話,直接:git reset HEAD yourfile.cpp
即可
九、如何進(jìn)行g(shù)it倉(cāng)庫(kù)遷移
1.先從老git倉(cāng)庫(kù)拷貝一個(gè)空殼下來(lái)
git clone --bare git://github.com/username/project.git
2.在新git倉(cāng)庫(kù)上創(chuàng)建一個(gè)新項(xiàng)目,比如new_project。
3.進(jìn)入空殼目錄,把內(nèi)容push到新git地址去
cd project.git
git push --mirror git@gitcafe.com/username/new_project.git
4).剛才的那個(gè)空殼已經(jīng)沒(méi)用了,可以扔掉了
rm -rf project.git
十、git如何合并代碼
1. 如何合并branch到master
git checkout master
git merge branch-name
git push origin master
2. 如何合并master到branch
git checkout master
git pull
git checkout branch-name
git pull
git merge master
十、如何升級(jí)git
Centos 7 服務(wù)器上默認(rèn)安裝的 Git 是 1.8.3.1 版本的,有時(shí)候需要升級(jí)git至2.x版本以上
yum -y remove git
yum -y remove git-*
yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
yum -y install git
十一、如何去除github上“Repositories you contribute to”的提示消息干擾
?
前提:如果你曾經(jīng)在github上對(duì)某個(gè)開(kāi)源項(xiàng)目,open過(guò)issue,那么今后你每次登陸github都被這個(gè)開(kāi)源repository的最新進(jìn)展消息所刷屏,下面是去除的辦法:
1.點(diǎn)擊右側(cè)你頭像的位置,然后選擇Settings
2.選擇左側(cè)的Notifications
3.將Participating
Notifications for the conversations you are participating in, or if someone cites you with an @mention.
下面的兩個(gè)復(fù)選框去除
4.即可
十二、git常見(jiàn)錯(cuò)誤:
1. git push總是提交失敗
git push
結(jié)果提示如下
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
git pull
又顯示正常:
Username for 'https://git.xxx.mycompany': myname
Password for 'https://myname@git.xxx.mycompany':
Already up-to-date.
解決辦法:
git config --global push.default current
2. git push時(shí)報(bào)錯(cuò):“fatal: The remote end hung up unexpectedly”
?
整個(gè)錯(cuò)誤顯示是這樣的:
error: RPC failed; result=22, HTTP code = 413
fatal: The remote end hung up unexpectedly
這個(gè)時(shí)候,即使設(shè)置了git config http.postBuffer 524288000,然后再git push也沒(méi)用
主要是得 git remote set-url origin git@git.xxx-inc.com:your_name/your_project.git (這一步驟需要在git網(wǎng)頁(yè)上傳你的開(kāi)發(fā)機(jī)的公共秘鑰,參考Git設(shè)置ssh密鑰 - chenguiya - 博客園即可)
然后 再git push 就好使啦
3. git clone時(shí)報(bào)錯(cuò):Initialized empty Git repository in: Gtk-WARNING **: cannot open display:
直接在終端中輸入:
unset SSH_ASKPASS
即可
4. git push時(shí)報(bào)錯(cuò):The requested URL returned error: 401 while accessing
直接在命令行輸入:
git remote set-url origin 你的git項(xiàng)目地址
然后重新git push即可
5. git pull時(shí)報(bào)錯(cuò):error: insufficient permission for adding an object to repository database .git/objects
sudo chmod 777 -R .git/objects
即可
6. git clone時(shí)報(bào)錯(cuò):Peer’s Certificate issuer is not recognized
提示SSL證書(shū)錯(cuò)誤。這個(gè)錯(cuò)誤并不重要,是系統(tǒng)證書(shū)的問(wèn)題,系統(tǒng)判斷到這個(gè)行為會(huì)造成不良影響,所以進(jìn)行了阻止,只要設(shè)置跳過(guò)SSL證書(shū)驗(yàn)證就可以了,輸入以下命令即可:
git config --global http.sslVerify false
7. git clone時(shí)報(bào)錯(cuò):Empty reply from server
報(bào)錯(cuò)信息如下:
fatal: unable to access ‘http://myname@git.department.company/myname/myproject.git/’: Empty reply from server文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-465110.html
解決辦法:
發(fā)現(xiàn)~/.bashrc中配置了http_proxy代理,將其注釋掉,然后重新登錄一次終端即可文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-465110.html
參考文獻(xiàn):
- https://www.jianshu.com/p/cdd80dd15593
- https://git-scm.com/book/zh/v1/Git-%E5%9F%BA%E7%A1%80-%E6%92%A4%E6%B6%88%E6%93%8D%E4%BD%9C
到了這里,關(guān)于git常用操作指南的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!