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:

108 questions
6290
votes
29 answers

How to make Git "forget" about a file that was tracked but is now in .gitignore?

There is a file that was being tracked by git, but now the file is on the .gitignore list. However, that file keeps showing up in git status after it's edited. How do you force git to completely forget about it?
Ivan
  • 77,768
  • 15
  • 47
  • 57
3299
votes
11 answers

Remove a file from a Git repository without deleting it from the local filesystem

My initial commit contained some log files. I've added *log to my .gitignore, and now I want to remove the log files from my repository. git rm mylogfile.log will remove a file from the repository, but will also remove it from the local file…
mveerman
  • 33,863
  • 3
  • 19
  • 14
2615
votes
21 answers

Ignore files that have already been committed to a Git repository

I have an already initialized Git repository that I added a .gitignore file to. How can I refresh the file index so the files I want ignored get ignored?
trobrock
  • 44,089
  • 11
  • 35
  • 44
2179
votes
24 answers

How can I delete a file from a Git repository?

I have added a file named "file1.txt" to a Git repository. After that, I committed it, added a couple of directories called dir1 and dir2, and committed them to the Git repository. Now the current repository has "file1.txt", dir1, and dir2. How can…
webminal.org
  • 37,814
  • 34
  • 84
  • 122
1339
votes
30 answers

Removing multiple files from a Git repo that have already been deleted from disk

I have a Git repo that I have deleted four files from using rm (not git rm), and my Git status looks like this: # deleted: file1.txt # deleted: file2.txt # deleted: file3.txt # deleted: file4.txt How do I remove these files…
Codebeef
  • 41,810
  • 20
  • 83
  • 116
1253
votes
13 answers

Why are there two ways to unstage a file in Git?

Sometimes git suggests git rm --cached to unstage a file, sometimes git reset HEAD file. When should I use which? EDIT: D:\code\gt2>git init Initialized empty Git repository in D:/code/gt2/.git/ D:\code\gt2>touch a D:\code\gt2>git status # On…
Senthess
  • 15,020
  • 5
  • 20
  • 28
536
votes
10 answers

Staging Deleted files

Say I have a file in my git repository called foo. Suppose it has been deleted with rm (not git rm). Then git status will show: Changes not staged for commit: deleted: foo How do I stage this individual file deletion? If I try: git add…
Andrew Tomazos
  • 58,923
  • 32
  • 156
  • 267
519
votes
6 answers

Remove a folder from git tracking

I need to exclude a folder (name uploads) from tracking. I tried to run git rm -r --cached wordpress/wp-content/uploads and after that I added the path to .gitignore /wordpress/wp-content/uploads but when I ran git status they show up as deleted.…
Stefan
  • 6,536
  • 3
  • 25
  • 37
420
votes
2 answers

Remove file from the repository but keep it locally

I have a folder which I'd like to remove in my remote repository. I'd like to delete it, but keep the folder in my computer
Rodrigo Souza
  • 6,680
  • 10
  • 39
  • 71
416
votes
12 answers

How do you fix a bad merge, and replay your good commits onto a fixed merge?

I accidentally committed an unwanted file (filename.orig while resolving a merge) to my repository several commits ago, without me noticing it until now. I want to completely delete the file from the repository history. Is it possible to rewrite…
Grant Limberg
  • 19,335
  • 10
  • 59
  • 84
409
votes
13 answers

How to revert a "git rm -r ."?

I accidentely said git rm -r .. How do I recover from this? I did not commit. I think all files were marked for deletion and were also physically removed from my local checkout. EDIT: I could (if I knew the command) revert to the last commit. But it…
user89021
  • 13,714
  • 14
  • 51
  • 65
391
votes
2 answers

How do I git rm a file without deleting it from disk?

The command removes the file in my system. I meant it to remove only the file from Git-repository. How can I remove the file from a Git repository, without removing the file in my system?
Léo Léopold Hertz 준영
  • 119,377
  • 159
  • 417
  • 655
363
votes
9 answers

Git: list only "untracked" files (also, custom commands)

Is there a way to use a command like git ls-files to show only untracked files? The reason I'm asking is because I use the following command to process all deleted files: git ls-files -d | xargs git rm I'd like something similar for untracked…
We Are All Monica
  • 11,597
  • 7
  • 41
  • 69
268
votes
10 answers

Git add all files modified, deleted, and untracked?

Is there a way to add all files no matter what you do to them whether it be deleted, untracked, etc? like for a commit. I just don't want to have to git add or git rm all my files every time I commit, especially when I'm working on a large product.
INSANENEIVIESIS
  • 2,701
  • 2
  • 14
  • 4
244
votes
16 answers

How to remove multiple deleted files in Git repository

I have deleted some files and git status shows as below. I have committed and pushed. GitHub still shows the deleted files in the repository. How can I delete files in the GitHub repository? # On branch master # Changes not staged for commit: # …
shin
  • 28,830
  • 62
  • 170
  • 248
1
2 3 4 5 6 7 8