I committed files from .idea folder, then I created .gitignore file, and I wanted to stop tracking those files from .idea folder.
To do this, I wrote:
git rm -r --cached .
git add .
and committed changes. Everything was fine until Android Studio changed file misc.xml, by changing java language level, and I do not know why, but if I try to commit changes, I can still commit this file misc.xml, which is ignored and should not be tracking anymore. What can I do?
Thanks to #mt0s from comment, I executed command
git status --ignored
and it showed only two files from idea, excluding misc.xml:
So I repeated the commands:
git rm -r --cached .
git add .
and now it works, it deleted all files from .idea from tracking, and now when I change something in a file misc.xml, it do not goes to commit.
Related
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
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!
From the title of my question you can see what my problem is. I have an app on GitHub but I don't have .gitnore file. Now I want to make that file. I read somewhere that I must delete some files with terminal(Ubuntu) and then to make new .gitnore file.
Could someone tell me how to do all that stuff?
EDIT: I followed a solution from another question but when I write it into the terminal I received this:
dev3#dev3-All-Series:~$ git rm --cached
fatal: Not a git repository (or any of the parent directories): .git
dev3#dev3-All-Series:~$
You can remove the files on your local machine, and push to the repository. If the files are removed there, thén you can make the .gitnore file. That way, you don't end up with useless 'dead' folders or files on your repo. This way you don't need local access to the files, just your git client.
If you add the .gitnore first, you won't be able to delete the files because they will be ignored :).
If you already have a .gitnore file setup, you can do the following to remove files:
You can remove them from the repository manually:
git rm --cached file1 file2 dir/file3
Or, if you have a lot of files:
git rm --cached `git ls-files -i --exclude-from=.gitignore`
But this doesn't seem to work in Git Bash on Windows. It produces an error message. The following works better:
git ls-files -i --exclude-from=.gitignore | xargs git rm --cached
(found that solution here)
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
Iv'e added:
*.iml
to all of the gitignore files in my project.
They are still being tracked, even after committing the .gitignore.
The safe option is to remove the iml file from your staging index.
git rm --cached <path to iml file>
git will track the files sometimes even if you added the file which shouldn't be tracked in .gitignore
In that case you should remove the cache first then add all.
Important : Before, commit or stash your current changes
$ git rm -r --cached .
$ git add .
$ git commit -m "file tracking - changed"
When you added them one time, they will keep tracked!
You have to retrieve all commits till the one where you commited the .iml files.
Here is a good post on SF about reseting commits in git:
How to revert Git repository to a previous commit?