Git操作指南
一、Git的配置
1.设置用户名和邮箱,在这里我理解的以后所有的git拉取都会使用此账号
git config --global user.name "yourname" // 你的用户名
git config --global user.email "your_email@youremail.com" // 你的邮箱
2.生成密钥(SSH Key)
此密钥需要填入Gitee个人主页中的密钥里面
ssh-keygen -t rsa -C "your_email@youremail.com"
二、创建版本库
1.输入以下命令初始化仓库,若出现:Initialized empty Git repository in E:/** /**/.git/ 则表示创建成功[注意:此时会生成一个.git目录(隐藏目录)]
git init
2.连接远程仓库
git remote add origin git@github.com:xxx.git
3.从远程仓库pull文件
git pull origin master
4.将本地文件push到远程仓库
git status 查看工作目录的文件是否改变
git add <file> 将文件添加到暂存区
git add . 将所有文件添加到暂存区
git commit -m " 备注信息" 提交更改,添加备注信息(将暂存区提交本地仓库)
git push origin master 将本地仓库的文件push到远程仓库(若 push 不成功,可加 -f 进行强推操作)
会出现的问题
Please commit your changes or stash them before you merge
当本地分支和远程修改了同一个文件代码,pull远程分支的代码的时候会出现文件冲突
出现这个错误 Please commit your changes or stash them before you merge.
可以先将当前的内容存储起来,git stash就可以把当前内容存储在栈内
git stash 后再 git pull下新代码
然后再把存储在栈内的内容放出来 , git stash pop
git stash list 可以查看临时存储栈内的列表