I want to delete files managed by Git

When you forget to write in .gitignore and commit "It's okay if you add it to .gitignore ..." Are you misunderstanding? Like me .. sweat

Files managed by Git will not be removed just by adding to .gitignore later, so I will write a countermeasure in such a case.

If you want to keep Git-managed files and exclude them

$ git rm --cached [File name you want to exclude]

After that, be sure to add the files you want to exclude to .gitignore. Note: Be sure to add --cached! !! If you do not add it, the entire file will be deleted.

If you want to delete the entire file

$ git rm [File name you want to delete]

If you want to delete the entire directory

$ git rm -r [Directory you want to delete]


When I started using Git, I forgot it several times and committed it, and I checked it each time, so I will keep it as a memorandum.

I hope it helps those who are in the same situation.

Recommended Posts

I want to delete files managed by Git
I want to sort by tab delimited by ruby
I want to convert characters ...
I want to easily back up files used at work
I want to recursively search for files under a specific directory
I want to give edit and delete permissions only to the poster
I want to avoid OutOfMemory when outputting large files with POI
I want to limit the input by narrowing the range of numbers
I want to judge the necessity of testing by comparing the difference of class files when refactoring Java
I want to develop a web application!
I want to write a nice build.gradle
I want to make an ios.android app
I want to use DBViewer with Eclipse 2018-12! !!
I want to write a unit test!
I want to perform Group By processing with Stream (group-by-count, group-by-sum, group-by-max)
I want to stop Java updates altogether
I want to use @Autowired in Servlet
I want to target static fields to @Autowired
I want to do team development remotely
Run R from Java I want to run rJava
I want to send an email in Java.
[Ruby] I want to do a method jump!
I want to use java8 forEach with index
I want to var_dump the contents of the intent
I want to pass APP_HOME to logback in Gradle
I want to simply write a repeating string
I want to design a structured exception handling
rsync4j --I want to touch rsync in Java.
I want to play with Firestore from Rails
I want to be eventually even in kotlin
I want to write quickly from java to sqlite
I want to truncate after the decimal point
I want to get the value in Ruby
# 1_JAVA I want to get the index number by specifying one character in the character string.
I want to use Combine in UIKit as well.
I want to use Clojure's convenient functions in Kotlin
I want to call a method of another class
I want to do something like "cls" in Java
[Java] I want to calculate the difference from the date
I want to use NetBeans on Mac → I can use it!
I want to embed any TraceId in the log
Pointcut Expression I want to specify more than one
I want to use fish shell in Laradock too! !!
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
I learned stream (I want to convert List to Map <Integer, List>)
I want to judge the range using the monthly degree
I want to know the answer of the rock-paper-scissors app
I want to display the name of the poster of the comment
I want to dark mode with the SWT app
I want to monitor a specific file with WatchService
I want to apply ContainerRelativeShape only to specific corners [SwiftUI]
I want to authenticate users to Rails with Devise + OmniAuth
I want to define a function in Rails Console
[Android Studio] I want to use Maven library on Android
I want to transition screens with kotlin and java!
[Swift] I want to do something like C's sprinftf
firewalld went wrong, so I managed to fix it.
I want to stop snake case in table definition
I want to call the main method using reflection
I want to click a GoogleMap pin in RSpec
[Rough commentary] I want to marry the pluck method