When I run git show HEAD^:file.txt
git displays the content of this file at revision HEAD^
.
But when I run this command with the absolute path, i.e.: git show HEAD^:/home/me/repo/file.txt
it fails (exit code 128) with the message
fatal: path ‘/home/me/repo/file.txt’ exists on disk, but not in ‘HEAD^’
What would be an elegant way to show my file at revision HEAD^ when all my script has is the full path?
More details:
- I’m trying to get my
git show
command to work in a script. All I know is that the current working directory (from which the script is invoked) is in the git repo, but I don’t have more clues about the layout of this repo - My script should work on all my teammates laptops. I can’t make a lot of assumptions on their environment so I cannot use trick like leveraging Perl of Python to convert the absolute path to a local one
- Overall I’m pretty surprised because other git commands seem to handle absolute paths just fine (for instance
git diff -- /home/me/repo/file.txt
behaves correctly)