Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore with wildcards for filenames [duplicate]

My .gitignore file has the following entries. I am trying multiple things here as I can't seem to get my file ignored;

WinAppSetup/*.exe
/WinAppSetup/*.exe
WinAppSetup/setup.exe
**/WinAppSetup/setup.exe

When I run git status from git bash, I still see;

    modified:   WinAppSetup/setup.exe

What entry in my .gitignore will allow me to ignore this file?

After editing .gitignore, do I need to close and re-open git bash to have the .gitignore file re-read?

UPDATE

As per user2407038's comment, the issue was that the file already existed in the repository. I was able to remove the file locally, stage and then commit those changes and update my remote. A new build of the application then successfully ignored the file.

It seems I can also update my .gitignore file without having to close and re-open git bash too.

like image 535
Mr Moose Avatar asked Jan 24 '18 02:01

Mr Moose


People also ask

How do I use wildcards in Gitignore?

. 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.

Does Gitignore get cloned?

The process of cloning ignores the . gitignore file. If a file is added, committed and another commit with the . gitignore is created, the file will still be part of the repository and therefore cloned.

How do I ignore a specific file 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.

What is double star in Gitignore?

A trailing " /** " matches everything inside. For example, " abc/** " matches all files inside directory " abc ", relative to the location of the . gitignore file, with infinite depth. A slash followed by two consecutive asterisks then a slash matches zero or more directories.


Video Answer


1 Answers

.gitignore won't ignore a file that's already in your repository. You have to first remove the file for your repository.

You can remove a file from the repository without deleting the actual file with git rm --cached.

git rm --cached WinAppSetup/setup.exe

In this sort of situation I usually have the new .gitignore entry and the removal of the ignored file from the repository in the same commit.

like image 120
Schwern Avatar answered Oct 30 '22 16:10

Schwern