Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`git show` not working: "fatal: Path [mypath] exists on disk, but not in [mybranch]"

Tags:

git

Problem

I'm trying to view the contents of a file located in a branch named wip like so:

git show wip:local-config.php

However, I'm receiving the following error:

fatal: Path 'local-config.php' exists on disk, but not in 'wip'.

What I tried

I tried correcting the path but it failed:

git show wip:./local-config.php

Rather than using another branch, I tried to reference a previous commit from the same branch like so:

git show cd14704:local-config.php

That gave this error:

fatal: Path 'local-config.php' exists on disk, but not in 'cd14704'.

Finally when I try to show the current local-config.php I get no output at all:

git show local-config.php

The docs

According to the manual this is possible: https://www.kernel.org/pub/software/scm/git/docs/git-show.html. What am I doing wrong?

like image 222
JP Lew Avatar asked Sep 12 '13 03:09

JP Lew


3 Answers

It sounds like the file you're searching for does not exist in any commits within wip. git show will only display tracked objects with some history in the refspec you provide it (in this case, wip, or cd14704). To get the expected behavior you'll need a commit with that file present.

like image 87
Chris Hayes Avatar answered Oct 06 '22 13:10

Chris Hayes


FYI, I got this same error when I was accidentally using the full path to the file:

git show rev:/path/to/repo-root/folder/my-file

But you need to use the relative path from the repo root:

git show rev:folder/my-file
like image 27
Jeff Ward Avatar answered Oct 06 '22 14:10

Jeff Ward


I experienced exactly the same thing. The problem was that I used backslashes in my file path. So I replaced them by regular slashes and it started working just fine. Very confusing.

like image 4
the_V Avatar answered Oct 06 '22 12:10

the_V