Possible git bug (`git checkout` failure)

时间:2016-02-03 02:54:06

标签: git

This is the closest I can come a minimal example. (Granted, the example is weird, but that's par-for-the-course for minimal examples.)

Run the following script in some suitable scratch directory (e.g. /tmp). The script will create a directorydemo`, and initialize a repo in it. It will then create *two entirely distinct branches, having nothing in common.* These branches are populated from content coming out of two GitHub repos.

#!/bin/bash

rm -rf demo
mkdir demo
cd demo
git init
git commit -m 'root commit' --allow-empty

for URL in https://github.com/octocat/Spoon-Knife \
           https://github.com/octocat/hello-worId
do
    rm -rf content

    basename=$(basename $URL)
    branch_name=${basename%.git}
    git branch $branch_name
    git checkout $branch_name
    git clone $URL content
    rm -rf content/.git
    git add content
    git commit -m $branch_name
    git checkout master
done

git branch -a
git checkout Spoon-Knife

At the end of this script, the current branch is Spoon-Knife. If one now issues the command git checkout hello-world, git fails with the error:

error: pathspec 'hello-world' did not match any file(s) known to git.

Is this valid behavior?

1 个答案:

答案 0 :(得分:3)

You created the branch hello-worid but tried to checkout hello-worLd?

Not sure why you would name your repo like that and confuse yourself...