Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove deleted files from showing up in my local git status?

A developer added an image directory on the server without adding that folder to the .gitignore file. When I did a git pull it pulled those files (hundreds of files). I added the folder to the .gitignore on the server but not my local system. I then deleted the files locally (permanently). When I do a git status all those deleted files still show up. How can I suppress them from showing up?

Update: thanks for all the great help. To make sure there is no misunderstanding: I do want to keep the files on the server; I just want to remove them from git.

like image 698
uwe Avatar asked Nov 10 '11 20:11

uwe


People also ask

How do I remove a deleted file from my git repository?

Delete Files using git rm. The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.

How do I remove files from git and keep local?

Execute the following command: git rm --cached path/to/file . Git will list the files it has deleted. The --cached flag should be used if you want to keep the local copy but remove it from the repository.

Does git ignore delete files?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

How do I remove deleted files from staging?

Simply remove a file txt , will remove the file, and git status will show deleted: foo. txt . But git rm foo. txt will remove the file and add it to the staging area.


1 Answers

I find this to be the easiest way of doing the task.

$> git add -u <directory-path>   (or you may use --update)

Original State :

$> git status .

On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)
deleted:    .ipynb_checkpoints/Untitled-checkpoint.ipynb
deleted:    CVPR 1 hr tute-Backup.ipynb
deleted:    cifar10-test.t7
deleted:    cifar10-train.t7
deleted:    cifar10torchsmall.zip
deleted:    create_advr.lua
deleted:    criterion_cifar10_lr_0.001_epoch_13.t7
deleted:    train_cifar10.lua
deleted:    trained_net_cifar10_lr_0.001_epoch_13.t7

So, to remove all deleted files from my current directory, I use.

$> git add -u .
$> git commit -m "removing deleted files from tracking"
$> git push origin master

Final State :

$> git status .

On branch master
nothing to commit, working directory clean

Hope this helps :)

like image 91
NightFury13 Avatar answered Sep 29 '22 23:09

NightFury13