0


git常用操作指南

文章目录

欢迎访问chatGPT网站:智聊对话机器人

一、git如何使用命令打tag

先可以使用git tag命令查看下当前有哪些tag,然后在原有tag的基础上增加版本号,并提交tag信息,例如:

git tag -a v2.0.0 -m "语音识别版本"
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

如果有个项目是用git的lfs管理的,那么首先需要安装git-lfs

yum install git-lfs

然后执行:

git lfs install

最后,git clone

git lfs clone [email protected]:ai/text-models.git

四、git管理分支

在这里插入图片描述
在这里插入图片描述

  1. 如何删除本地某个分支:

在删除你想删除的那个分支前,需要先切换到其他分支,然后再执行git的删除命令:

git branch -D branch_name

  1. 是否可以在某个分支的基础上再拉取分支?

答案是可以

例如,你有个分支名为dev-0506,现在想在该分支基础上再拉取分支dev-xgboost,那么操作如下:

1). 首先切换到分支dev-0506:git checkout dev-0506

2). 创建新分支dev-xgboost:git checkout -b dev-xgboost

3). 把新分支push到远程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,并把其复制到git的网页中去
#测试:ssh -T [email protected]#以后就不要这样去操作了:#git clone https://git.your_company.com/your_path/your_name/your_project.git#应该用下面的方式:#git clone [email protected]_company.com:your_path/your_name/your_project.git

七、git如何回滚代码版本

简单来讲就两步:

git reset --hard <commit_id>git push origin HEAD --force

八、git刚刚add完就后悔了,还没commit

比如刚刚git add yourfile.cpp
想撤销的话,直接:git reset HEAD yourfile.cpp
即可

九、如何进行git仓库迁移

1.先从老git仓库拷贝一个空壳下来
git clone --bare git://github.com/username/project.git
2.在新git仓库上创建一个新项目,比如new_project。
3.进入空壳目录,把内容push到新git地址去
cd project.git
git push --mirror git@gitcafe.com/username/new_project.git
4).刚才的那个空壳已经没用了,可以扔掉了
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

十、如何升级git

Centos 7 服务器上默认安装的 Git 是 1.8.3.1 版本的,有时候需要升级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 installgit

十一、如何去除github上“Repositories you contribute to”的提示消息干扰


前提:如果你曾经在github上对某个开源项目,open过issue,那么今后你每次登陆github都被这个开源repository的最新进展消息所刷屏,下面是去除的办法:

1.点击右侧你头像的位置,然后选择Settings

2.选择左侧的Notifications

3.将Participating

Notifications for the conversations you are participating in, or if someone cites you with an @mention.

下面的两个复选框去除

4.即可

十二、git常见错误:

1. git push总是提交失败

git push

结果提示如下

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://[email protected]': 
Already up-to-date.

解决办法:

git config --global push.default current

2. git push时报错:“fatal: The remote end hung up unexpectedly”


整个错误显示是这样的:

error: RPC failed; result=22, HTTP code = 413
fatal: The remote end hung up unexpectedly

这个时候,即使设置了git config http.postBuffer 524288000,然后再git push也没用

主要是得 git remote set-url origin git@git.xxx-inc.com:your_name/your_project.git (这一步骤需要在git网页上传你的开发机的公共秘钥,参考Git设置ssh密钥 - chenguiya - 博客园即可)

然后 再git push 就好使啦

3. git clone时报错:Initialized empty Git repository in: Gtk-WARNING **: cannot open display:

直接在终端中输入:

unset SSH_ASKPASS

即可

4. git push时报错:The requested URL returned error: 401 while accessing

直接在命令行输入:

git remote set-url origin 你的git项目地址

然后重新git push即可

5. git pull时报错:error: insufficient permission for adding an object to repository database .git/objects

sudochmod777 -R .git/objects

即可

6. git clone时报错:Peer’s Certificate issuer is not recognized

提示SSL证书错误。这个错误并不重要,是系统证书的问题,系统判断到这个行为会造成不良影响,所以进行了阻止,只要设置跳过SSL证书验证就可以了,输入以下命令即可:

git config --global http.sslVerify false

7. git clone时报错:Empty reply from server

报错信息如下:
fatal: unable to access ‘http://[email protected]/myname/myproject.git/’: Empty reply from server

解决办法:
发现~/.bashrc中配置了http_proxy代理,将其注释掉,然后重新登录一次终端即可

参考文献:

标签: git github

本文转载自: https://blog.csdn.net/zh515858237/article/details/127395409
版权归原作者 智聊对话机器人 所有, 如有侵权,请联系我们删除。

“git常用操作指南”的评论:

还没有评论