Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove files deleted from .git?

Tags:

git

When I delete a file (or rename it) by using mv, rm or some other facility, the file shows as deleted when I do git status:

# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    ../src/main/..../myFile.java

Before creating a commit, it is cumbersome to do git rm <file> for each file, particularly as there is no auto-completion in the terminal for a file which isn't there.

Is there a shorter way to remove the deleted files from the set of files tracked by git?

Thanks

like image 781
axel22 Avatar asked Jul 14 '12 23:07

axel22


People also ask

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

The "rm" command helps you to remove files from a Git repository. It allows you to not only delete a file from the repository, but also - if you wish - from the filesystem. Deleting a file from the filesystem can of course easily be done in many other applications, e.g. a text editor, IDE or file browser.

Where do git deleted files go?

Listing all the deleted files in all of git history can be done by combining git log with --diff-filter . The log gives you lots of options to show different bits of information about the commit that happened at that point.

Does git store deleted files?

Git keeps a log of all the changes made to files within a repository. You can restore a file that you have deleted since a previous commit by using the git checkout command. This command lets you navigate to a previous point in your repository's history.

How do I delete all deleted files?

Deleting files by right-clicking them sends them directly to the Recycle Bin. To permanently delete all the files in your Recycling Bin, minimize all your open windows, right-click the Recycle Bin on your desktop, and select Empty Recycle Bin.


1 Answers

I believe git add -u will do what you wish, from the documentation:

-u
--update
  Only match <filepattern> against already tracked files in the index 
  rather than the working tree. That means that it will never stage new
  files, but that it will stage modified new contents of tracked files
  and that it will remove files from the index if the corresponding file
  in the working tree have been removed.

Reference: http://git-scm.com/docs/git-add

like image 159
Martin Avatar answered Sep 21 '22 05:09

Martin