Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does git break if '/' is the root of the repository?

We'd like to use git to maintain system configurations. Because sometimes configuration data exists outside of /etc, we've started doing something like this on our systems:

  # cd /
  # git init
  # git add etc
  # git add some/other/path
  # git commit -m 'initial import'

And so forth. This works, up to a point. As long as your cwd == '/', git behaves normally. However, if you try, for example, to run git from inside a subdirectory:

cd /etc
git status

You get garbage. In our case, thousands of lines of "deleted:" listings for files that clearly still exist. This behavior appears to be exclusive to running git in /; doing the same thing anywhere else works just fine.

I can "fix" the behavior like this:

GIT_WORK_TREE=/ git status

And hey, everything works the way Linus intended...but this is a pain. I don't want to set it in the environment unilaterally (because this would conflict with the use of git in other repositories), and I'd like to avoid a wrapper script. Do I have any other options?

like image 434
larsks Avatar asked Dec 23 '09 02:12

larsks


People also ask

What is the root directory of the repository?

The repository root directory is the parent directory of the . hg directory. Mercurial stores its internal data structures – the metadata – inside that . hg directory.

How do you fix not a git repository or any of the parent directories?

To do so, you need to navigate to the correct folder and then run the command git init , which will create a new empty Git repository or reinitialize an existing one.

How do I fix the fatal not a git repository error?

Check that you correctly created the repo. If the directory doesn't contain a . git repo, use git init to properly initialize the repo or clone an existing repo. Make sure your HEAD file contains the correct information on your current branch.

How do I find my git root directory?

git-rev-parse --show-cdup gives you the right number of ".."s to get to the root from your cwd, or the empty string if you are at the root. Then prepend "./" to deal with the empty string case and use readlink -f to translate to a full path.


1 Answers

This is a complete guess that you could use to investigate further, but I suspect that git's "find the .git directory" behavior is interacting with the fact that / is its own parent directory. Maybe the "stop at the root" logic has a fencepost-type error.

like image 100
hobbs Avatar answered Oct 12 '22 08:10

hobbs