Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitignore what is the meaning of *~ and these other patterns?

Tags:

git

gitignore

I came across this .gitignore file and could not understand it. Especially the first line *~ and the second one also.

Here are the complete contents for quick reference:

*~
\#*\#
*.swp
tmp/*
private/**/*
public/cache
.DS_Store
.#*
example_presentation.html

Please explain it. Where does one find the detailed syntax of patterns used by gitignore, (apart from the man-pages)?

I have already tried the man-pages, but sad to say, I found the patterns descriptions there to be less helpful. Hence the question.

like image 385
mntk123 Avatar asked Jul 12 '16 19:07

mntk123


People also ask

Which of the following patterns is are used to ignore a file or folder in Git?

gitignore is a plain text file in which each line contains a pattern for files or directories to ignore. It uses globbing patterns to match filenames with wildcard characters. If you have files or directories containing a wildcard pattern, you can use a single backslash ( \ ) to escape the character.

What is the meaning of in Gitignore?

gitignore file tells Git which files to ignore when committing your project to the GitHub repository. gitignore is located in the root directory of your repo.

What is the format of Gitignore?

A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .

What is exclamation mark in Gitignore?

An exclamation mark can be used to match any character except one from the specified set. debug[a-z].


1 Answers

There are two classes of expressions one put in a .gitignore file: expressions that match temporary files, backup files or files used by the development tools and expressions that match files from your project.

The first class matches files that are not needed by your project because they are generated by the tools, either for their own use or as backup of the files they modify.

The second class matches files that are needed by your project but they are either generated by the project's code or they are configuration files that contain sensitive information (i.e. passwords) and configuration settings that depend on the computer where the project runs.

The patterns you posted:

  1. backups, temporary files etc:

    • *~ - file names ending in ~ - they are created as backup copies by some editors on OSX and Linux; the Windows software usually replaces the file extension with .bak (or appends it);
    • \#*\# - quote from the documentation of .gitignore: "A line starting with # serves as a comment. Put a backslash ("\") in front of the first hash for patterns that begin with a hash." -- this means the second # doesn't need to be escaped.

      I don't know what software produces files whose name start and end with a # but, most probably, they are temporary files;

    • *.swp - temporary files used by vi to detect simultaneous edits of a file by two instances of the editor;
    • .DS_Store - files created by OSX Finder in each directory; they contain its internal bookeeping (thumbnails, sort order etc);
    • .#* - files whose names start with .#; I don't know any application that generates them; Emacs uses .#* for lock files to detect simultaneous edits (thanks @TobySpeight); there is no need to escape the #, see above;
  2. files used by your project but not needed in the repository:

    • tmp/* - many web applications generate temporary files in a directory named tmp or var/tmp or similar;
    • public/cache - the public directory is the part of the project that is visible through the web server; the cache subdirectory probably contains generated files (f.e. concatenated and minified scripts and CSS files) - they need to be visible from outside (public) without other processing but not needed in the repository because they are, well, generated during runtime;
    • private/**/*, example_presentation.html - these two are too specific; only your project can explain why the repository should ignore them.
like image 55
axiac Avatar answered Oct 13 '22 21:10

axiac