社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
在Linux下用过git,现在重新转回android,也从eclipse跳转到android studio,试试吧~
参考:http://blog.csdn.net/wh_19910525/article/details/8128916
1、Git —The stupid content tracker, 傻瓜内容跟踪器,是一个由Linux内核开发者Linus为了更好地管理Linux内核开发而创立的分布式版本控制软件。
2、GitHub — GitHub这个网站为每个用户提供服务器托管其Git代码库,免费空间为300M。注册GitHub后你就会有0.3G的免费空间,不过只能创建公开项目。
3、为什么不选CVS或SVN
Git提交/克隆/pull/push的速度更快
Git的绝大多数操作都可以在本地完成,不需要频繁连接服务器。
1、
ssh-add id_rsa
Could not open a connection to your authentication agent.
解决方法:ssh-agent bash(个人不是很懂原因~)
2、
Push failed
Failed with error: fatal: Could not read from remote repository
解决方式:这个问题太坑了,不是权限也不是密钥有啥问题,找了好久,重新弄ssh也不行,最后,http://bbs.csdn.net/topics/390909877感谢。我打开了项目下的.git目录下的config文件,不知道为啥我的
[remote "origin"]
url = git@github.com:username/NoteApp.git
fetch = +refs/heads/*:refs/remotes/origin/*
url链接前面多了spa几个字母,我天,难道路径去做了一个spa。。。。。。折腾了我好久。
我测试结果和这个不同,但是也是代表成功。
$ssh -v git@github.com
如果配置正确,显示
ERROR: Hi xxx! You've successfully authenticated, but GitHub does not provide shell access
Connection to github.com closed.
$ ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts.
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
$ git config --global user.name "name"
$ git config --global user.email your_mail@gmail.com
参考:http://jingyan.baidu.com/article/6766299761b1be54d51b84a0.html
1、准备,下载git到你的电脑上,下载地址: http://git-scm.com/downloads
安装,直接下一步下一步就好,记得下载位置就好,配置的时候要用
2、在studio中设置git插件:File->Setting->Version Control->Git,添加您刚刚安装的git地址目录,例如: C:Program FilesGitbingit.exe , 然后可以点击Test测试一下,如下图:那么你就设置成功了。
3、android studio如何使用git
(1)初始化git项目(git init),操作如下:VCS->Enable Control Integration->Select “Git”.
(2)为git添加remote,在这一步中,studio没有为我们提供可视化的GUI,得用Git工具了。找到并打开git安装目录下面的Git Bash,将目录切换到项目的目录,然后输入git添加remote的命令,例如:git remote add origin “https://github.com/xxx/xxx.git“.(ssh也行)
(3)将代码添加到VCS(git add),选中要提交的文件->VCS->Git->Add,
(4)提交变化(git commit),VCS->Commit Changes,如下图,在提交的时候可以选择Commit and Push,就可以直接push到服务器。
(5)Git Push,VCS->Git->Push.
==》上面总结:
git add <.> <dir> <file> //将变更放入暂存区
git commit - m "intro" //放入本地git版本库中
git push origin <origin_name> //推送至git远程仓库
(6)如果服务器上代码更新,让代码在本地也更新pull下来。
最后,如果要是clone project到studio,如下图
注意:clone是clone一个本地不存在或者是新建一个目录的,不能是放在已存在目录
背景:android项目中,不是所有的文件都需要加入到版本控制中。比如:bin 目录和 gen目录下的文件都是会自动生成的,我们不应该将这部分文件添加到版本控制当中,否则有可能会对文件的自动生成造成影响。
解决方式:Git 提供了一种可配性很强的机制来允许用户将指定的文件或目录排除在版本控制之
外,它会检查代码仓库的根目录下是否存在一个名为.gitignore的文件,如果存在的话就去一
行行读取这个文件中的内容,并把每一行指定的文件或目录排除在版本控制之外。注
意.gitignore中指定的文件或目录是可以使用“*”通配符的
如果你使用的是as,目录下会发现有一个.gitignore的文件,默认配置
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
1、使用git控制的as项目,关闭重新打开后出现下面的错误。
Invalid VCS root mapping The directory D:asworkspacexxxAppxxxApp is registered as a Git root, but no Git repositories were found there.
解决方法:
选中红色错误地方,点击减号。不过我没查到为啥,这是试一下成功的。
1、打开git bash 进入项目目录。
git clone https://github.com/tony-green/coolweather.git
不过我的出错了,fatal: I don’t handle protocol ‘https’,查了好多都没解决,最后换成SSH方式。配置问题?谁懂?
git clone git@github.com:zhanghaixia/CoolWeather.git
参考网上答案,没测试
1、 git clone looks for and then the . Normally you can skip the options, but with the latest version of the Windows git bash I’ve had to add an option for the git clone https… to work.
If you aren’t using options just use git clone -q https…. for the “quiet” option and it should work fine.
2、You are probably entering the command git clone http://repo/url in the place where it expects only the url, i.e http://repo/url
2、拷贝克隆的文件到项目根目录
因为克隆下来的会在当前目录生成一个以最尾巴的名称为文件名的文件(比如上面CoolWeather),拷贝到项目根目录。(包括了LICENSE和 README.md以及最重要的隐藏文件.git)
3、把 CoolWeather 项目中现有的文件提交到 GitHub上面
git add .
然后在本地执行提交操作:
git commit -m "First commit."
最后将提交的内容同步到远程版本库,也就是 GitHub 上面:
git push origin master
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!