简体   繁体   中英

How do I tell git to ignore files that start with a tilde?

My text editor creates swap files that start with a tilde. I accidentally checked on of these into git. How do I tell git to ignore any files like this anywhere in my project tree?

So I had

/folder/another/file.txt
/folder/another/~file.txt

I want ~file.txt to be ignored by git.

Just use a .gitignore file:

echo '~*' >> .gitignore

Alternatively, you can also write this line to .git/info/exclude which is a project-wide local ignore file (which you obviously cannot check in, as you can do with .gitignore ).

echo '~*' >> .gitignore

This will append the needed entry.

Else edit the .gitignore file manually and add ~* on a new line.

  1. first check if git ever added your file to the tracked files.

    git status

yes ? so remove the file or folder from git

git rm --cached <file-name> or git rm -r --cached <folder-name>

then, append to the .gitignore file the followed pattern (an asterisk "*" matches anything except a slash.)

echo '.~*' >> .gitignore

that's all folks !

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM