Let's say I have a git repo for my stuffs inside a directory myapp
:
myapp
/.git
/.gitignore
/subdirA
/subdirB
/file1.txt
/file2.txt
/(and some other stuffs)
/(and some other stuffs)
I want to view file1.txt
from an old commit abcd123
. For another thread, I learnt that I should use something like:
$ git show abcd123:path/to/file1.txt
However, I am confused about the right path to use. I've tried something like
$ git show abcd123:myapp/subdirA/subdirB/file1.txt
$ git show abcd123:subdirA/subdirB/file1.txt
$ git show abcd123:subdirB/file1.txt
$ git show abcd123:file1.txt
but git keeps giving me error messages like
$ Path 'subdirA/subdirB/file1.txt' does not exist in 'abcd123'
How to solve this problem?
This command will generate a list of paths that exist in comment
abcd123
:Anything you get from that command should work as a path for
git show abcd123:...
Also, it's easier sometimes to use a leading
./
on the path. That automatically replaces the.
with the path from the repository root to your current directory in the working tree. For example:If you try
git show abcd123:Makefile
it doesn't work... but git does suggest ("Did you mean...?") both the version with the full path from the repository root and the version with the./
... unless you also have aMakefile
in the root directory ofabcd123
in which case you just get that with no warning that you might have wanted./Makefile
instead.