JuniorIncanter
JuniorIncanter

Reputation: 1579

Git fatal: ambiguous argument 'commit hash': unknown revision or path not in the working tree

I'm trying to use the git CLI to do some rather simple scripting. What I'm ultimately trying to do is to use git to show all of the file changes between two commits, which should be as simple as something like 'git diff [commit1] [commit2]'.

But I can't even get the diff for one commit with 'git diff [commit]'. I used git init to create a repo locally, then made some dummy files and folders. I tried using git diff and ran into this problem. I thought maybe the problem was that I wasn't using a branch, so tried creating one via 'git checkout -b my/branch', made some more commits, and I'm still getting this problem.

I tried searching on here and found situations & solutions that were significantly more complicated than the simple scripting use case I'm trying to prototype here.

λ git log
commit 6d107f6bcff58b263d8611c19c770c6370d7a33c (HEAD -> my/branch)
Author: ---
Date:   Tue Oct 13 15:07:35 2020 -0700

    filemodcheck

λ git diff c6370d7a33c
fatal: ambiguous argument 'c6370d7a33c': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

This problem also repro's if I send something like 'git diff [commit1] [commit2]' and if I pick a commit from master instead of from the branch, despite all of the selected commits being found via 'git log'.

Thanks in advance!

Upvotes: 0

Views: 1777

Answers (1)

prosoitos
prosoitos

Reputation: 7327

That's because you are using the last characters of the hash instead of the first ones.

Try:

git diff 6d107f6

A short Git hash is made of the first n characters (7 by default) of the SHA-1 checksum. Since you were using the last characters, Git could not recognize the hash.

Upvotes: 2

Related Questions