常见问题
fatal: unable to access’https://github.com/xxx/xxx.git/':Failed connect to github.com:xxx;
解决方法:
git config –global http.proxy
git config –global –unset http.proxy
查询到当前设置了代理,取消这个设置即可。
如果在git push -u origin master时出现以下错误,证明电脑没有修改远程仓库的公钥
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
- 解决方法:
- 在github上点击Edit profile –> SSH and GPG keys –> new SSH key 添加SHH公钥
- 打开id_rsa.pub文件(C:/Users/Administrator/.ssh/id.rsa.pub)
- 将id_rsa.pub文件内容拷贝到key就可以了,title随便填。
github 仓库克隆到本地
git clone https://github.com/xxx/xxx.git
本地仓库创建
git init
本地代码提交仓库
1)更新全部文件:git add .
2)输入修改信息:git commit -m '修改信息'
3)push到github上:git push -u origin master
分支合并到master分支上
1)git checkout master:将master分支拉取下来
2)git merge origin/xxx:将master分支和xxx做一个合并
3)git push 将合并后的代码提交到master中
拉取最新分支
1)git pull
2)git checkout '分支名'
查看仓库状态
git status
查看分支
git branch
合并分支
git merge xxx
同步本地仓库和远程仓库
git pull --rebase origin master
查看历史版本
git log
git log --pretty=oneline
回退到版本
*回退到上一个版本*
git reset --hard HEAD^
*回退到上100个版本*
git reset --hard HEAD~100
*回退到该ID版本*
git reset --hard 038491dda6a7982ae02bbb1c85908c4eabf0f639
参考资料
https://segmentfault.com/a/1190000019419170?utm_source=tag-newest