一.关于git |
中文帮助网站: |
http://git-scm.com/book/zh/v1/Git-%E5%9F%BA%E7%A1%80-%E5%8F%96%E5%BE%97%E9%A1%B9%E7%9B%AE%E7%9A%84-Git-%E4%BB%93%E5%BA%93 |
电子书: |
https://progit2.s3.amazonaws.com/zh/2014-11-16-d449e/progit-zh.138.pdf |
二.在github建立仓库的正确流程 |
1.安装git及添加信息到github的ssh key |
安装Git-1.9.4-preview20140929.exe |
ssh-keygen -t rsa -C "winstongit@gmail.com" |
eval `ssh-agent -s` |
ssh-add ~/.ssh/id_rsa |
复制id_rsa.pub的内容到https://github.com/settings/ssh |
ssh -T git@github.com 验证ssh是否成功配置 |
配置用户信息: |
git config --global user.name "winstongit" |
git config --global user.email "winstongit@gmail.com" |
2.在github服务器上建空仓库 |
3.克隆仓库并配置本地关联 |
git clone https://github.com/winstongit/udacityapp.git udacode |
cd udacode |
git remote add uda https://github.com/winstongit/udacityapp.git |
git config --global credential.helper wincred //保存密码,避免每次推送都输账户和密码 |
4.拉取远程仓库分支 |
git clone https://github.com/winstongit/Sunshine.git test |
git branch -a |
git fetch origin xxx:xxx |
git checkout xxx |
(或者git fetch origin xxx然后git checkout -b origin xxx或git checkout origin xxx) |
5.添加远程分支 |
//git remote add uda https://github.com/winstongit/udacityapp.git |
git branch xxx |
git checkout xxx |
git rm -r * |
git add --all . |
git commit -m "this is for test" |
git push -u origin xxx |
6.删除远程分支 |
git remote add uda https://github.com/winstongit/udacityapp.git |
git branch -d -r origin/xxx |
只能删除本地的远程分支显示,目前还是从github网站删除分支方便. |
7.修改远程远程分支的名称 |
git branch -m -r origin/v1.01 origin/v1.02 |
8.复制的仓库做新库无法比较之前的分支代码 |
git log --reverse newrepo |
git log --reverse master |
If you redo your commits on top of the original history, you should then be able to compare the branches. |
There are several different ways that you can redo your commits, including |
git rebase --onto |
git cherry-pick |
9.github代码对比 |
低版本在前,高版本在后,并保证是2个分支是同1个commit。 |
否则会出现There isn't anything to compare.gh-pages and v2.00-list-item are entirely different commit histories. |
三.使用中遇到的问题 |
问题1.生成的ssh秘钥找不到 |
解决方法: |
在~/.ssh目录下 |
问题2.Could not open a connection to your authentication agent |
解决方法: |
eval `ssh-agent -s` |
ssh-add ~/.ssh/id_rsa |
问题3.git clone git@github.com:winstongit/Sunshinework.git失败,报错The authenticity of host 'github.com (192.30.252.130)' can't be established. |
解决方法:修改仓库访问方式,ssh改https。 |
git@github.com:winstongit/Sunshinework.git为https://github.com/winstongit/Sunshinework.git |
问题4.fatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists. |
解决方法: |
github建立对应名称的仓库 |
git push -u origin master |
问题5.error: src refspec master does not match any.error: failed to push some refs to 'https://github.com/winstongit/Sunshinework.git' |
解决方法: |
没有添加远程仓库,导致无法推送成功 |
git remote add origin git@github.com:winstongit/Sunshinework.git //连接远程github项目 |
问题6.fatal: remote origin already exists. |
解决方法: |
存在多个远程仓库的本地映射,删除远程仓库的本地origin映射 |
git remote rm origin |
问题7.You've successfully authenticated, but GitHub does not provide shell access. |
The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in Gemfile. |
解决方法: |
第一个警告没关系,不影响使用 |
第二个警告是linux的代码结尾空格符和windows不同,要剔除这个警告使用如下命令 |
git config core.autocrlf true |
问题8.无法删除本地当前分支 |
git branch -d lesson_v1.1 |
问题:error: Cannot delete the branch 'lesson_v1.1' which you are currently on |
解决方法: |
必须先切换到其他分支,再删除lesson_v1.1的分支 |
git checkout master |
git branch -d lesson_v1.1 |
问题9.无法删除带子文件的文件夹fatal: pathspec 'weathercastv1.0' did not match any files |
git rm -r weather2.0 fatal: pathspec 'weathercastv3.02' did not match any files |
解决方法: |
git rm -rf *无法删除文件夹,说明文件夹并没有加入git管理 |
rm -rf weathercastv1.0 |
问题10.查看代码是否是最新版本 |
解决方法: |
git log 显示提交的commit记录 |
git status 查看代码和服务器的差别 |
git diff |
git --help |
问题11.无法切换分支 error: Your local changes to the following files would be overwritten by checkou t: |
解决方法: |
git checkout -f master |
问题12.不想提交所在分支的修改,希望清空分支或希望代码复位 |
解决方法: |
删除所有:rm -rf * ; git add --all . |
清空 git reset --hard head^^(复位到本地仓库的最原始版本,跟服务器对应的版本内容可能不同,不大建议使用) |
如不是最新版本则 git pull. |
问题13.无法开启模拟器 |
解决方法: |
c盘空间严重不足,挪到e盘。修改androidstudio\bin\idea.properties |
idea.config.path=E:/androidlearn/androidstudio/.AndroidStudioBeta/config |
idea.system.path=E:/androidlearn/androidstudio/.AndroidStudioBeta/system |
idea.plugins.path=E:/androidlearn/androidstudio/plugins |
idea.log.path=E:/androidlearn/androidstudio/log |
问题14.模拟器太慢, |
解决方法: |
如果使用androud studio没有用apple电脑或者win7会有点吃亏。特别是使用模拟器的话没有硬件加速会很慢,最好使用真机调试,减少系统的消耗。 |
使用真机仿真。最新的模拟器插件是genymotion。功能很全,没测试过。 |
adb connect 192.168.1.151 |
adb remount |
问题15.无法下载所有分支 |
解决方法:没解决,只能单独下载对应的分支? |
问题16.无法删除github远程分支,git branch -d -r origin/x1 origin/x2 origin/x3无法删除 |
解决方法: |
github还需要手动删除对应的分支 |
问题17.修改了git ignore文件,无法正确checkout文件 |
解决方法: |
最终使用google课程源码中的.gitignore文件,确认参数齐全。 |
问题18. |
fatal: Cannot update paths and switch to branch 'origin' at the same time. |
Did you intend to checkout '4.11-add-content-provider-to-contract' which can not |
be resolved as commit? |
git fetch origin 4.11-add-content-provider-to-contract:4.11-add-content-provider-to-contract |
解决方法: |
不能使用git fetch origin origin/xxx |
github说明
最新推荐文章于 2024-08-28 15:23:49 发布