Pushed node_modules but cant figure out how to remove - node-modules

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"

Related

Xcode git can't ignore all *.xcodeproj/xcuserdata/ folders

I followed cant-ignore-userinterfacestate-xcuserstate and ignore-files-that-have-already-been-committed-to-a-git-repository. But these never works.
My Step Reproduction:
Quit Xcode
project directory: git rm -r --cached .
project directory: git add . && git commit -m "remove junk files"
Open Xcode project
Then these files appear again.
Most troubled me was that each time I rebase code will automatic appear these files so I will rebase fail of unstage files. Each time I need to stash these file.
This is my .gitignore file code section:
### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
*.xcodeproj/xcuserdata/
I just realized that these want to ignored files was buried in deep folder.
And git don't support this kind of pattern *.xcodeproj/xcuserdata/.
Want to ignore other son son (recursive) folder need add this to .gitignore:
ios/**/*.xcodeproj/xcuserdata/
or a clean way:
**/xcuserdata/
This **/*.xcodeproj was git version 1.8.2's feature.
$ git --version
git version 2.16.1
So most of us can use it.
I learnt from how-to-gitignore-files-recursively.

Git Ignore Basics

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.

How do I correctly add a visual studios project to a Git repository

I have already committed my whole Visual Studios project to my Git repository. However, I realized that I didn't include a gitignore file until after I committed my project. I think this is causing problems since I've pushed some of the files that are compiled. My main problem is that my gitignore is not ignoring files such as .dll and .pdb.
How can I fix this? Should I remove my whole project and recommit with the new gitignore? or are there specific visual studios folders I can just remove?
.gitignore ignores only those files which are not being already tracked with git. Since you already added the .dll files, they won't be ignored on their own now.
You can remove specific folders/files from your repo using git rm
git rm -r --cached folder_1
git rm -r --cached folder_2
git rm --cached file_1
git commit -m "removing unwanted files"
The -r above is for recursive removal of folders.
However, that will leave a commit history having all those files.
So, if you haven't pushed it upstream already, and have made fairly low number of commits till now, I would recommend creating a new repo - Delete the .git folder, and then run git init, then create/update the .gitignore file with the right entries, and finally add your code again.

Git not ignoring certain Xcode files in .gitignore

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

Git Ignore Pattern for XCode Build Directory

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).

Resources