Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I ignore a directory in the root of my git repository, but include it further down in the tree?

Tags:

git

I need to use .gitignore to exclude a directory in the root of my repository. However, other directories with the same name exist deeper in the directory tree, and I need those to be included. It seems that when I put the name of the directory into .gitignore, it catches all of these directories, not just the one I need to ignore. I understand that .gitignore is actually not a list of files, but patterns. So how can I construct a pattern to ignore just a file in my root directory, but not files with the same name further down?

like image 213
skiphoppy Avatar asked Jan 23 '09 14:01

skiphoppy


People also ask

How do I ignore an entire directory in git?

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.

Should Gitignore be in root folder?

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 .

How do I ignore files while pushing to git repository?

Excluding local files without creating a .Use your favorite text editor to open the file called . git/info/exclude within the root of your Git repository. Any rule you add here will not be checked in, and will only ignore files for your local repository.


1 Answers

Use a leading /

  /file.x 

That will only match a top level file.x but not one lower down, in "want/file.x", say.

like image 145
richq Avatar answered Sep 17 '22 21:09

richq