Can't Remove git Sub-Module - android

I am fairly new to git and had not really utilized the command-line interface until recently. I was trying to start a new private repository on github using Android Studio and made a mistake. I ran the command:
git remote add origin [github.com/location]in two places, one of which was the root folder of the project, and one of which was subfolder containing the java class files. When I tried to add and commit all the files, it wouldn't include the subfolder, giving me the error: fatal: Pathspec 'file' is in submodule 'app/src/...' Before thinking through what I was doing, I tried removing the .git folder from the subfolder. There is no .gitmodules file in the .git folder in the root project folder, so there are no submodules to remove. I'm not sure if this is enough information to go off of so I'm sorry in advance if this sounds vague, but I was hoping someone could help me clear whatever is causing this so I can add this subfolder to the main project and commit it. Thank you!
FIXED:
I figured out that I needed to remove the subfolder and re-add it thusly:
git rm --cached dirname
git add dirname
I also had to get rid of the index.lock file in the base project .git folder in order to do this.

Did you check on the github repo if there is no conflict?
Do you try to commit locally or commit and push?
Did you try to clone the project on a another location?
If you use Windows or Mac, I have a nice tool for git repository Source Tree

Related

Should I version app/build files in Android Studio?

I'm new to Git and Android development and I could not find an answer to this question.
When I build a project in Android Studio a lot of files are created in the folder app/build.
I guess I don't need that files, but before ignoring them in the .gitignore, I would like to be sure to not mess my repo since from the first commit :D
I checked this question, but I cannot see in the example .gitignore the folder app/build.
Should I add it to my .gitignore?
P.S. I'm using Android Studio 2.2.3, if relevant
I guess I don't need that files, but before ignoring them in the .gitignore I would like to be sure to not mess my repo since from the first commit :D
You don't need build files in your repo.
Usually .gitignore file contains /build.
I checked this question but I cannot see in the example .gitignore the folder app/build.
You can place another one .gitignore file to app directory, the content of this file also contains /build.
/project
.gitignore
/app
.gitignore
If I copy/past the example .gitignore (which contains build/ ) in the app/ folder, build files are not ignored.
That would be because those files are already tracked.
Try:
cd app
git rm --cached -r build/
git add .
git commit -m "record build content deletion"
git push
Then app/build will be ignored.
Have a look at gitignore.io for generating gitignore files

How to keep library files out of github in android?

How do I keep library files out of my github repo yet still have them work if someone downloads my code? I get about 600 "changes" each time I make a small change to my code! Also if it changes anything I am using github desktop (not through cmd). Thanks in advance!
you need to use git ignore to ignore your build folders from updating with git. git ignore helps you to make a blacklist of items you dont want to commit everytime.
you can see how to make a git ignore file in below:
How to create .gitignore file
I guess you see changes to the workspace files modified by Android Studio / IntelliJ in the .idea folder. These files are automatically re-generated if you remove them and should be private to each user, i.e. not uploaded to source control with git.
Step by step fix
Close Android Studio
Remove the .idea folder in your project root (or backup elsewhere for now)
in the .gitignore file in the root of your project, add a line containing just .idea to ignore the folder and its content when you use git
Commit changes to git which should be the removal of the .idea folder & the .gitignore change
Open Android Studio, re-import you project
.idea folder is now regenerated and private to each git user
Run git status to verify

Commit Folder Android Studio Project

Not all folder in project uploaded to github as default. Is it ok?
such folder build not uploading to git as default. any reference about it? should I leave it or including folder build too?
How to do that?
Thank you
By default build/ is part of .gitignore that is why it's not been uploaded on remote. This is perfectly fine.
Even if you wish to include it into remote repository.
git rm --cached .
git add -A
git commit -m "Message of your choice"
git push origin branch_name
Android projects now are created with a .gitignore file. gitignore specifies intentionally untracked files to ignore. So one of the files that are specified in gitignore is the build folder. Therefore when you commit, it doesn't get uploaded to git as default. You should leave it alone but if you want to, you can simply remove the build folder specified in .gitignore.
You can also look at this post as well. Hope this helps!

Git not showing 'assets' folder

I have a folder called 'assets' ( auto generated when creating a new android app using the wizard in netbeans ) but it does not show up in the git command line, nor does it get added to the repo even if I try to.
Any help?
Sounds like the directory is git-ignored. Check .gitignore at the root of your Git repo, and ~/.gitignore (your global ignore settings). Does assets show up in there? If so, do git add -f assets/ to force the add.
Git doesn't work with (empty) folders, only with files. If you need to commit a folder you need to check a file within, in order to force git to recreate that folder.
I suggest you to commit an empty file that begins with an underscore '.' like ".keep", this file will be ignored by android build process.
I hope that helps you

Cannot commit android "gen" folder to Git

I am using EGit in eclipse to provide Git support for an Android project I am working on. The problem is that after committing my project to the local repository I realized that the "gen" folder was not getting committed. As a result of this when I try to open the project on another machine after getting the latest source from the Git repository I keep getting the following error:
ERROR: Unable to open class file D:\CodeRep\POCs\Java\Android\Sudoku\gen\org\blah\example\R.java: No such file or directory
Why can't I commit the "gen" folder to Git from Eclipse ? Everything gets committed just fine so I can push it to the remote repository.
You shouldn't be commiting the gen folder; it contains generated code and doesn't belong in source control. You should be recreating it on the machine you pull the source code on with either an Eclipse "Project -> Clean" or a command line "ant clean" if you're using the build scripts.
This is a file of generated code, you would normally only be commit sources to git.
You probably need to clean your project when you check it out, perhaps you've got some other object files mistakenly included in the commit so it looks like it's already been built.
It shouldn't be necessary to commit the "gen" directory to git as everything in it should be automatically generated based upon content elsewhere in your source. In fact, the "gen" directory may have been added to your .gitignore by the Android SDK.

Categories

Resources