O、版本控制
分支:branch
git branch -a # 查看分支 git switch -c dev # 创建并切换到分支 git branch <name> 也可创建分支 git switch dev # 切换分支 git merge dev # 合并指定分支到当前分支 git branch -d dev # 删除本地分支 git push gitee --delete dev # 删除云端分支 git log --graph # 查看分支合并图 git status # 查看状态
标签:tag
git tag # 查看所有标签 git tag v1.0 # 创建标签 git tag -d v0.1 # 删除标签 git tag v0.9 f52c633 # 按照历史提交创建标签 git show v0.9 # 查看标签信息 git tag -a v0.1 -m "version 0.1 released" 1094adb # 创建时指定标签信息 git push origin v1.0 # 推送某个标签 git push origin --tags # 推送所有标签
建立仓库联系
git remote -v # 查看远程仓库连接 git remote rm origin # 删除远程仓库连接 git remote add github git@github.com: # 增加连接 git remote add gitee git@gitee.com: # 增加连接 git push github/gitee master # push操作
创建别名
git config --global alias.ci commit # 把commit换成ci
工作区
git status # 查看暂存区
移动文件
mv oldname newname # 移动文件 git add newname # 增加新文件 git rm oldname # 删除旧文件
一、日常使用
1、克隆
把项目复制到本地
git clone https://github.com/philox12358/Jason-Research.git # http克隆 git clone git@github.com:philox12358/Jason-Research.git # ssh克隆(更好用)
2、提交
0、更新云端文件到本地:
git pull origin main
1、Git操作即可
git add -A # 先修改文件,后更新暂存区 git commit -m "web" # 设置提交信息 git push --set-upstream origin master # 推送云端 git push --set-upstream github master # 云端名字 本地分支名字
2、git pull
git pull origin master # 远程分支是与当前分支合并
3、合并
依次点击以下按键
compare & pull request create pull request merge pull request ——(This branch has no conflicts with the base branch) confirm merge Pull request successfully merged and closed # 成功
二、配置Git和GitHub的连接
1、本地Git配置绑定远程Github账户
git config --global user.name "philox12358"
git config --global user.email philox12358@163.com # 添加本地账户信息
ssh-keygen -t rsa -C "philox12358@163.com" # 生成密匙
去对应文件夹把“id_rsa.pub”文件的内容复制
到自己的github当中的设置里面创建新的SSH key,输入刚才复制的密匙即可。
ssh -T git@github.com //git中输入此代码验证连接
ssh -T -p 443 git@ssh.github.com //使用指定端口验证连接
三、解决Git相关的问题
1、fatal: unable to access ‘https://github.com/.../.git'
只需要在命令行中执行
git config --global git.proxy 127.0.0.1:10080
git config --global http.proxy 127.0.0.1:10080
git config --global https.proxy 127.0.0.1:10080
2、git push失败
重新绑定网上的仓库地址,或者换gitee
3、Could not read from remote repository.
git remote –v
4、重装node出现问题
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解决办法:
ssh: connect to host github.com port 22: Connection timed out_妙欣风的博客-CSDN博客
重装Git然后添加ssh KEY