2

I am trying to make git ignore the opencv2.framework I have imported into my project. However, even though I am adding opencv2.framework into my .gitignore, every time I run git status on my terminal, all the opencv2.framework files are showing up as new files. Could anybody help? Thanks! This is what my .gitignore file looks like: (I wrote opencv2.framework under ##Various Settings)

# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
opencv2.framework/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
jx8
  • 45
  • 8
  • Just to double check, have you added and committed the changes to the .gitignore? – alkasm Jun 30 '17 at 02:47
  • Possible duplicate of [gitignore not ignoring file](https://stackoverflow.com/questions/23716553/gitignore-not-ignoring-file) – ha100 Jul 05 '17 at 21:51

1 Answers1

2

Just in case, see if git status changes after:

cd /path/to/my/repo
git rm -r --cached opencv2.framework/

If it does (and you don't see anymore opencv2.framework/ files), commit your current state.

You need to execute the git rm -r --cached:

  • in the parent repo of the folder to remove (parent of opencv2.framework/).
    Do add and commit (and eventually push), in order to record that deletion from the git repo (but not from the disk, thanks to the --cached option);
  • in order to delete those tracked files, as a .gitignore rule only applies to untracked files.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I entered that command, and it returned "fatal: path spec 'opencv2.framework/' did not match any files" – jx8 Jul 05 '17 at 15:38
  • So I found a temporary workaround since I am using Xcode: while committing the .gitignore (with opencv2.framework), i manually unchecked all the opencv2 files to prevent them from committing and pushing to my remote. However, when I check git status, the opencv2 files are still showing up as new files, so it does not seem like git is ignoring them. I tried running "git rm -r --cached opencv2.framework" again, and the same fatal message returned. – jx8 Jul 05 '17 at 15:49
  • @jx8 Strange: did you do the git rm in the right fodler (parent of opencv2.framework/). Is there a lowecase/upercase issue, where the Git repo knows that folder with an upercase? – VonC Jul 05 '17 at 15:51
  • Ah, that was quite foolish of me - I was in the wrong folder (had to use ls to check contents). I ran the the git rm command, and it seems to have removed the opencv2 files. What is the next step I should take? And I apologize for the simple question (I'm new to git), but what does "git rm -r --cached afile" exactly do? – jx8 Jul 05 '17 at 16:16
  • Add and commit. Then check your git status. The folder content should be ignored now. – VonC Jul 05 '17 at 16:18
  • Yes, upon checking git status now, the opencv2 files are ignored. Just for future reference, why did I need to run the "git rm -r --cached" command even though I added the opencv2.framework to my .gitignore file? – jx8 Jul 05 '17 at 16:23
  • As long as the folder content is already tracked, gitignore rules won't matter. Those rules only apply to untracked content. – VonC Jul 05 '17 at 16:25
  • @jx8 I just edited the answer to include those comments and make them more visible. – VonC Jul 05 '17 at 19:08