iAmoric
iAmoric

Reputation: 1965

git checkout error: pathspec '?0c69153...' did not match any file(s) known to git

Using Powershell, i'm trying to checkout a specific git commit using a variable.

Without the variable, it works well as expected:

> git checkout 0c69153xxxxx
Note: switching to '0c69153xxxxx'.

[...]

HEAD is now at 0c69153 

Now, in my script I compute dynamically the commit sha and save it in a variable.

I checked the content of the variable and it's ok:

> $commit_sha
0c69153xxxxx

> $commit_sha.GetType().Name
String

But now the same command using the variable doesn't work:

git checkout $commit_sha
error: pathspec '?0c69153xxxxx' did not match any file(s) known to git

why checkout command think I want to use pathspec? How can I do the checkout using my variable?

Thanks

Upvotes: 1

Views: 110

Answers (1)

iAmoric
iAmoric

Reputation: 1965

$commit_sha contained a hidden whitespace.

Solution was to trim the variable before using it:

> $commit_sha.Length
41
> $commit_sha = $commit_sha.Trim()
> $commit_sha.Length
40
> git checkout $commit_sha
Note: switching to '0c69153xxxxx'.

[...]

HEAD is now at 0c69153

Upvotes: 1

Related Questions