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)
Related
I have used this command to archive a git source code:
git archive --format=tgz -o ~/myproj-20180402.tgz --prefix=myproj/ master
Are there same/similar way to archive a AOSP repo branch or tag. How to do ? Any help would be greatly appreciated.
AOSP code is not a single git project, it's actually many more (hundreds). So there is not a git command per-se.
What you could do is use repo this way:
repo forall -j16 "<your-git-command-1; your-git-command-2>"
So for the exact git command you proposed it would be:
repo forall -j16 "git archive --format=tgz -o ~/myproj-20180402.tgz --prefix=myproj/ master"
But keep in mind there is not a single git project, so you will end up with hundreds of archives, each inside it's root dir. Check the manifest you sync for a full list of projects and it's location locally.
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.
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!
I executed these commands on intranet server (initialized empty Git repository in /home/git/project/):
mkdir project
cd project
git init --bare
Then I executed these commands on client:
git clone git#server:project
Then copied android source code (directory: alps/) to project
git status
git add .
git commit -m "xxx"
git push origin master
When this operation was done, I deleted the project and cloned it from server again. Some files were lost (e.g.:some .mk files in alps/external/chromium_org)
Why did it happen?
Most probably you've got the .mk extension in your .gitignore file. The file is in the project root directory. It may be hidden.
If you're sure that you want .mk files under source control, find a line with it in the .gitignore and delete that line.
Then:
git add .gitignore
git commit -m'removed .mk from .gitignore'
git add --all
git commit -m'tracked .mk files'
By the way, a good sample of .gitignore for Android can be found in GitHub default .gitignore files.
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?