使用工具git Git Bash Here
对于一个git远程仓库管理工具而言,一般都是需要配置本地与仓库账号相匹配的ssh key
git config --list //可以查看是否配置了名字和邮箱
git config --global user.name "姓名" //配置git名称
git config --global user.email "邮箱地址" //配置git邮箱
查看对应的ssh-key
如果你发现没有
使用命令
ssh-keygen -t rsa -C "你的邮箱地址"
使用noteapp++打开文件:id_rsa.pub
将内容全部复制:ssh-rsa xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
将SSH-key配置到github或者码云等等中 就不细说了
下载已有项目
进入你的文件夹目录中 右键打开Git Bash Here
git remote add origin url //url为你的git下载路径
#如果报错fatal: remote origin already exists.
#那么就 git remote rm origin 然后继续再次执行下载的命令
#执行完之后是没有任何反应的,拉去代码,还需要一个命令
git pull origin master
#[master]这个为需要拉去的分支名称 一般都是主干master
#然后你会发现 你本地文件夹里面已经把远程的项目下载下来了
上传自己修改的代码
git add . //把代码添加暂存
git commit -m “备注信息” //提交到本地并说明信息
git push origin master //提交到远程 之前创建的origin项目上的master分支上
分支使用
分支创建
git branch demo //demo为分支名称 可以任意取名
git branch //查看所有分支*表示当前所在分支
git checkout demo //切换分支 demo表示切换的分支名称
git push origin demo //把当前分支上传到远程仓库中去
分支代码的提交与整合
#首先你要知道自己所在分支
git branch
#不是自己想要的分支可以命令切换
git checkout demo
#然后提交代码
git add .
git commit -m "备注信息"
git push origin demo //上传至远程仓库 完成
##把分支代码整合在主干上
git checkout master //回到主干上面
git merge demo //选择合并的分支
git push origin master //上传至远程
分支提交了3个版本 只需要整合第一个版本到主干 怎么弄
##回到主干上
git cherry-pick id //指定分支提交版本的id
git push origin master //同步到远程
分支的删除
##回到主干上
git branch -d demo //demo为分支名称
#如果分支没有被合并不允许删除会有以下错误发生
error: The branch 'demo' is not fully merged.
If you are sure you want to delete it, run 'git branch -D demo'.
##强制删除
git branch -D demo //demo为分支名称
git push origin --delete demo //删除远程分支
版本回退
git revert -n 版本号
git commit -m "备注信息"
git push origin master
版本号我这里用的是码云
找到你所在的项目
这个就是所在的版本号拉~
基本git常用操作命令都在拉~