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:
- error: src refspec master does not match any error:failed to push some refs to ‘[email protected]:xxxx
- pathspec ‘master’ did not match any files known to git
- Git error: unlink of file failed.Should I try again?
- Perl application – delete “. SVN” folder in current directory and subdirectory
- Linux shell RM deletes all. O suffix files in the subdirectory
- bad index file sha1 signature fatal
- Git solves pull origin error: the following untracked working tree files would be rewritten by merge
- Common linux commands — find command’s Exec
- How to clean up the disk space of Linux server
- Error in ogrListLayers(dsn = dsn): Cannot open data source is reported when readOGR loads the shapefile
- Idea can’t submit code to GitHub when using git — too much code / file leads to submission failure
- Git prompts another git process sees to be running in this repository, e.g. an editor opened by
- Delete files with specified suffix in specified folder under Linux
- GitHub desktop submission errors and Solutions
- Linux command line cursor moving skills
- GitHub desktop upload file error commit failed – exit code 1 received
- How to cancel the commit, how to cancel the commit after git commit, and how to change the submitted content
- Git commit encountered error: pathspec (Fixed)
- How to Fix LDPlayer4 Proxy Setting Not Work Issue
- 【Oracle】 ORA-00257: archiver error. Connect internal only, until freed