I'm new to Git and Github and I'm trying to figure out how to push to the root directory on Github from Eclipse (Windows).
I have created a Github project called MyProject. MyProject is an Android project with the usual Android directory structure:
MyProject
src (+ res, assets, etc)
From Eclipse I push my Android project called MyGame to MyProject. MyProject now becomes a sub-directory to MyGame, so that the readme file in MyProject isn't visible unless the user first clicks on MyProject on Github to drill down one level in the directory hierarchy.
How can I push MyGame so that its contents (src folder, res folder, readme) become visible at the root level in the Github project.
Update: I tried using command line:
git remote add origin git#github.com:username/reponame.git
git push origin master
This has the same result, on Github the directory hierarchy is:
MyProject
MyGame
src
How can I make it
MyProject
src
?
I believe your problem may be that your git repo in Eclipse is in the parent folder of the project. What you need is for your git repo to be in the project folder.
Now, Eclipse seems to recommend that Git repos be set up in the parent folder of their projects. I am guessing that this is so that later related projects that may be needed can be easily added to the git repo. If you're not worried about that, and just want it to work as you described, see below.
Note that I'm running Ubuntu Linux, and so my Eclipse and desktop will probably look different from yours.
First we're going to find out if my guess as to the problem is correct:
Open the "Git Repository Exploring" perspective in Eclipse.
Look at the "Git Repositories" view. See if the path given for your repository is pointing to the folder containing your project. If it is, continue with the instructions below.
If your repo is in the folder above your project, then the problem shapes up like this: Git will recreate all the paths in your repo relative to the repository itself when you push it to GitHub. If it is in the folder above your project, then all the paths will include the folder containing your project. So, you'll need to move your repo into the folder containing your project. I'll describe the steps to achieve that below.
To begin, you'll want to make sure you don't have any uncommitted changes, or any stashed changes (if you don't know what stashed changes are, don't worry about them).
As a matter of caution, you may want to create a complete copy of your current code & repository at this point if it's at all important.
Open Windows Explorer and navigate to the folder containing your git repo, per the path given in the "Git Repositories" view.
At this point, you may want to close Eclipse, to avoid changes startling it (they shouldn't, but "you never can tell with bees!")
If you can see a .git folder in Windows Explorer, then go on to the next step. If not, you'll need to show hidden files. http://windows.microsoft.com/en-US/windows7/show-hidden-files gives instructions for Win7.
Now you should be able to see a .git folder. Copy this into your project folder.
Start Eclipse (if you closed it) and open the "Git Repositories" view again.
Click the button to add an existing local git repository. Choose the project folder.
Go back to the normal Eclipse Java perspective. Right-click your project and choose Team > Disconnect to temporarily stop heeding the old repository.
Right-click on the project again and choose Team > Share Project.... When prompted for a repository, check the box to use the one in the project/parent folder. In the view below, check the box of the one which is directly within the project folder (it will probably have one dot next to a folder.) Then click the Finish button.
Now you'll probably have a lot of catching up to do. Git will believe that you have deleted every file in your project and replaced it with a file with one less layer of directory path. You'll need to commit all those changes to get a clean repo.
Push the changes from step ten to GitHub. Check that it looks as you expect.
I hope this helps. Please comment if something's unclear or there's another issue. Please make sure to have a backup before you try this... I've not tested it entirely, and I don't want to cause any unneeded grief.
Related
With a friend we were a long time trying to work with Git and Android Studio, but we had a problem (we are very new to git and Android Studio, we started a couple of days ago on both issues).
What happens to us is that, for example, if I cloned the git repository and I try to make a merge, then the button to execute is grayed out and it doesn't let me compile or run it, also if I display the project structure as Android or Packages I see nothing, I can only see the files in Project, Project Files, Recent Changes, etc...
I will explain in detail everything we've done.
First, the repository looks like this (p and c are just the initials).
x (c)
/
x (master)
\
x (p)
Master has the first initial commit with .gitignore and README.md, nothing more, while we (me who created the branch p, and my friend who created the branc c) have just one commit each one with executable projects, although I'm not interested in joining what I've done with what my friend has done, I just want to start a new project of Android Studio with what my friend has made.
So I start Android Studio, "Check out project from Version Control -> GitHub", I put my key and choose the repository I want to clone, after that AS ask me if I want to create a new project and I click Yes.
I hit next until the new project is created and here I can see all the branches that we have created on GitHub.
After that I make a local branch to try to work with the project of my friend, with the option "Git branches -> New Branch" and calling it p, which moves me to this local branch automatically.
After that, I choose the Merge option of the remote branch origin/c, and I get a merge failure, that says "Some untracked working tree files would be overwritten by merge. Please move or remove them before you can merge.", I choose the option to view the files and it shows me these.
Since my project is completely new, and the project that my friend uploaded worked fine for him, I just deleted these files with the red bar that my mouse is pointing and after that a message appears that says there is no difference now.
Finally, after that, I go again to the merge option of the remote branch c, and a conflict message appears, which is on the .gitignore file, in my case I put to "Accept Theirs", and I see the message that the merge was correctly.
And now it is when I see that the button to execute is grayed and if I display the project structure as Android I see nothing, I can only see the files in Project, Project Files, etc...
I think it should be something super basic what I'm asking, but we (me and my friend) had never worked with git or android studio and now we are asked to make a project using them.
This is because you have added .idea folder in your git repository.Sample .gitignore file can be like this
build/
.gradle/
*.iml
.idea/
src/main/gen/*
*~
*.swp
local.properties
*.keystore
*.keystore.password
Also you need to delete this folder from git repo. You can use below command
git rm -rf .idea/
git commit -m "deleting .idea, updated .gitignore"
Then try to merge
Followed by #Akhil's answer, click "Make Project" icon to awake your Run button. Sometimes this button makes Android Studio recognize your project runnable again.
I'm migrating my Android project from Eclipse to Android Studio. I use Subversion and am wondering how I can migrate my SVN to the new file structure used in Android Studio without losing my history.
Thanks for any help!
Posting this because it might help someone else.
I ran into the same problem as well. #user714965 was inspiring but didn't solve my problem because I couldn't figure out how to get SVN recognize that I moved a file from the original folder to the new structure in my working copy.
For the following, you will need TortoiseSVN or a similar SVN GUI client to do this.
Here is what I did:
Commit the Eclipse project last changes into the SVN repo.
Open Android Studio and use that to import the Eclipse project working copy.
Android Studio will nicely convert the Eclipse project into a Android Studio/Gradle project. Let's call this project "PrjGradle".
Open the converted Gradle project folder window and keep it one side of your screen
Go into your SVN repo where you have your project (using TortoiseSVN).
Backup your current trunk into a branch or a tag and call it "final_eclipse" or whatever.
Now, mirror the folder structure of the newly converted Gradle project on your local machine directly on the TortoiseSVN Repo Browser window. Meaning, look at how the directory is structured in "PrkGradle" and create/delete/rename folders directly on the trunk repository. This will be painstakingly tedious but you have to bear with it if you want to preserve your SVN history.
When you move files around (not copy) directly on the repo, the history of the files remain intact.
Once you complete, check out the restructured directory into your local machine. Let's call this "NewPrj".
Use a suitable Folder compare program (such as Beyond Compare) to synchronize missing items (such as build.gradle, .iml files, etc.)
Rename your converted project to "PrjGradle_old", and rename the newly checked out project (NewPrj) to "PrjGradle".
Open "PrjGradle" in Android Studio. That's it!
Hope it works out.
I don't know the differences of both file structures. But it would try it this way:
Check out your project (maybe better use a client like TortoiseSVN)
Build the new file structure (new folders)
Commit
Move the files from the old structure to the new
Commit (check the commit dialog if there are move actions only!)
Delete old folders which you don't need anymore
Commit
SVN will recognize these move operations. You will see if it works by the operations in the commit dialog. If there are "delete"/"new" actions something went wrong there should only be "move" actions.
I was working on an Android project in Eclipse and I then decided to Git it. Being new, instead of creating a local repository in the parent of the project, I ended up creating it in C:\Users\Little\.git\LocalRepository.
Now, I am facing a lot of problems in my Android project; specifically with adding user libraries to my build path.
Based on this answer here:
Eclipse will not recognize project as library (ActionBarSherlock/ViewPagerIndicator)
I have imported all the user libraries to my workspace. However, my project itself is in a different folder and hence I am stuck. There is also a comment on the answer which says:
Thanks. In my case, I forgot that my project was imported from git and
was physically located in another folder than all other projects.
I believe I have to do the same. How do I get the project from local repo to my workspace?
May be below command help someone to get rid of same issue with command line :
Step 1 : To make sure that ur git does not contains any local changes do :
git status
make sure here there is files where u have changes something and is in red color
Step 2: To check when and how commited last do :
git log
Step 3 :
rm -rf .git
Make sure u just take backup.
Step 4 : do git clone to dir u need :
git clone ssh://firstname.lastname#xx.x.xx.xx:xxxxx/project_name
I am using Subclipse to connect to a SVN repo where I have check in my Android project. I need Subclipse to pickup my R.java too, (to make the long story short, some team members need the whole thing to generate jni headers).
So my question is how to get subclipse to pick it up? I tried Window->preferences. Also Team -- show properties (it is blank, no svn:ignore property)
The gen folder is in the repository, but empty.
How to do it?
EDIT: Thanks to an answer from Chris, I right-clicked on the package-name inside the gen folder and clicked Team --> Add to version control. I got a warning & when I clicked OK, it did seem to add the missing package.
However, inside the repo, the gen directory is still empty. R.java still does not show the little repo icon that other source files have. I committed the gen folder, refreshed the repo, even restarted eclipse. Same thing
If I retry Team --> Add to version control on that package, I get an "already in repo" error. But cannot see it there :-( . Not sure why.
just right-click the gen folder and use Team->Add to Version Control, that should work i think
I'm developing an application that is supposed to run on both Android as well as regular Java SE.
I have an eclipse project called foobar-core which contains code that is used both by the Android and the SE version. I have another project called foobar-android, which contains all android-specific code.
I need to reference some of the foobar-core code in the foobar-android project, so I added foobar-core to foobar-android in Settings -> Java Build path -> Projects -> Required projects on the build path. This works fine, as I can use code from foobare-core in foobar-android now.
Here's the problem: Both foobar-core and foobar-android are independent git repositories, which means they both have a .git subdirectory. Now I get a lot of warnings on the "Console" tab whenever I compile foobar-android. They look like this:
/foobar-core/src/.git/HEAD conflicts with another file already put at .git/HEAD
/foobar-core/src/.git/config conflicts with another file already put at .git/config
/foobar-core/src/.git/description conflicts with another file already put at > .git/description
/foobar-core/src/.git/hooks/applypatch-msg.sample conflicts with another file already > put at .git/hooks/applypatch-msg.sample
How can I tell Eclipse to ignore the .git files when importing sources from the foobar-core project?
Even if you just have a single git repo, it is good to ignore the .git directory because other Eclipse will waste a lot of time looking at the files in it even though it never needs to do anything with them. In particular, when you do a project wide search, Eclipse will search through the all the files in .git directory, which takes a long time and ends up showing you lots of duplicates (or almost duplicates, older versions of the same file with the same search term found).
I think the Eclipse git extensions probably take care of this but if you don't want to install yet another extension, the best way I have found it to tell Eclipse that all .git directories are "Derived", which seems to make Eclipse somewhat ignore the contained files.
You do this by switching from the Package Explorer view to the Navigator view, where you should see the .git folder. Right-click on the .git folder, selecting properties, selecting Resource from the settings selector, and then checking the "Derived" box.
I would setup a .gitignore file that simply ignored the entire foobar-code project.