如何将现有的 Android Studio 项目连接到现有的 Github 存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26345407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to connect existing Android Studio project to existing Github repository
提问by johncorser
So I am new to Android development and Android Studio.
所以我是 Android 开发和 Android Studio 的新手。
I used Android Studio to create an Android project, and each time I wanted to commit the code to GitHub, I switched over to the command line and committed/pushed the code from there.
我使用 Android Studio 创建了一个 Android 项目,每次我想将代码提交到 GitHub 时,我都会切换到命令行并从那里提交/推送代码。
However, I realize now that Android Studio has it's own features for connecting to GitHub. I'd like to use those features.
但是,我现在意识到 Android Studio 有自己的连接 GitHub 的功能。我想使用这些功能。
Since the project already exists, I prefer not to just create a new GitHub repository from Android Studio and delete the old one. I just want to connect the existing GitHub repository with the Android Studio project.
由于该项目已经存在,我不想只是从 Android Studio 创建一个新的 GitHub 存储库并删除旧的存储库。我只想将现有的 GitHub 存储库与 Android Studio 项目连接起来。
How can I sync these up?
我怎样才能同步这些?
采纳答案by MartianKnight
I would view this thread if you want to create a new project.
如果您想创建一个新项目,我会查看此线程。
How do you synchronise projects to GitHub with Android Studio?
如何使用 Android Studio 将项目同步到 GitHub?
If this doesn't help then I would just delete your current(local) project and import from github.
如果这没有帮助,那么我将删除您当前的(本地)项目并从 github 导入。
http://teamtreehouse.com/library/android-tools/git/pulling-down-github-projects-to-android-studio
http://teamtreehouse.com/library/android-tools/git/pulling-down-github-projects-to-android-studio
I would recommend staying with command line. It is great practice. View link below for more information.
我建议继续使用命令行。这是很好的做法。查看下面的链接了解更多信息。
回答by Suragch
Connecting existing Android Studio project to existing Github repository
将现有的 Android Studio 项目连接到现有的 Github 存储库
If your local project is newer than the one on GitHub, then you can temporarily move it to another location, import the GitHub version into Android studio, delete these old files, and copy in the new files. Then push the changes back to GitHub. The directions to do all of this are here. This takes some command line work, but after it is set up, you can do any future commits right in Android Studio.
如果你的本地项目比 GitHub 上的新,那么你可以暂时将其移动到另一个位置,将 GitHub 版本导入 Android Studio,删除这些旧文件,然后复制新文件。然后将更改推送回 GitHub。执行所有这些操作的说明在这里。这需要一些命令行工作,但在设置之后,您可以直接在 Android Studio 中进行任何未来的提交。
Committing and pushing to GitHub from Android Studio
从 Android Studio 提交并推送到 GitHub
After making a change, you can commit it by selecting the app folder in the Android view (or the main project folder in whatever view you are using). Then go to VCS > Git > Commit Directory....
进行更改后,您可以通过选择 Android 视图中的 app 文件夹(或您正在使用的任何视图中的主项目文件夹)来提交它。然后转到VCS > Git > Commit Directory...。
Add a commit message and click Commit.
添加提交消息并单击Commit。
Then go to VCS > Git > Pushto push your changes to GitHub.
然后转到VCS > Git > Push将您的更改推送到 GitHub。
That's it.
就是这样。
回答by Ian Neumann Sánchez
Maybe it is a little bit late, but if it helps to someone here is what I do in command line:
也许有点晚了,但如果它对这里的某人有帮助,那就是我在命令行中所做的:
cd <proyect folder>
git init
git remote add origin <link to repo>
git fetch origin
git checkout master
note: if there are commits on the repo it may require you to remove conflicting files
注意:如果 repo 上有提交,则可能需要您删除冲突文件
git add --all
git commit -m "<message>"
git push
回答by Robert Wildman
This may help but I find it easier to the use the Git Hub desktop software which can be found here for mac: mac.github.com and here for windows: windows.github.com.
这可能会有所帮助,但我发现使用 Git Hub 桌面软件更容易,Mac 可在此处找到:mac.github.com,Windows 可在此处找到:windows.github.com。
Based on my use of the mac one.
基于我对 mac 的使用。
回答by triplejay
I was having the same issue and was looking for a solution. The answers provided on this thread are useful as git goes, but didn't answer my question. After some tinkering around I found my own solution. I cloned the git repository that I wanted to merge my existing Android Studio Project with. I copied over the '.git' folder from the cloned repository to my main Project folder for Android studio. I staged files and committed them, and pushed them to the existing git repository. Doing so updated my git repository with my existing project. I didn't have to create a new Git repository.
我遇到了同样的问题,正在寻找解决方案。该线程上提供的答案在 git 中很有用,但没有回答我的问题。经过一番修补后,我找到了自己的解决方案。我克隆了我想合并我现有的 Android Studio 项目的 git 存储库。我将“.git”文件夹从克隆的存储库复制到我的 Android Studio 主项目文件夹。我暂存文件并提交它们,然后将它们推送到现有的 git 存储库。这样做用我现有的项目更新了我的 git 存储库。我不必创建新的 Git 存储库。
Make note that you will have to set up your "remotes" as you would have to do with command line. Your remote will be the same URL used to clone the repository.
请注意,您必须像使用命令行一样设置“遥控器”。您的远程将与用于克隆存储库的 URL 相同。
回答by Kshitij Agarwal
Warning:This not might be the answer that you are thinking of but it will surely help you get an idea of how things work around here.
警告:这可能不是您正在考虑的答案,但它肯定会帮助您了解这里的工作原理。
Background
背景
I'm also new to Android and the mentor of my course (from which I was learning Android Development) had a habit of creating new projects in Android Studio whenever a new topic started, let it be Java Basics, Intents, Fragments or backendless. I was familiar with Git and it's working. So an idea struck in my head to create a singlerepository with multiple branches and keep all the projects in respective branches. Quite simple right, but things don't work in that fashion.
我也是 Android 新手,我的课程导师(我从中学习 Android 开发)有一个习惯,每当一个新主题开始时,都会在 Android Studio 中创建新项目,无论是 Java 基础知识、意图、片段还是后端。我熟悉 Git 并且它正在工作。因此,我的脑海中闪过一个想法,即创建一个具有多个分支的单个存储库,并将所有项目保存在各自的分支中。很简单,但事情并非如此。
Research
研究
I had looked for all the answers on whatever blogs, videos or answers on StackOverflow was present and had tried all the methods. Still, I was not able to get what exactly I wanted. In the Android Studio, when we create a new project, n number of files are created, and all of them are important.
我在 StackOverflow 上的任何博客、视频或答案中寻找所有答案,并尝试了所有方法。尽管如此,我还是无法得到我想要的。在 Android Studio 中,当我们创建一个新项目时,会创建 n 个文件,它们都很重要。
I tried to add an existing repository into Android Studio. Firstly we cannot directly add the project into a sub-branch. Secondly, the project will not get merged, I don't know why. Link
I also tried to import the existing project into Android Studio. The projects will not contain all the files. Link
我尝试将现有存储库添加到 Android Studio。首先我们不能直接将项目添加到子分支中。其次,项目不会被合并,我不知道为什么。关联
我还尝试将现有项目导入 Android Studio。项目不会包含所有文件。关联
Solution
解决方案
The only solution which I could find was to create a new repository every time and we can upload the changes into it. Believe me, its the best way to keep things organized. Now there comes a problem, with so many repositories, it's hard to keep a track of all of them. So I came up with my own naming conventions for the repositories:
我能找到的唯一解决方案是每次都创建一个新的存储库,我们可以将更改上传到其中。相信我,这是让事情井井有条的最佳方式。现在出现了一个问题,有这么多存储库,很难跟踪所有这些存储库。所以我想出了我自己的存储库命名约定:
Android-Practice-<Project/topic name>
- just by the name we can recognize it if we need to refer anything in future and while searching for it, they will all be in a single placeAndroid-Project-<name>
- If we are developing our app we can use this, so all projects will be present in a single place.
Android-Practice-<Project/topic name>
- 如果我们将来需要引用任何东西,我们可以通过名称识别它,并且在搜索它时,它们都将在一个地方Android-Project-<name>
- 如果我们正在开发我们的应用程序,我们可以使用它,因此所有项目都将出现在一个地方。
PS - I like my files to be organized in a proper hierarchy order.
PS - 我喜欢我的文件以适当的层次结构顺序组织。