git rm --cached and fatal: pathspec

前端 未结 3 1042
夕颜
夕颜 2021-01-07 19:50

I just tried to checkout my master branch and ran into:

error: Untracked working tree file \'app.xcodeproj/project.xcworkspace/xcuserdata/u.xcuserdatad/UserI         


        
相关标签:
3条回答
  • 2021-01-07 20:06

    So, the solution is this:

    The file is untracked in this current branch B

    But it exists in the branch we are trying to check out, branch A, so we get a warning that the file in our current working tree will be overwritten (even though we aren't tracking it)

    So:

    1. delete the file in your existing directory (I just moved it somewhere out of the working tree initially to be safe) of branch B

    2. check out the branch you want - i.e. branch A

    3. Remove it from branch A using something like this:

      git rm --cached app.xcodeproj/project.xcworkspace/xcuserdata/u.xcuserdatad/UserInterfaceState.xcuserstate

    Note: Fwiw, Branch A was my master branch. Branch B was my dev branch.

    0 讨论(0)
  • 2021-01-07 20:07

    For the issue in the question title, you can generally solve it this way:

    git rm --cached *
    
    fatal: pathspec 'blah' did not match any files 
    
    git ls-files
    

    That will list the files git does have in its index, and you can then remove them explicitly one by one. If for example it lists img/blah.jpg:

    git rm --cached img/blah.jpg
    

    This will solve the pathspec error in the more general case, whether it's a branching issue as it was in the other answer here, or a new .gitignore entry, or a result of using 2 repos in the same dir, etc.

    0 讨论(0)
  • 2021-01-07 20:14

    simple:

    git add file.ext
    git rm --cached file.ext
    

    or

    git add path/*
    git rm --cached path/*
    
    0 讨论(0)
提交回复
热议问题