常用git指令
-
查看、添加/修改用户名和邮箱
#查看 git config user.name/user.email git config --global user.name/user.email # 修改全局 git config --global user.name/user.email xxx/xxx@xx.com # 修改当前project git config user.name/user.email xxx/xxx@xx.com
-
克隆远程仓库
# 默认克隆master分支 git clone https://github.com/open-mmlab/OpenPCDet.git # 克隆并重命名 git clone [远程仓库地址] [想要重命名的文件夹名称] git clone https://github.com/open-mmlab/OpenPCDet.git OpenPCDet(master) # 克隆指定版本 git clone --branch [tag/branch] [git地址] or git clone --b [tags标签] [git地址] git clone -b v0.5.0 https://github.com/open-mmlab/OpenPCDet.git
-
查看、删除、切换\添加远程仓库
# 查看 git remote git remote -v # 会显示需要读写远程仓库使用的 Git 保存的简写与其对应的 URL # 删除 git remote rm origin # 切换\添加 git remote add origin https://github.com/open-mmlab/OpenPCDet.git # 添加多个(这时不能再用origin来命名) git remote add WPX https://github.com/weioingxiao/OpenPCDet.git
-
查看、创建、切换、删除分支
git branch # 查看分支(当前分支前面会标一个*号) git branch -a # 查看所有分支 git branch dev # 创建分支 git checkout dev # 切换分支(git switch dev) git checkout -b dev git branch -D dev # 删除分支
-
合并多余的commit
1. 使用reset git reset --soft xxxx # 回到某次commit git commit xxx # 重新提交,这样多余的commit就合并了 2. 使用rebase # 合并最近两次的commit git rebase -i HEAD~2 选s,表示squese
-
回到之前的commit
1. 回到任意的commit git log # 查看某一次的commit编号 git reset --soft xxxx # 回到某次提交版本,soft表示当前的代码仍然保持不变 2. 回到上几次的commit git reset --soft HEAD~1 # 回到前一次
-
撤回push/commit后重新push/commit
1. 回到上一次commit版本 git reset --soft HEAD~1 2. 重新提交 git commit xxx 3. 强制更新远程仓库 git push origin main --force
-
从origin远程仓库获取最新版本的代码到本地的temp分支
git fetch origin master:temp git pull origin master #会自动和本地分支合并 git pull origin master --allow-unrelated-histories
-
查看temp分支与本地原有分支的不同
git diff temp
-
将temp分支和本地的master分支合并
git merge temp git merge temp --allow-unrelated-histories # 版本出现偏差时
-
将本地代码提交到github
1. 获得token 2. 从远端pull初始仓库 3. 修改后commit、push到远程仓库
常见问题
-
fatal: refusing to merge unrelated histories
git pull origin master --allow-unrelated-histories
-
OpenSSL SSL_read: Connection was reset, errno 10054
git config --global http.sslVerify "false"
-
Failed to connect to github.com port 443: Timed out
可能是有代理的原因
git知识点
-
tag和branch的区别
tag是一系列commit的中的一个点,只能查看,不能移动
branch是一系列串联的commit的线