目录
一、git使用步骤
1. git一般步骤
a. git init
初始化本地仓库,会创建.git
隐藏文件夹,如果有本地仓库,就不要创建新的本地仓库
b. git add <文件>
把文件添加到暂存区
c. git commit -m <信息>
把暂存区的所有内容提交到当前分支,并注释信息
d. git remote add origin <远程仓库地址>
添加远程仓库
e. git pull --rebase origin <远程分支名>
拉取github分支到本地
f. git push -u origin <本地分支>
将本地代码推送到远程仓库
2. git 拉取/克隆代码
a. git pull <远程仓库地址>
b. git clone <远程仓库地址>
3. git推送代码
git push -u origin main
二、git错误经验
1. git没有设置邮箱
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
2. 分支冲突
github仓库中主分支是main,vscode中默认是master,需要对本地仓库改名
3. 连接不到远程服务器
报错:
fatal: unable to access ‘https://github.com/xxx.git/’: Failed to connect to github.com port 443 after 21102 ms: Timed out
解决方法:对代理服务器进行设置
4. 推送出错
报错:
error: failed to push some refs to ‘https://github.com/xxx.git’
本地和远程不一致,需要pull一下代码,但是注意将本地代码添加到暂存区
5. git版本回退
当本地代码被覆盖,可以查看git日志中之前的版本
git reflog
查看命令历史
git reset --hard HEAD^
回退到指定版本的代码