GIT配置及在AS中的使用
参考文章: https://blog.****.net/gao_chun/article/details/49817229/ 全面介绍Android Studio中Git的使用
https://blog.****.net/gao_chun/article/details/49817267 全面介绍Android Studio中Git 的使用(二)
https://blog.****.net/itluochen/article/details/52400018 Android开发之Android studio使用git(一)
1.git安装及配置
git官网下载git for windows
一路下一步安装后,运行GitBash
首先配置身份
git config --global user.name "Tony"
git config --global ueser.email "[email protected]"
配置是否成功,去掉账号密码,重新输入命令。显示出上述账号密码表示配置成功
2创建本地仓库
进入项目根目录,右键GitBash Here
在命令行中输入命令
git init
在根目录中生成名称为.git的隐藏文件夹,本地仓库创建成功
3远程仓库托管
3.1向已存在的远程仓库中提交代码
a 创建github远程仓库
b找到远程仓库地址,在git管理的目录下关联远程仓库
git remote add origin https://github.com/[username]/[project_name].git
c 在AS中,项目包名右键,
Git-Add
Git-Commit Dictionary
Git-Repository-Push
然后填写github帐号密码
到这里就完成里向远程仓库提交代码
3.2用AS自带的Git插件创建远程仓库
a 首先在AS中配置git帐号密码
Settings-Version Control-Git
b 然后创建远程仓库
VCS-Import into Version Control-Git
c 配置远程仓库
d 添加文件夹
e done.
4 具体git命令,参考
http://blog.****.net/liranke/article/details/6643169
git status //查看状态
git add . //当前路径下的修改文件
git add 文件名 //指定文件
git commit -m "注释" //添加注释
git push 本地 远程 //提交本地代码到远程
git reset HEAD file
//当git add后,又想重新修改文件,可以先用它。
git log --pretty=oneline RingtoneManager.java //查看修改记录
git log ./media/java/android/media/RingtoneManager.java //查看修改记录
git show 22f24422996393bebefa1da3a0ae937c1c4270d4 //查看某一次的修改点
5 git使用过程中程序报错
5.1 Push rejected: Push to origin/master was rejected
git bash错误描述
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/wwqby/test.git'
hint: Updates were rejected because the tip of your current branch is behind
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.
(提示:由于当前分支的尖端位于后面,因此更新被拒绝
提示:它的远程副本。 整合远程更改(例如
提示:'git pull ...'),然后再次推送。)
push失败,解决办法,参考
https://blog.****.net/u012934325/article/details/71023241
原因上项目建立时,需要先从gitbub上pull项目包,然后在这个包里修改的代码才能提交
首先备份项目代码到其他文件夹(留下.git文件夹),然后pull远程仓库到当前文件夹,把项目代码复制回来,然后重新add-commit-push,此时不会出现报错了
在VCS中能查看git的根节点(git root)和对应的remote路径(github远程仓库)
5.2 registered as a Git root, but no Git repositories were found there.
.idea
存储库中有一个文件夹不应该在那里。里面是与vcs相关的文件,可能包含一个不在你的电脑上的路径。
确保.git
在PC上的项目中有一个文件夹。如果不是,那么如果需要启用vcs工具,则必须正确克隆该项目。这里有一个关于如何做到这一点的链接:Git基础知识,搜索克隆现有的存储库然后,您需要关闭Android Studio,删除该.idea
文件夹,然后再次打开Android Studio。它会重新创建.idea
文件夹和问题应该解决。
5.3 初次使用git配置以及git如何使用ssh**(将ssh**添加到github)
https://www.cnblogs.com/superGG1990/p/6844952.html
5.4 解决无法Ping通Github
https://blog.****.net/u012552275/article/details/61654857
定位C:\Windows\System32\drivers\etc 目录下的hosts文件,记事本打开
在最后一行添加
192.30.253.113 github.com
192.30.252.131 github.com
185.31.16.185 github.global.ssl.fastly.net
74.125.237.1 dl-ssl.google.com
173.194.127.200 groups.google.com
192.30.252.131 github.com
185.31.16.185 github.global.ssl.fastly.net
74.125.128.95 ajax.googleapis.com
并保存
5.5 SSL certificate problem: unable to get local issuer certificate
提示SSL证书错误。后面用谷歌搜索了一下,发现说这个错误并不重要是系统证书的问题,系统判断到这个行为会造成不良影响,所以进行了阻止,只要设置跳过SSL证书验证就可以了,那么用命令 :
git config --global http.sslVerify false
5.6push失败告警如下
unable to access ' https://git.coding.net/xxxx/xxxx.git/ ': The requested URL returned error: 403
解决办法;https://blog.****.net/kuaiguixs/article/details/52094692
原因是因为push时的缓存账号密码不对
打开git命令行,
git config credential.helper
找到账号密码是否缓存
然后找到保存缓存的文件位置
git config --show-origin --get credential.helper
打开文件并删除下面的语句并保存
[credential] helper = xxx
然后重新缓存账号密码
git config --global credential.helper store
这个时候再push就成功了