Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore everything in root directory for WordPress.gitignore #3378

Open
wants to merge 2 commits into
base: master
from

Conversation

@loteoo
Copy link

@loteoo loteoo commented Apr 18, 2020

Reasons for making this change:
I think that first line was missing in the .gitignore, am I wrong?

Links to documentation supporting these rule changes:

This first line in the current repository points to this ignoring everything in the root directory:
https://github.com/github/gitignore/blob/master/WordPress.gitignore#L1

Thanks

I think that first line was missing in the .gitignore, am I wrong?

Thanks
@loteoo loteoo changed the title Ignore everything in root directory Ignore everything in root directory for WordPress.gitignore Apr 18, 2020
@LucasLarson
Copy link

@LucasLarson LucasLarson commented Apr 19, 2020

I think that first line was missing

.gitignore files don’t use /* PHP-style comments */

   

am I wrong?

Probably. Your change uses valid .gitignore syntax, but not in the way I imagine you intended:

  1. the leading / refers to the directory separator, and
  2. the * matches everything except /,

so adding this .gitignore would permit Git to ignore any file in the same directory whose name was a single character, but wouldn’t

Ignore everything in root directory for WordPress.gitignore

@loteoo
Copy link
Author

@loteoo loteoo commented Apr 19, 2020

@LucasLarson Thanks for the feedback!

I was not trying to add a php style comment, but trying to ignore everything in the root directory, except (the other lines that have a ! in front of it)

This configuration (with the modification I added) works great on my windows machine with gitbash, but maybe my machine is a edge-case.

Without it, all the files of WordPress core are tracked with the repo. With it, only the plugin / theme files are tracked (which is what I was looking for in my case)

@LucasLarson
Copy link

@LucasLarson LucasLarson commented Apr 24, 2020

I don’t think this is production-ready yet.

.gitignore is already built to ignore or skip everything in a directory unless otherwise specified. Adding the /* line to an existing .gitignore does nothing to your repo unless you also run git rm -rf --cached: “The files/folder in your version control will not just delete themselves just because you added them to the .gitignore” and if they’re “already in the repository” then “you have to remove them” yourself (via Ahmad on StackOverflow).

If the user will already have to git rm -rf --cached, then there is no need to add this line, because those entries will already be skipped unless they’re in this .gitignore’s other rules.

@tywmick
Copy link

@tywmick tywmick commented Apr 29, 2020

.gitignore is already built to ignore or skip everything in a directory unless otherwise specified.

I'm on Git 2.23.0, and using this .gitignore without a /* at the beginning, in a freshly downloaded WordPress folder, after git init and before any commits, VS Code tells me there are 1,694 pending changes:

.gitignore without /*

After adding /* (and !.gitignore), VS Code tells me there are 29 pending changes:

.gitignore with /*

Also, gitignore's documentation says that with the !, "any matching file excluded by a previous pattern will become included again", and their example at the end for excluding everything except a specific directory includes a /* at the top:

Example to exclude everything except a specific directory foo/bar (note the /* - without the slash, the wildcard would also exclude everything within foo/bar):

$ cat .gitignore
# exclude everything except directory foo/bar
/*
!/foo
/foo/*
!/foo/bar
Copy link

@LucasLarson LucasLarson left a comment

This does exactly what it should (and doesn’t unnecessarily commit the entire WordPress installation to a repository).

And mea culpa – it didn’t occur to me that we shouldn’t copy the entire installation.

Copy link

@pedrosanta pedrosanta left a comment

As I explain in #3295, I don't think the catch-all approach is the best for this .gitignore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants