git是我们常用的版本控制工具
下面推荐几个好用的链接
git中文网 git官网
1.安装
2.启动git bash如果电脑之前不确定是否安装git cd ~/.ssh
看下以前有没有生成的公钥私钥
3.ssh-keygen -t rsa -C"这里写你的邮件地址"
创建公钥私钥 不管别的全回车,全回车比较简单不然在ssh连接时莫名其妙的出些问题
4.把生成的.ssh 里的 id_rsa.pub文件内容 给GitHub或者自己服务器上的git或者gitlab等需要密钥的地方 一般.ssh在windows 里c:/用户/Administrator/ 里反正我就是这些文件夹里翻命令行也能查找到但是我懒
1 | git config --global user.name "填写自己的用户名" //设置git的@用户名 如果不带邮箱就是查看本机git的的用户名 |
下面是写git的命令行,git这东西有时候后用有时候不用老是会忘记录下防止忘记
记录一些git的常用命令
1 | git clone [URL] //拉取远程代码 |
git仓库和本地如果冲突
pull的时候出现了以下报错 一般发生这两个情况是因为库修改了本地也修改了合并的时候需要选取线上还是线下
error: Your local changes to the following files would be overwritten by merge:
src/page/homePageMange/adMange.vue
Please commit your changes or stash them before you merge.
或push的时候
error: failed to push some refs to ‘git@github.com:yangchao0718/cocos2d.git
hint: Updates were rejected because the tip of your current branch is behin
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push –help’ for details.
1 | git pull --rebase origin master //拉取项目合并两者 尝试拉取合并下 |
什么是–rebase
git pull = git fetch + git merge
git pull –rebase=git fetch+git rebase
rebase好处
想要更好的提交树,使用rebase操作会更好一点。
这样可以线性的看到每一次提交,并且没有增加提交节点。
merge 操作遇到冲突的时候,当前merge不能继续进行下去。手动修改冲突内容后,add 修改,commit 就可以了。
而rebase 操作的话,会中断rebase,同时会提示去解决冲突。
解决冲突后,将修改add后执行git rebase –continue继续操作,或者git rebase –skip忽略冲突。
1 | 解决问题本地和线上发生异常想本地替换线上 |
如果出现 (master|AM/REBASE)的情况是因为本地一直没推送一直在拉git记录出现问题
1 | git am --abort |