Search code examples
gitdrupal-7gitignore

Git ignore issues


How do I excluded a directory from being tracked by Git? My Git ignore entry does not work.

I've got a confusing issue with my Drupal website in which I am using two Git repositories.

The basic structure of the site is : var/www/Intranet/sites/intranet

In the Intranet/sites/intranet is my first Git repository which is where I maintain custom and contributed code using Git to version control.

In order to version control the Drupal core code base, I initiated a new GIT repository at var/www/Intranet. This new repo is meant to track everything except the contents of the sites sub directory. To this end I added sites to the .gitignore file.

But, what I've noticed recently is when I go to var/www/Intranet/sites, it is still being tracked by the new Git repo (var/www/Intranet) which should NOT be the case.

I'm not sure why that is happening.


Solution

  • (I first misread your question.)

    If you have two nested git repos :

    Intranet   # <- repo1
    +- .git/
    +- sites/
     +- intranet  # <- repo2
      +- .git/
    
    • from repo1, git will automatically find out that sites/intranet is another repo, and not try to track anything inside it,
    • from repo2, git will show you the history of repo2, and report any changes for files in repo2

    If you run a flat git log from anywhere within the repository, you will see the history of the whole repository.

    If you want to check what changes affected a particular file or directory (a path) :
    you should run git log [path]

    If you run git log sites/ for example (or equivalently : cd sites/; git log .) you should see that nothing has ever been commited in the sites/ directory.

    Likewise :

    • git status will output info about files of the whole repo
    • git status [path] will restrict its output to files contained in [path]