標籤:android studio git
在Android studio下使用git
參考:http://www.tuicool.com/articles/V7j6Zfq
1.準備安裝 git :
sudo apt-get install git-core
參考:https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-12-04
在Android studio中設定git外掛程式:File->Setting->Version Control->Git, 然後可以點擊Test測試一下,如:那麼你就設定成功了。
2.初始化git項目(git init)
操作如下:VCS->Enable Control Integration->Select "Git".
3.為git添加remote
在這一步中,studio沒有為我們提供可視化的GUI,在terminal下將目錄切換到項目的目錄,然後輸入git添加remote的命令,例如:git remote add origin "https://github.com/xxx/xxx.git".
4.將代碼添加到VCS(git add)
選中要提交的檔案->VCS->Git->Add
5.提交變化(git commit)
VCS->Commit Changes在提交的時候可以選擇Commit and Push,就可以直接push到伺服器。
在第一次提交時可能會出現 “Nothing to push” 的問題
參考:http://stackoverflow.com/questions/15913669/nothing-to-push-error-in-intellij-with-git
因為第一次提交,repository為空白,沒有master,你需要 在push介面中最下方的checkbox上挑勾,選擇"Push current branch to alternative branch"並且填寫為master即可,這樣就能建立master,以後push就不需要checkbox了,除非添加新的分支。
When you push to an empty repository you must set on checkbox "Push current branch to alternative branch" and choosemaster as that alternative.It‘s because master is not created yet (repo isreally empty). But doing this way you can pretend to initialize the repository.
While that checkbox is off and repository is empty, IDEA can‘t push, because its interface must be safe and he will not just create new brach if the one in which you pushed last accidentally disappeared (or just not exist). You must force that "branch creation"
“Nothing to push” error in Android studio with Git