Table of contents
The current warehouse of this machine is valid
Ignore files in a single repository (remote sharing)
The current warehouse of this machine is valid
When submitting with git, you can add ignore files by setting the exclude file in the .git/info directory (only effective locally, and will not be synchronized to the remote warehouse), so the files that are most suitable for your own use. It only takes effect in the current warehouse of the machine
One ignore file per line, where relative to the root directory . Then save it, the ones that have been added to version control are invalid
Ignore files in a single repository (remote sharing)
Create a new .gitignore file in the root directory of the warehouse, configure the ignore rules in the file, and add the .gitignore file to version management. Afterwards, the configuration can be synchronized to the remote warehouse, and the .gitignore file is valid for the directory where it is located and all subdirectories of the directory where it is located.
创建.gitignore文件。
touch .gitignore
Each file or regular match takes one line.
xyj-*.py
native global ignore
Works on all Git repositories on this machine
Copy the file in the user's root directory .gitconfig
and name it .gitignore_global (others are also available, there is no limit to the .txt format)
(It can be placed in the user root directory or other paths), empty the contents of the .gitignore_global file
git config --global core.excludesfile /c/Users/admin/.gitignore_global
After executing the command, view .gitconfig
the file and see the following content:
# 下面两行是生成的
[core]
excludesfile = C:/Users/admin/.gitignore_global
Then add the files to ignore
In fact, you can directly write the contents of the .gitignore_global file to the .gitconfig file, and the effect is the same. It's just that it's a little more confusing.
Delete already pushed files
After setting the ignore file, the previously added version control is invalid and needs to be deleted from the local library
- delete files
git rm --cached 路径下的文件名
; - Delete a folder and all files in it
git rm -r --cached 路径下的文件名
Delete already added files
- Clear the staging area with the content of the repository, git reset HEAD (use with caution)
- Only delete specific files from the temporary storage area, git rm --cached xxx