

1、基本指令
- 克隆
git clone HTTPS/SSH
- 拉取远程仓库
git pull origin 远程分支
- 查看分支:
git branch -a
- 建立分支
git branch 分支名
- 切换分支
it checkout 分支名
- 查看提交历史
git log
- 推送到远程仓库
工作区->暂存区:git add .
暂存区->本地仓库:git commit -m '提交备注'
本地仓库->远程仓库:git push origin 远程分支
- 合并:
git merge 需要合并的分支(在合并的目标分支下操作)
- 删除远程仓库:
git remote rm [别名]
或git push origin --delete [别名]
- 查看当前方式(HTTPS ro SSH)
git remote -V
- 使用命令将远程URL从HTTPS更改为SSH 。
git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
12.回退到某个版本
先查看commitID
git log
git reset --hard commitID
13.查看所有操作,包括错误的
git reflog
git关联提交
1.执行一下命令初始化git
git init
2.配置远程仓库链接
git remote add origin https://gitlab.com/qhhh/cuhk-archive.git
3.使用以下命令查看是否配置成功
git remote -v
4.推送仓库
git add .
git commit -m '提交备注'
it push -u origin 远程分支
可能出现的问题
- ‘https://gitlab.com/ffbb321/rocks-web-c.git/’: OpenSSL SSL_connect: Connection was reset in connection to gitlab.com:443
- 连接远程失败,解决方法切换ssh或https连接
配置SSH
- 生成 SSH Key
ssh-keygen -t rsa -C "youremail@example.com"
- 查看SSH Key
cat ~/.ssh/id_rsa.pub