Git – remove and trace files

to remove a file from Git, you must remove it from the list of traced files (specifically, from the staging area) and commit it. You can do this with the git rm command, along with removing the specified file from the working directory so that it does not appear in the untracked file list in the future.

if you simply manually delete a file from your working directory, running git status will show you the Changes not passage for commit section (i.e., without a listing) :

$ rm grit.gemspec
$ git status
On branch master
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:    grit.gemspec

no changes added to commit (use "git add" and/or "git commit -a")

and then run git rm to record the removal of the file:

$ 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

When

is finally committed, the file is no longer in version management. If you have modified a file before deleting it and it is already in the staging area, you must use the force delete option -f to avoid losing the modified content after deleting the file by mistake.

is another situation where we want to delete a file from the Git repository (that is, remove it from the staging area), but still want to keep it in the current working directory. In other words, simply delete from the trace list. For example, some large log files or a pile of . A compiled files are accidentally included in the warehouse. Remove the trace but do not delete the files, so that they can be added later to the .gitignore files

$ git rm --cached readme.txt

can be followed by the name of the file or directory, or glob mode can be used. For example:

$ git rm log/\*.log

notice that the backslash \ precedes the asterisk *, because Git has its own file-pattern extension matching mode, so we don’t use the shell to expand it, but the shell extension only deletes files in the specified directory without recursively matching. The above example specifies the directory, so the effect is the same, but the following example matches recursively, so a backslash must be added. . This command deletes all files under the log/ directory with the extension . Log . Something like this:

$ git rm \*~

recursively deletes all files ending in ~ in the current directory and its subdirectories.

untracking files still has one command: git update-index — support-unchanged < Untracked file & GT;
note: this command can only cancel the file before the commit to the temporary area, you can use git reset < The file name & gt; returns a file in the staging area to before the staging area, and then untraces it.

Read More: