Git-Remove files and cancel tracking of files

Source: Internet
Author: User
Tags using git

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):

  1. $ RM Grit.gemspec
  2. $ git status
  3. On Branch Master
  4. Changes not staged for commit:
  5. (use "git add/rm <file> ..." To update what'll be committed)
  6. (use "git checkout--<file> ..." To discard changes in working directory)
  7. Deleted:grit.gemspec
  8. 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:

    1. $ git rm grit.gemspec
    2. RM ' Grit.gemspec '
    3. $ git status
    4. On Branch Master
    5. Changes to be committed:
    6. (Use "git reset HEAD <file> ..." To unstage)
    7. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.