Git: cannot checkout branch - error: pathspec '…' did not match any file(s) known to git

后端 未结 30 3053
太阳男子
太阳男子 2020-11-27 23:54

I\'m not sure why I\'m unable to checkout a branch that I had worked on earlier. See the commands below (note: co is an alias for checkou

相关标签:
30条回答
  • 2020-11-28 00:46

    On Windows OS by default git is instaled with

    core.ignorecase = true
    

    This means that git repo files will be case insensitive, to change this you need to execute:

    \yourLocalRepo> git config core.ignorecase false
    

    you can find this configuration on .git\config file

    0 讨论(0)
  • 2020-11-28 00:46

    Happened to me after renaming an uncommitted file in Android Studio.

    Git seemed to have the old version in its repository, even if it didn´t exist anymore.

    fetch, pull, checkout, add all and so on did not help in my case!
    

    So I opened the Git GUI of TortoiseGit which showed me the exact file that caused trouble.

    Afterwards I deleted the file from the repository with

    git rm -r --cached /path/to/affected/file
    

    and the problem was gone

    0 讨论(0)
  • 2020-11-28 00:47

    check whether it is not a typo in the target file name. I was attempting to stage by typing

    git add includes/connection..php
    

    But I did not notice that I was using two dots But then I type

    git add includes/connection.php
    

    It works

    0 讨论(0)
  • 2020-11-28 00:49

    I got this error for a branch that was remote and had no local tracking branch. Even though I'm certain I've checked out remote branches via a simple

    git checkout feature/foo
    

    in the past, to get around this error I had to

    git checkout -t -b feature/foo origin/feature/foo
    

    I have no idea what I did to get myself into that situation either.

    0 讨论(0)
  • 2020-11-28 00:49

    I fixed it by modifying my git config file Check your the config file in your git directory - .git\config

    It previously had

    [remote "origin"]
    url = http://git.xyz.com/abc-group/pqr.git
    fetch = +refs/heads/develop:refs/remotes/origin/develop
    

    I fixed by modifying it to

    [remote "origin"]
    url = http://git.xyz.com/abc-group/pqr.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    

    Notice the head was pointing to only one branch, so it couldnt find the reference to other existing branches, I changed it to * so it checks everything in origin.

    0 讨论(0)
  • 2020-11-28 00:52
    git pull
    

    That simply fixed it for me :)

    0 讨论(0)
提交回复
热议问题