1
git show $(git rev-list --max-count=1 --all -- ranker/knowledge/city_province_map.py)^:ranker/knowledge/city_province_map.py

This gives me the error:

fatal: bad revision '^:ranker/knowledge/city_province_map.py'

I also tried:

git show HEAD^:ranker/knowledge/city_province_map.py

But this gives a similar error:

fatal: path 'ranker/knowledgw/city_province_map.py' does not exist in 'HEAD^'

I have a file deleted a while a ago and I want to see its content and restore it to the repository. I executed the two commands at the root directory of the git project in my local machine.

How to do that?

marlon
  • 6,029
  • 8
  • 42
  • 76
  • 1
    The file doesn't exist in the commit which `HEAD^` points to. Consider reading https://stackoverflow.com/questions/44768004/find-deleted-file-in-git? – evolutionxbox Oct 09 '22 at 18:42
  • 2
    If you run `git rev-list --max-count=1 --all -- ranker/knowledge/city_province_map.py` (without the `$(...)`, by itself), what comes out? – torek Oct 09 '22 at 19:57
  • Follow torek's suggestion. The first error suggests that `$( git rev-list .... )` returns an empty output (nothing is mentioned before the `^`), the second command that your file was already deleted in `HEAD^`. – LeGEC Oct 10 '22 at 08:27
  • Also, rule out any typo : does `git show HEAD^:` mention a `ranker/` directory ? with that exact same all lowercase name ? what about `git show HEAD^:ranker/` and `git show HEAD^:ranker/knowledgw/` ? – LeGEC Oct 10 '22 at 08:28

1 Answers1

0

I suspect you have the format.pretty config set, which affects rev-list. You can check this of course with git config -l | grep format.pretty

From the docs for rev-list:

--pretty[=<format>]
--format=<format>
    Pretty-print the contents of the commit logs in a given format, [...]

    Note: you can specify the default pretty format in the repository configuration (see git-config(1)).

And in docs for config:

format.pretty
    The default pretty format [...]
Mike Kim
  • 115
  • 6
  • Hi, nice contribution, unfortunately I think you hit an issue in git's documentation : `git rev-list` does have the `--pretty/--format` option, but isn't affected by the configuration setting. That doc paragraph about `--format` is shared by the following commands : `git log`, `git rev-list` and `git show`. The "... in the repository configuration ..." line is also copied, but incorrect for `rev-list`. On the `git help config` side of things : you can see : `format.pretty : The default pretty format for log/show/whatchanged command` – LeGEC Oct 10 '22 at 08:24