Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git ignoring .gitattributes pattern

I've a directory structure like this:

root/
  .git
  deploy/
  Site/
    blah/
    more_blah/
      something.local
      else.development
    Rakefile
    .gitattributes

Edit: to further clarify the above, directories have a trailing / and children are indented beneath a directory, so blah and more_blah are directories but Rakefile and .gitattributes are files, but all four are children of Site.


I'm running git-archive from the Site directory like so:

git archive --format=tar --prefix=git-v0.0.1/ v0.0.1 | gzip > ../deploy/git-v0.0.1.tar.zip

but whatever pattern I put in .gitattributes, the resulting archive always contains Rakefile. I've tried:

  • Rakefile
  • Site/Rakefile
  • */Rakefile
  • ./Rakefile
  • Rakefile*
  • *

None of them work as I'd expect. Is anyone willing to point out the obvious yet non-obvious to me solution? Any help is much appreciated.


My apologies for not being clear.

  • I said the pattern I was using didn't seem to work, but I am using "export-ignore" after the pattern.
  • Rakefile is not a directory, just a file
  • The .gitattributes file is successful in removing other patterns from the archive, Rakefile is not the only pattern used, but is the only one that doesn't work. It doesn't work whether I have it on its own or with other patterns, and at any place in the file. This is not true, due to having renamed certain files but not archiving the commit with the rename I was appearing to get some good results. My bad! :S

This is my .gitattributes (sitting in the directory Site)

Rakefile        export-ignore
*.local         export-ignore
*.development   export-ignore
*.staging       export-ignore
like image 641
ian Avatar asked Apr 02 '11 17:04

ian


2 Answers

Not sure this is common case but I had trouble excluding folder tests from source tree which have many nested levels of folders. If I wrote only this line to .gitattributes

tests/* export-ignore

It didnt work and entire directory was remain in archive. The solution was to add wildcards for all subdirs levels:

tests/* export-ignore
tests/*/* export-ignore
tests/*/*/* export-ignore
tests/*/*/*/* export-ignore
tests/*/*/*/*/* export-ignore

With these lines the tests directory finally disappeared from archive.

like image 66
Alexander Pravdin Avatar answered Oct 02 '22 03:10

Alexander Pravdin


If you want git to ignore a file put it in the .gitignore file not the .attributes file.

If you want to ignore your Rakefile put the following in the .gitignore file at the root of your project.

/**/Rakefile

Specify the full path if you have more than one and you only want to ignore one of them.

A few examples of how to implement pattern matching for these files:

For All Files in All Folders
/**/*.ext
For A File in All Folders
/**/some_file.ext
File in Root Folder
/some_file.ext
File in A Folder
/some_folder/some_file.ext
All Files in A Folder
/some_folder/*
like image 29
JerodG Avatar answered Oct 02 '22 02:10

JerodG