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

I get the following no matter what file I’m investigating:

git rev-parse --show-toplevel  (completed in 0.058s)
fatal: Not a git repository (or any of the parent directories): .git

This happens whether I have terminal open at the same location or not.

My seetings file includes:

  "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
  "git.path": "C:\\Program Files\\Git\\bin\\git.exe",
  "git.confirmSync": false,
  "git.enableSmartCommit": true,
  "gitProjectManager.baseProjectsFolders": [
    "E:\\simonl\\Documents\\_dev"
  ],

There is definitely a .git folder at the level of the file being investigated.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 5
  • Comments: 50 (5 by maintainers)

Most upvoted comments

You should first run git init in your current directory.

+1

This basically completely breaks this extension for me - it’s quite rare that I open a git repo as the root directory of the work-space.

@knapejor I’ve found that this bug have been fixed in version 0.4.3, it was released 4 days ago and your VS code have automatically updated extension. https://github.com/DonJayamanne/gitHistoryVSCode/pull/316 https://github.com/DonJayamanne/gitHistoryVSCode/releases/tag/0.4.3

Same problem again with 1.26.1…

Have just updated VSCode to 1.20.0 (Shell: 1.7.9, Renderer: 58.0.3029.110, Node: 7.9.0, Architecture: x64) and problem persists.

My workaround for the moment is to create a multi-root workspace. Now whenever I click the gitHistory button (top-right) it asks which root to use and all works OK.

Yup - I opened the folder within VSCode’s terminal and had it selected in the folder list on the left. BTW: running git rev-parse --show-toplevel in the terminal responds with the folder path correctly.

@arielf

Thanks, but this command is generated by Git History, I didn’t write / run the command myself. I can’t see any setting to alter the path, and as it was working before I believe something happened in Git History.

Any thoughts?

I have the same issue as sonnyandersson (now at Git History version 0.4.2 and VS Code version 1.26.1):

When opening Git History, selecting a commit and choosing ‘compare against previous version’, I get the following output:

git log --pretty=oneline b120949045fca8fc35a8509d2df8ee67afb201fb^1 -n 1 -- ..\..\..\c:\www\xxx\file.php (completed in 0.069s)

fatal: ..\..\..\c:\www\xxx\file.php: '..\..\..\c:\www\xxx\file.php' is outside repository

When choosing ‘Compare against workspace file’, an errors pops up with message ‘Corresponding workspace file does not exist’.

This functionality was working fine up until a few weeks ago.

+1 on v 0.4.1 in VS 1.25.0

I had the same issue (even though I don’t use VScode at all) and believe I figured out this bug.

Bug is triggered when git interacts with hooks that do a chdir/cd inside the hook process & then call git rev-parse --show-toplevel internally to figure out the git top level directory.

Just before calling any hooks, git sets several env vars, among them is one called GIT_DIR which points to the git index dir (if you’re at the top level, it will be set to .git prior to calling your hooks)

The GIT_DIR setting becomes invalid when the hook does a chdir and calls git reentrantly to figure out the git top level dir.

This is because git seems to have an internal optimization:

 if $GIT_DIR is set, trust it and use it

My work-around was simple: inside my hook, just before calling git rev-parse --show-toplevel I make sure to unset GIT_DIR (hook is a bash script) so git doesn’t get confused about which is its current directory.

No more errors after this simple work around.

I’m not sure what did happen but everything started to work like normal yesterday afternoon. In the morning the problem was still there, (When I placed my previous post / comment, I checked)

No updates / change logs can be seen but also no changes to our systems were made regarding to this, and it now works on all our repositories.

Can anyone else having these problems check this functionality?

@gcuevas82 can you please post the complete error?!

The error that I placed before is still there:

When opening Git History, selecting a commit and choosing ‘compare against previous version’ for a file, I get the following output:

git log --pretty=oneline b120949045fca8fc35a8509d2df8ee67afb201fb^1 -n 1 -- ..\..\..\c:\www\xxx\file.php (completed in 0.069s)

fatal: ..\..\..\c:\www\xxx\file.php: '..\..\..\c:\www\xxx\file.php' is outside repository

When choosing ‘Compare against workspace file’, an errors pops up with message ‘Corresponding workspace file does not exist’.

If the git commands fail then it’s not a git repo. Either way it’s outside the scope of the extension. Please confirm u having opened a git folder. Opening a file within a git folder isn’t sufficient. You need to open that folder within vscode.