Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore - ignore file starting with ~

To ignore any file starting with ~(tilde), I put following in gitignore file

^~.*

But, it is not working for the file name starting with ~(eg. ~$ofession email.docx).

There is no issue with gitignore configuration setting as other patterns are working well.

What is wrong here with the regular expression?

like image 539
Ram Limbu Avatar asked Mar 25 '17 19:03

Ram Limbu


People also ask

How do I ignore a text file in Gitignore?

You have the option to use double Asterisk (**) to match any number of directories and files. For example, Test/**/*. txt will tell git to ignore only files ending with . txt in the test directory and its subdirectories.

How do I Gitignore a file?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

Does git ignore any files by default?

git folder is ignored by default. All others are deamed potentially important for the source-base unless configured otherwise within the repository or at a global level.


2 Answers

You may escape a character by surrounding it with "[]":

[~][$]*

This will ignore any Microsoft temporary/backup files.

like image 113
Некто Лохматый Avatar answered Oct 10 '22 06:10

Некто Лохматый


Regular expressions are not supported in .gitignore, you can use globs only. To fix it, use ~*, that will ignore anything starts with tilde.

like image 30
hurturk Avatar answered Oct 10 '22 06:10

hurturk