0

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
sisko
  • 9,604
  • 20
  • 67
  • 139
  • Is it possible that you (or someone else) tracked the files you mention in an earlier commit ? In that case, you will need to untrack them by hand. – LeGEC Jul 11 '17 at 07:45
  • @LeGEC: I tried to remove the sites sub directory from GIT tracking but the feedback, (git rm --cached sites && fatal: pathspec 'sites' did not match any files), suggests it was NOT previously being tracked – sisko Jul 11 '17 at 08:59

1 Answers1

0

(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]
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • Sorry if I was being unclear. The issue is that when I change into Intranet/sites, GIT evidently at work within that directory and you can see the logs of the parent directory. My issue is that it shouldn't because I included *sites* in the .gitignore file – sisko Jul 11 '17 at 11:55
  • you mean : running `git log` from within `sites/` displays the history of `repo1` ? This is the expected behavior. – LeGEC Jul 11 '17 at 12:16
  • @sisko: Does `git log .` (<- note the extra '.') from `sites/` display any commit ? – LeGEC Jul 11 '17 at 12:20
  • "git log" from the sites directory shows commits for Repo#1. However, "git log ." does not show any commits. – sisko Jul 13 '17 at 12:55
  • @sisko: this means that, as expected, no commits have affected the content of the `sites/` directory. Do you see some other things which would lead you to think that `sites/` is not ignored ? – LeGEC Jul 13 '17 at 13:28
  • I've been giving this a lot of thought and I wish I was clearer on this issue but you are correct. I'm just confused why sites/ (though set to be ignored by git) shows git status data for it's parent directory. To me it seems like a bug. – sisko Jul 17 '17 at 13:04