I am trying to tell git to ignore files which have _autosave
somewhere in the filename. An example of such a file is:
hats/TFCB_ATV_TOP_HAT/_autosave-TFCB_ATV_HAT.kicad_pcb
In a regular expression, I would simply use the pattern ^.*_autosave.*
Of course, git doesn't use regular expressions to evaluate its .gitignore file. I did some reading and had the impression that *_autosave*
would work, but it doesn't.
What is the correct syntax to tell git to ignore these files?
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.
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.
Use Git update-index to ignore changes Or, you can temporarily stop tracking a file and have Git ignore changes to the file by using the git update-index command with the assume-unchanged flag.
gitignore should contain all files that you want to ignore. Therefore, you should ignore files generated by the OS, the IDE you are working on... My question appears when the repository is on Github and people can clone it and push the changes. These people can use other operating systems and can use other IDEs.
Add this line to your .gitignore
*_autosave*
According to git help gitignore
patterns match relative to the location of the .gitignore file
Patternz like *_autosave*
match files or directories containing "_autosave" somewhere in the name.
Two consecutive asterisks ("**") in patterns mathed against full pathname may have special meaning
A leading "**" followed by a slash means match in all directories.
But "**/" seams redundant in some enviroments.
EDIT:
My machine at work (using git 1.7.1) does not have support for dubbel asterisk, but with *_autosave*
it excludes the files.
here is a simple test scrtipt (for Linux)
DIR="$(mktemp -d)" git init $DIR/project1 cd $DIR/project1 cat > .gitignore <<EOF **/*_autosave* *_autosave* EOF mkdir dir1 touch README foo_autosave dir1/bar_autosave git status rm -rf $DIR/project1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With