3

I have a project, and have shared the root folder through git.

My compatriots and I are using different versions of Gradle (and have named the project different things), so it would be appropriate for some things in the .idea folder (a certain folder) to be in the .gitignore file. I did not realize this until now, when my friend has pulled it, changed many things due to using a different version, and now pushed it back.

I have added to the .gitignore file:

/.idea/

However, git seems to still be sending the changes in that folder to the Github repo.

I have checked out a few things, including this, this, and a few more questions on stack overflow.

I ran git rm --cached .idea/ and that successfully kept the changes from being pushed. However, if I checkout another branch and then return to this one, it does not include the appropriate files in the .idea directory.

Thank you,

A confused coder

Community
  • 1
  • 1
FWhitaker
  • 31
  • 1
  • 1
    Wouldn't `/.idea/` ignore the root-level `.idea` folder and not the one in your project directory? – pjmorse Jun 20 '16 at 19:52
  • It certainly seems to be ignoring the .idea folder, as the contents of the folder are disappearing. – FWhitaker Jun 22 '16 at 13:00

1 Answers1

1

Files that are already tracked in the repository will remain so even if you add them to .gitignore - it only affects untracked files. In order to remove a file from git without deleting the file from the working directory, use

git update-index --force-remove yourFileName

This will mark the file for removal without deleting it. --force-remove seems to only work on individual files, so in order to remove an entire folder, try this:

find .idea | xargs git update-index --force-remove
Aasmund Eldhuset
  • 37,289
  • 4
  • 68
  • 81
  • If I commit this, then checkout another branch, then checkout the first branch, these files will be gone. – FWhitaker Jun 20 '16 at 20:16
  • I can only imagine that that is because the files are still committed in that branch, and so when you switch back to the branch where the files no longer exist, git thinks it should remove the files from the working directory. However, as long as the directory has been removed from all branches that you switch between, it should be preserved between checkouts even if it is ignored. – Aasmund Eldhuset Jun 20 '16 at 22:25