简体   繁体   中英

How to not ignore everything in the parent repo when the child repo ignores everything?

I have a repo that ignores everything except a few files and the .gitignore looks like this:

# first ignore everything
*

# then whitelist what's needed
!*/
!.gitignore
!wordpress/wp-content/plugins/check-last-login/*
!wordpress/wp-content/plugins/wp-issuetracker/*
!mediawiki/extensions/single-signon/*

This repository is a child repository. It is inside of another repository, the parent. The child repository is ignoring everything except the few things just fine, but the parent is also doing the same, but I don't want it to.

It seems like the parent repo follows the ignore rules of the child repo's .gitignore file. I tried .gitignoring the .gitignore file of the child repo but that didn't work in making the parent track all files.

How can I make the parent not ignore any of the files that the child ignores?

Okay, I can make git do this the obvious way, by doing git init in a directory that already has tracked content, and the smoketests all work. I certainly wasn't expecting that. git's apparently following existing trees (the repo objects) into the submodule:

   # in a throwaway clone of an existing project
   git init src
   cd src
   mkdir -p .git/info
   echo "*.junk" >.git/info/exclude
   touch foo.junk; git add .; git commit -m-
   git ls-files -s
   cd ..
   git add src
   git ls-files -s src

and I've got parallel histories. That actually makes at least some sense; it usually doesn't care at all about files that aren't tracked, and git add has to ignore .git in the root tree. For what concrete reason should git refuse to do this? I can't think of one offhand.

I'd be mildly worried that someone will perhaps rather arbitrarily decide this behavior's a bug and make git start checking for .git s on the way down, but thinking about it I think hardcoding ignore- .git -even-in-subtrees rather than only in the root might even be intentional. It might leave you with some handroll synchronization if you ever start collaborating with other repos rather than just publishing, but writing the scripts to do it seems straightforward at first glance, and you're plainly getting some value out of the setup. <shrug>.

As you've discovered, repo-local excludes go in .git/info/exclude .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM