How to remove deleted files from showing up in my local git status?
You probably need to git rm
the deleted files. From Pro Git:
Removing Files
To remove a file from Git, you have to remove it from your tracked files (more accurately, remove it from your staging area) and then commit. The
git rm
command does that and also removes the file from your working directory so you don’t see it as an untracked file next time around.If you simply remove the file from your working directory, it shows up under the “Changed but not updated” (that is, unstaged) area of your
git status
output:$ rm grit.gemspec $ git status # On branch master # # Changed but not updated: # (use "git add/rm <file>..." to update what will be committed) # # deleted: grit.gemspec #
Then, if you run
git rm
, it stages the file’s removal:$ git rm grit.gemspec rm 'grit.gemspec' $ git status # On branch master # # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # deleted: grit.gemspec #
The next time you commit, the file will be gone and no longer tracked. If you modified the file and added it to the index already, you must force the removal with the
-f
option. This is a safety feature to prevent accidental removal of data that hasn’t yet been recorded in a snapshot and that can’t be recovered from Git.
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 :)
Updated after your comments.
If you want to keep the images on the server, but remove the files from git then you need to add the --cached
flag to git rm
.
cd images
git rm --cached *
cd ..
echo "images" > .gitignore
git add .
git commit -m "removed image files from git only"
git push
if you want people to create the images directory when they pull (but have no files), then add a images/.gitignore
with the single line !.gitignore
Note, this won't remove them from the history. For that, i would look at this SO answer