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

后端 未结 30 3052
太阳男子
太阳男子 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:43

    I faced the issue while switching my branch.

    I did a git pull on the current branch and then tried to checkout the new one and it worked

    git pull // on your old branch git checkout <new_branch>

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

    If it happens on Windows, it is probably the filename case issue.

    I had this error today - I've created new file, added to GIT, then I changed one letter in filename from lower to upper and then I couldn't to anything - commit, revert, delete file from repo.

    The only solution I found was changing the filename again back to exact same case when I added this file to GIT, then doing GIT revert to remove this file from GIT, then changing filename again as I want. After those changes I could commit to repo and then push without any problem.

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

    None of these answers solved my issue:

    Nikolai@CALIGARI-7 ~/Documents/NetBeansProjects/Version (master)
    $ git log --format=oneline
    b9cc6a9078312865280fb5432a43e17eff03a5c6 Formatted README
    288772f36befe6bd60dd41b8185f1e24e0119668 Updated README documentation
    d2bdbe18f4169358d46fad50eacfb89786df3bf8 Version object v3.0.0-SNAPSHOT
    a46b1910a3f548b4fa254a6055d25f68d3f217dd VersionFactory is now Platform agnostic
    24179ae569ec7bd28311389c0a7a85ea7b4f9594 Added internal.Platform abstraction
    252b684417cf4edd71aed43a15da2c8a59c629a7 Added IPlugin implementation for Sponge
    e3f8d21d6cf61ee4fc806791689c984c149b45e3 Added IPlugin implementation for Bukkit
    aeb403914310b4b10dee9e980cf64472e2bfda79 Refactored Version.java
    ef50efcff700c6438d57f70fac30846de2747a7e Refactored TesterFactory
    a20808065878d4d28657ae362235c837cfa8e625 Added IPlugin abstraction
    9712a3575a70060d7ecea8b62bb5e888fdc32d07 Heavily refactored Tester
    02d025788ae740dbfe3ef76a132cea8ca4e47467 Added generic Predicate<T> interface
    9c565777abea9be6767dfdab4ab94ed1173750dd Minor refactoring of testCompareTo()
    2ff2a28c221681e256dcff28770782736d3a796a Version object v2.0.1
    d4b2e2bd830f77cdbc2297112c2e46b6555d4393 Fix compareTo()
    05fe7e012b07d1a5b8de29804f96d9a6b24229a1 Make compareTo() fail
    6e85371414357a41c1fc0cec0e75adba92f96832 Fix VersionFactory passing null
    c1fd1f032f87d860d5ed9d6f6679c9fa522cff8d Version object v2.0
    62c3a92c008a2ed11f0a4d016080afc3541d0700 Version object v1.2
    c42e9e617128085e872c51b4d977a04e48d69e8f Deprecated, doc'd, future-proofed getNm
    
    
    Nikolai@CALIGARI-7 ~/Documents/NetBeansProjects/Version (master)
    $ git checkout 3a796a
    error: pathspec '3a796a' did not match any file(s) known to git.
    

    I was trying to go back and build the commit for Version object v2.0.1. Luckily, I got the idea to try the whole hash code and it worked ! Which means that I was using the wrong end of the hash code.

    Nikolai@CALIGARI-7 ~/Documents/NetBeansProjects/Version (master)
    $ git checkout 2ff2a
    Note: checking out '2ff2a'.
    
    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by performing another checkout.
    
    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -b with the checkout command again. Example:
    
      git checkout -b new_branch_name
    
    HEAD is now at 2ff2a28... Version object v2.0.1
    
    Nikolai@CALIGARI-7 ~/Documents/NetBeansProjects/Version ((2ff2a28...))
    $
    

    As shown above, for partial hash codes, you must supply the front-end, not the back-end.

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

    Git Windows users beware - without the --icase-pathspecs or GIT_ICASE_PATHSPECS = 1 env var setting, that git pathspecs will be case-sensitive, in which case

    git checkout origin/FooBranch "Some/Path/To/File.txt"
    

    is not the same as

    git checkout origin/FooBranch "some/path/to/file.Txt"
    
    0 讨论(0)
  • 2020-11-28 00:45

    I had this problem today I was trying to git checkout foo and got error: pathspec 'foo' did not match any file(s) known to git.

    It turns out I was in the wrong repo. So lesson learned: check which repo you're looking at before freaking out.

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

    If you deleted a branch with git branch -D yourbranchname and pulled/cloned again your repo, you may need to create your local branch again.

    Try:

    git checkout -b yourbranchname
    
    0 讨论(0)
提交回复
热议问题