To remove a file from Git, you must remove it from the list of tracked files (to be exact, remove it from the staging area) and commit. You can git rm
do this with a command, and also delete the specified file from the working directory so that it does not appear in the list of non-tracked files.
If you simply delete the file manually from the working directory, the runtime git status
will see it in the "changes not staged for commit" section (that is, the manifest is not staged):
- $ RM Grit.gemspec
- $ git status
- On Branch Master
- Changes not staged for commit:
- (use "git add/rm <file> ..." To update what'll 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")
Then run git rm
the operation to record the removal of this 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
The file is no longer included in version management when it is last submitted. If the deletion has been modified before and has been placed in the staging area, you must use the force Delete option -f
(the first letter of forces) in case you lose the modified content after deleting the file by mistake.
Another scenario is that we want to remove the 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, it is only removed from the tracking list. For example, some large log files or a bunch .a
of compiled files, accidentally into the warehouse, to remove the trace but do not delete the file, so that later in the .gitignore
file to fill, with the --cached
option:
--cached readme.txt
The name of the file or directory can be listed later, or you can use the Glob mode. Say:
log/\*.log
Notice the backslash *
before the asterisk \
, because Git has its own file pattern extension match, so we don't have to use the shell to help with the expansion (it can actually be run without a backslash, just as the shell expands, Delete only the files in the specified directory without recursive matching. The above example would have specified a directory, so the effect is equivalent, but the following example will be recursively matched, so the backslash must be added. )。 This command removes all log/
.log
files that have the file name extension under all directories. A similar example:
$ git rm \*~
Recursively deletes all ~
files at the end of the current directory and its subdirectories.
To cancel a trace of a file there is one more command: git update-index--assume-unchanged < un-tracked files >
Note: This command only cancels files that were submitted to staging area before you can cancel the trace by first using git reset < file name > fallback the staging file to staging area.
---------------------This article from leedaning csdn blog, full-text address please click: 44976319?utm_source=copy
Git-Removing files and canceling tracking of files