Questions tagged [git-rm]

`git rm` is a Git command used to remove files from the working tree and from the index. Use this tag for all posts related to the usage of this command.

git rm is a Git command used to remove files from the working tree and from the index. In particular, it allows to actually start ignoring the files, listed in .gitignore.

Recommended questions:

117 questions
181
votes
3 answers

"git rm --cached x" vs "git reset head --​ x"?

GitRef.org - Basic: git rm will remove entries from the staging area. This is a bit different from git reset HEAD which "unstages" files. By "unstage" I mean it reverts the staging area to what was there before we started modifying…
Pacerier
  • 86,231
  • 106
  • 366
  • 634
179
votes
7 answers

Git: How to remove file from index without deleting files from any repository

When you use git rm --cached myfile it doesn't delete from the local filesystem, which is the goal. But if you've already versioned and committed the file, pushed it to a central repository, and pulled it into yet another repository before using…
Fletcher Moore
  • 13,558
  • 11
  • 40
  • 58
107
votes
3 answers

How to ignore files which are in repository?

I have a file (config.php), that is already committed to a Git repository, but I want to ignore locally, i.e. I want that file to remain in repository, but force Git to ignore any changes to it. I put the file into .gitignore, but it is still marked…
prcaen
  • 2,429
  • 4
  • 25
  • 32
97
votes
1 answer

Git - undoing git rm

Possible Duplicate: How to revert a “git rm -r .”? Git SOS here. I worked 10 hours on a project without committing (I know, I know) and then I git added too many files, so I tried using git rm and accidentally deleted EVERYTHING. Is there hope…
user1436111
  • 2,111
  • 7
  • 24
  • 41
87
votes
5 answers

How to disconnect a local Git repository from remote master

How do I completely disconnect a local Git repository from all remote branches? I cloned a Git repository from github.com, but then it was deleted and I don't want Git to report any changes needing to be "pushed up". I've tried googling this, but I…
Cerin
  • 60,957
  • 96
  • 316
  • 522
79
votes
3 answers

Completely remove files from Git repo and remote on GitHub

I accidentally added a folder of images and committed. Then, I made one more commit. Then I removed those files using git rm -f ./images and committed again. Right now, I have made a lot more commits in that branch (master). In my HEAD, I don't…
shadyabhi
  • 16,675
  • 26
  • 80
  • 131
68
votes
1 answer

git rm --cached file vs git reset file

I'm trying to learn Git. I'm confused between git rm --cached file and git reset file both of the commands seem to take the file from staged to un-staged area. How do the commands differ?
Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126
30
votes
11 answers

Git rm several files?

How do I easily remove several files without manually typing the full paths of all of them to git rm? I have plenty of modified files I'd like to keep so removing all modified is not possible either. And also it is possible to revert the changes of…
Tower
  • 98,741
  • 129
  • 357
  • 507
27
votes
5 answers

git rm --cached and fatal: pathspec

I just tried to checkout my master branch and ran into: error: Untracked working tree file 'app.xcodeproj/project.xcworkspace/xcuserdata/u.xcuserdatad/UserInterfaceState.xcuserstate' would be overwritten by merge. So, I tried to delete this file…
Snowcrash
  • 80,579
  • 89
  • 266
  • 376
23
votes
3 answers

When is git rm -f used?

I am learning Git and am unable to understand under what condition the -f flag is used while issuing the "git rm" command. Please explain a scenario where rm -f would be required instead of rm only?
Mohnish
  • 1,905
  • 2
  • 17
  • 19
23
votes
4 answers

How to recover file after `git rm abc.c`?

I supposed to delete another file with git rm abc.c. But I deleted a wrong one. How can I recover it? Right now, when I issue git status, it says deleted: abc.c BTW, I have other uncommitted changes now.
Anders Lind
  • 4,542
  • 8
  • 46
  • 59
22
votes
5 answers

Git - Remove All of a Certain Type of File from the Repository

How do I remove all of a certain type of file from the Repository? I'm using git filter-branch --index-filter 'git rm -rf --cached **/*.jar' Either git is not expanding globs, or it isn't expanding ** in the way I'm expecting.
lmat - Reinstate Monica
  • 7,289
  • 6
  • 48
  • 62
21
votes
1 answer

What's the difference between 'git rm --cached', 'git restore --staged', and 'git reset'

I have come across the following three ways in order to unstage the files that were staged by the command 'git add' git rm --cached git restore --staged git reset Their behaviors looked completely same when I ran those commands…
sekai_no_suda
  • 413
  • 4
  • 11
19
votes
2 answers

Will git-rm --cached delete another user's working tree files when they pull

I wish to stop tracking files but still keep them in my working tree. I've gathered that git rm --cached FILE will let me do that. However, if someone else pulls this change, will their local copies be deleted?
rod
  • 3,403
  • 4
  • 19
  • 25
17
votes
6 answers

Restore deleted file not staged in git

I accidentally removed the entire directory of my source code...with a nice rm -r. I know, really bad; but fortunately, I had a git repo in the containing directory. Thus, git has a huge list of unstaged changes of deleted files. For example:…
Vance T
  • 513
  • 2
  • 5
  • 15