I am very new to Git and am trying to use a .gitignore file. I have an Xcode project which includes many CocoaPods and Nodejs modules. I want all these files to be ignored, but I'm not sure how to create a .gitignore file and how to specify which files to ignore. Somebody please help.
First, you can simply copy a .gitignore file from gitignore.io:
https://www.gitignore.io/api/xcode
Second, make sure those files were not already added to the index.
Do a git check-ignore -v -- a/file/I/want/ignored: if it returns nothing, then remove it from the index (git rm --cached a/file/I/want/ignored) and try again.
Related
I push the node modules up to GitHub, then realized I did not have a .gitignore.
I added the gitignore but it did not fix the problem.
I found answers on here that said to remove it from the cached with git rm -r --cached node_modules, but this wont work because it says it cannot find that file, and I can still see it in my repo as well.
My file structure is the repo, then a dev folder with node_modules inside it, along with all the other code I have written.
The .gitignore is outside of the dev folder, next to the README file.
Do I need to give the .gitignore a path to find the modules like a ./node_modules or something?
the gitignore is outside of the dev folder next to the readme file
Then, it should include:
dev/node_modules/
That would ignore the dev/node_modules folder, and its content.
Check that (after a git rm --cached dev/node_modules done from the root folder of your repo) with:
git check-ignore -v -- dev/node_modules/afile
(test it on one existing file inside that dev/node_modules/ folder)
If you've added just node_modules in the .gitignore file, then it ignores all the node_modules directories within the repo. So you are just fine with .gitignore configuration.
The issue is that you should use the correct path when removing the cached copy of the node_modules. It should be as follows from the root of your repository.
git rm -r --cached ./dev/node_modules
Add this in .gitignore
dev/node_modules/
Now reset cache.
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
I have tried to solve this by
Deleting all pods and re installing
Cleaning build folder
Deleting .gitignore and recreating
However there are a few files within the Pods dir that continue to show up
I'm ignoring using this in my .gitignore since my initial commit - nothing in this has ever been committed.
Pods/
Note this has only started recently with a with a new pod update
When I try to commit I get the following.
All other pods within this dir are ignored.
I have looked at these, but no luck fixing
.gitignore ignoring whitelisted folder
.gitignore not ignoring folder
Gitignore not ignoring folders
.gitignore doesn't ignore files
This looked like it may have the solution but not sure if I want to try it, so decided to post and understand the reason why this is happening
gitignore does not ignore folder
Note: Running Swift 4.2 / Xcode 10.1
You were tracking this files so they are added to index. All you have to do before ignoring this files you have to untrack them.
If you want to remove them from the index you have to type git rm -r --cached {name_folder} then use git commit -m "removed files from index" and change your .gitignore file.
I am new to Git and I am using it to backup an iPhone project I am working on.
I have added a list of files that Git should ignore (xcode files) when I update, but this .perspectivev3 (which is in my .gitignore) file keeps showing up when I go to commit my changes. Does anyone know why this is, or what I am doing wrong?
Thanks,
Zach
This is what is in my .gitignore file:
# xcode noise
*.mode1v3
*.pbxuser
*.perspective
*.perspectivev3
*.pyc
*~.nib/
build/*
# Textmate - if you build your xcode projects with it
*.tm_build_errors
# old skool
.svn
# osx noise
.DS_Store
profile
If it keep showing up in the git status, it must have been added or committed before.
You need to
git rm --cached that file, in order for the git status to not list it anymore (it is was just added, but not committed yet).
git rm that file, if it was previously committed (see this question for instance)
You can use
$ git rm --cached ./whatever1.txt
after something is already under version control.
In fact, if you have "whatever1.txt" under version control and you want to remove it from git, but leave your working tree undisturbed, then just do this:
$ git rm --cached ./whatever1.txt
$ echo /whatever1.txt >> ${PROJECT_ROOT}/.gitignore
$ git status # this will now show ./whatever1 as "deleted" (from git, not your working tree, and will show gitignore as modified or created)
$ git commit -a
And that's it.
Only use
$ git rm
when you want to remove the file from both the working tree AND the git repo.
CAVEAT: The likely scenario you would use this is for removing IDE-specific files from git. In this example "whatever1" represents your IDE file(s) you're removing. If you are working on a project with several people and you push this changeset to a shared repo, then their "./whatever1" files WILL BE DELETED when they pull this changeset. The easy thing to do from here for the people on the receiving end is:
$ git checkout 1215ef -- ./file-you-want-to-restore ./another-file ./another-etc
(where 1215ef represents the last commit before the deletion)
This has the effect of restoring those files that were present at their last commit before the pull. After they have done this those files will be safe and not show up as uncommitted b/c they will fall under the exclusion of gitignore.
Good luck!
.gitignore only applies for untracked files. If you've git-add'ed files that are otherwise untracked due to .gitignore, they will still be part of the repository.
Simply remove the files from the repository you don't want anymore:
git rm *.perspectivev3
I am new to Git, and this is my first project using Git rather than SVN as my source control. I am working in XCode on an iPhone project. I want Git to ignore the build directory, which is in the root folder of the XCode project. I've found several other questions here and also found articles on google that provide examples on how to create the .gitignore file in the root directory and then add it to the Git repository to get the directory to be ignored.
Here are the steps I'm taking when setting up the repository:
Open Terminal and navigate to the root directory of the application
Call git init to initialize the repository
Call git add .gitignore to add the gitignore file
Call git commit -m to commit the gitignore file
Call git status to view the status of the repository
At this point, all of the other directories and files listed in my gitignore file are properly ignored except the build directory. Here is what my gitignore file looks like:
build/
.DS_Store
**/*.pbxuser
*.mode2v3
*.mode1v3
**/*.perspectivev*
I have tried ignoring the build directory using the following different entries with no success:
build
build/
build/*
Anyone know what I'm doing wrong here?
build/ or build/* should be enough to ignore the directory.
See also "Difference between .gitignore rules with and without trailing slash like /dir and /dir/"
The only reasons it could be still not ignored at this point if it:
has somehow been added to the index and committed (which, according to your setup, shouldn't be the case)
has a trailing space (/build ) in the .gitignore file rule, as in this .gitconfig, before Git 2.0 (Q2 2014).
I have an Xcode project that uses git for version control. I have a .gitignore file to ignore the build subdirectory:
build/*
I recently added a subdirectory that contains an Xcode project and forgot to update the .gitignore file before checking it in.
Is there any way to make git ignore the build subdirctory now, after the fact?
Thanks,
Doug
git rm --cached dirToignore
echo dirToignore >>.gitignore
From there, a new commit will record that:
dirToignore is no longer par of versioned data
dirToIgnore won't show up anymore in git status
See this SO question for similar advices.
If you want to amend previous commit in order to remove said subdirectory from an old commit, see this SO question:
git commit --amend
can help you remove it from at least the last commit.