5

In a hook script for Git, I am trying to run a command like this..

please refer to(git --git-dir not working as expected)

git log --name-status --git-dir="C:\Documents and Settings\user\My Documents\Visual Studio 2008\Projects\CMS\.git" --work-tree="C:\Documents and Settings\user\My Documents\Visual Studio 2008\Projects\CMS"

when I run this command I am getting the following error.

fatal: Not a git repository (or any of the parent directories): .git

Is there any thing wrong in the command I am using?

2 Answers 2

8

I recently had this problem on Mac, the solution for me was to put the --git-dir and --work-tree directives before the git subcommand.

So, your command would look like this:

git --git-dir="C:\Documents and Settings\user\My Documents\Visual Studio 2008\Projects\CMS\.git" --work-tree="C:\Documents and Settings\user\My Documents\Visual Studio 2008\Projects\CMS" log --name-status

HTH, it did the trick for me.

Sign up to request clarification or add additional context in comments.

2 Comments

It's odd that it works for anyone with it after. --git-dir is an option for git, not for log.
Thanks it solves the problem on Windows also: "c:\program files (x86)\git\bin\git.exe" --git-dir="c:/path/to/repo/.git" --work-tree="c:/path/to/repo" commit -m"Message" c:\path\to\repo\file.test
4

Since it is a hook script, it will probably use POSIX paths, in a bash session, not Windows paths.

git log --name-status --git-dir='/C/Documents and Settings/user/My Documents/Visual Studio 2008/Projects/CMS/.git' --work-tree='/C/Documents and Settings/user/My Documents/Visual Studio 2008/Projects/CMS'

From a DOS session (as in "not a hook), the path might have looked like:

git log --name-status --git-dir='C:/Documents and Settings/user/My Documents/Visual Studio 2008/Projects/CMS/.git' --work-tree='C:/Documents and Settings/user/My Documents/Visual Studio 2008/Projects/CMS'

Alternative syntax (not tested): "c:\\xxx\\yyy\\..."

1 Comment

@Syam: I have updated my answer with POSIX path. Give it a try.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.