I have a Ruby on Rails application which crashes when vendor/rails
is present but works fine if it is not. I need to keep this folder deleted in my local copy so that I can work, but I don't want this deletion to ever be committed. Someone put it there for a reason.
So how do I delete this folder without it coming up in git status
as a thousand deleted files? Obviously .gitignore
won't work since you can't ignore files which are already tracked. Neither do any of the solutions listed here (git update-index --assume-unchanged
) work.
All ignored files get stored in a .gitignore file. A .gitignore file is a plain text file that contains a list of all the specified files and folders from the project that Git should ignore and not track.
Even though you removed the file or directory with the commands above, Git will still try to track it. Additionally, if you accidentally commit or push that certain file or directory in the future, it will end up in a remote repository again. To avoid that, add the full path to the file/dir in question to the .gitignore file.
You can’t push these local changes, and putting these configuration files in the .gitignore file is also a no-go as these files need to be tracked by git. Turns out you can ignore local files using the power of Git! If you navigate to the .git folder, there is a folder in there called info, which should have one file inside called exclude.
You have several options: Leave a dirty (or uncommitted) .gitignore file in your working dir (or apply it automatically using topgit or some other such patch tool). Put the excludes in your $GIT_DIR/info/exclude file, if this is specific to one tree.
git ls-files --deleted -z | git update-index --assume-unchanged -z --stdin
Note that because this is an index-based operation, you cannot set directories to be ignored – only individual files. If upstream ever adds a file inside those directories, you will have to repeat the fix-up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With