Development Tip

Git : cannot checkout branch-오류 : pathspec '…'이 (가) git에 알려진 파일과 일치하지 않습니다.

yourdevel 2020. 10. 2. 23:22
반응형

Git : cannot checkout branch-오류 : pathspec '…'이 (가) git에 알려진 파일과 일치하지 않습니다.


이전에 작업 한 지점 을 체크 아웃 할 수없는 이유를 모르겠습니다 . 아래 명령을 참조하십시오 (참고 : co는의 별칭 checkout임).

ramon@ramon-desktop:~/source/unstilted$ git branch -a
* develop
  feature/datts_right
  feature/user_controlled_menu
  feature/user_controlled_site_layouts
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/develop
  remotes/origin/feature/datts_right
  remotes/origin/master
ramon@ramon-desktop:~/source/unstilted$ git co feature/user_controlled_site_layouts 
error: pathspec 'feature/user_controlled_site_layouts' did not match any file(s) known to git.

무슨 뜻인지 잘 모르겠고 Google에서 이해할 수있는 내용을 찾을 수없는 것 같습니다.

그 지점을 어떻게 체크 아웃하고 이것을 깨기 위해 무엇을 할 수 있습니까?

업데이트 :

이 게시물을 찾았고 실행 git show-ref하면 다음 같은 결과가 나타납니다 .

97e2cb33914e763ff92bbe38531d3fd02408da46 refs/heads/develop
c438c439c66da3f2356d2449505c073549b221c1 refs/heads/feature/datts_right
11a90dae8897ceed318700b9af3019f4b4dceb1e refs/heads/feature/user_controlled_menu
c889b37a5ee690986935c9c74b71999e2cf3c6d7 refs/heads/master
c889b37a5ee690986935c9c74b71999e2cf3c6d7 refs/remotes/origin/HEAD
e7c17eb40610505eea4e6687e4572191216ad4c6 refs/remotes/origin/develop
c438c439c66da3f2356d2449505c073549b221c1 refs/remotes/origin/feature/datts_right
c889b37a5ee690986935c9c74b71999e2cf3c6d7 refs/remotes/origin/master
23768aa5425cbf29d10ff24274adad42d90d15cc refs/stash
e572cf91e95da03f04a5e51820f58a7306ce01de refs/tags/menu_shows_published_only
429ebaa895d9d41d835a34da72676caa75902e3d refs/tags/slow_dev

에 UPDATE .git디렉토리 ( user_controlled_site_layoutsrefs/heads/feature folder) :

$ ls .git/refs/heads/feature/
datts_right  user_controlled_menu  user_controlled_site_layouts
$ cat .git/refs/heads/feature/user_controlled_site_layouts
3af84fcf1508c44013844dcd0998a14e61455034

업데이트 git show 3af84fcf1508c44013844dcd0998a14e61455034

$ git show 3af84fcf1508c44013844dcd0998a14e61455034
commit 3af84fcf1508c44013844dcd0998a14e61455034
Author: Ramon Tayag <xxx@xxxxx.xxx>
Date:   Thu May 12 19:00:03 2011 +0800

    Removed site layouts migration

diff --git a/db/schema.rb b/db/schema.rb
index 1218fc8..2040b9f 100755
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended to check this file into your version control system.

-ActiveRecord::Schema.define(:version => 20110511012647) do
+ActiveRecord::Schema.define(:version => 20110503040056) do

   create_table "attachments", :force => true do |t|
     t.string   "name"
@@ -205,15 +205,6 @@ ActiveRecord::Schema.define(:version => 20110511012647) do
     t.integer  "old_id"
   end

-  create_table "site_layouts", :force => true do |t|
-    t.string   "name"
-    t.text     "description"
-    t.text     "content"
-    t.integer  "site_id"
-    t.datetime "created_at"
-    t.datetime "updated_at"
-  end
-
   create_table "site_styles", :force => true do |t|
     t.text     "published"
     t.datetime "created_at"

git fetch로컬 저장소가 github에서 모든 새로운 정보를 얻도록 시도하십시오 . 새 브랜치에 대한 정보 만 취하고 실제 코드는 필요하지 않습니다. 그 후에는 git checkout잘 작동합니다.


새 지점을 확인하려고 할 때이 오류가 발생했습니다.

오류 : pathspec 'BRANCH-NAME'이 git에 알려진 파일과 일치하지 않습니다.

시도했을 때 git checkout origin/<BRANCH-NAME>HEAD가 분리되었습니다.

(원산지에서 분리됨 /)

마지막으로 문제를 해결하기 위해 다음을 수행했습니다 .

git remote update
git fetch 
git checkout --track origin/<BRANCH-NAME>

원격 지점에 로컬 추적 지점이없는 지점에 대해이 오류가 발생했습니다. 간단한 방법을 통해 원격 지점을 확인했지만

git checkout feature/foo

과거에는이 오류를 해결하기 위해

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

나도 그 상황에 빠지기 위해 내가 뭘 했는지도 모르겠다.


리포지토리를 사용하여 브랜치를 삭제하고 git branch -D yourbranchname다시 풀 / 복제 한 경우 로컬 브랜치를 다시 만들어야 할 수 있습니다.

시험:

git checkout -b yourbranchname

동일한 질문이 있으며이 링크에서 몇 가지 정보를 얻었습니다. git fetch는 모든 분기를 가져 오지 않습니다.

이제 어떻게 이런 상황이 발생했는지 확신 할 수 없습니다. 최소한 해결할 수 있습니다.

1 단계. "remote.origin.fetch"설정이 다음과 같아야합니다.

$ git config --get remote.origin.fetch

+ refs / heads / private_dev_branch : refs / remotes / origin / private_dev_branch

2 단계. "remote.origin.fetch"를 변경하여 모든 것을 가져옵니다.

$ git config remote.origin.fetch "+ refs / heads / * : refs / remotes / origin / *"

$ git config --get remote.origin.fetch

+ refs / heads / * : refs / remotes / origin / *

그런 다음 "git pull"( "git fetch origin"도 작동하지만 시도하지 않았 음)을 시도하여 모든 분기를 가져올 수 있습니다.


Git Windows 사용자는 --icase-pathspecs또는 GIT_ICASE_PATHSPECS = 1 env var 설정 없이 git 경로 사양이 대소 문자를 구분한다는 점에 유의하세요.

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

다음과 같지 않다

git checkout origin/FooBranch "some/path/to/file.Txt"

브랜치 이름이고 커밋되지 않은 파일이 없다면 이것을 시도하십시오

git fetch && git checkout <branch name>

git pull

그것은 단순히 나를 위해 그것을 고쳤습니다 :)


다음을 수행했을 때 이것을 얻었습니다.

  • git에 연결된 IntelliJ IDE 사용
  • 새 파일을 만들고 git에 추가했습니다.
  • 새 파일의 이름이 변경되었습니다.

디렉토리를 확인하려고 할 때이 오류가 발생했습니다.

고치다:

git 확장에서 저장소를 열었습니다. 파일 (이전 이름)이 준비된 것을 보았습니다. 그러나 더 이상 존재하지 않았기 때문에 커밋 할 수 없었습니다.

이 파일을 간단히 언 스테이징했습니다.

그런 다음 파일 (이번에는 올바른 이름)을 git에 다시 추가하고 오류없이 커밋했습니다.


내가 사용하기 때문에이 같은 문제를 가지고 git clone --depth=1의미하는 --single-branch.

완료 git clone하면 문제가 해결됩니다.


내가하려고했던 오늘이 문제를 가지고 git checkout foo얻은error: pathspec 'foo' did not match any file(s) known to git.

내가 잘못된 저장소에있는 것으로 밝혀졌습니다 . 그래서 교훈을 얻었습니다. 놀라기 전에 어떤 저장소를보고 있는지 확인하십시오.


Windows OS에서는 기본적으로 git이 설치됩니다.

core.ignorecase = true

즉, git repo 파일은 대소 문자를 구분하지 않으므로이를 변경하려면 다음을 실행해야합니다.

\yourLocalRepo> git config core.ignorecase false

이 구성은 .git \ config 파일 에서 찾을 수 있습니다.


먼저 상위 브랜치를 체크 아웃 한 다음

git fetch --all --prune 
git checkout <your branch>

도움이 되었기를 바랍니다!.


I copied remote origin url from another .git/config file, doing so my new .git/config file was missing following line in [remote "origin"] section

fetch = +refs/heads/*:refs/remotes/origin/*

Adding above line fixed error: pathspec 'master' did not match any file(s) known to git.


I had the same issue.. I thought I had branch named foo when I try to:

git checkout foo

I was getting:

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

Then I tried the full branch name:

git checkout feature/foo

then worked for me.


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.


In my case I have TWO branch 1) master(which is for live server) 2) dev(test server). I had set multiple remote to push code on respective server. When I tried to switch branch I got the error like error: pathspec 'master' did not match any file(s) known to git.

You can see them by git remote -v. I had removed other remote except origin remote by git remote remove <remote-name>

Then git fetch

Now I am able to checkout branch by git checkout <branch-name>.


I had made a silly mistake of not providing -m flag while committing (lol happens)

git commit -m "commit message in here"

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


In my case I had renamed a file changing the case of the file, i.e. SomeFile.js -> someFile.js

I think that was related to the problem. Doing a git fetch didn't fix the issue.

I moved the files out of my project, did a fetch, and did a push without them. Then I did a fetch, added them back, and did a push, and it worked. I don't know if all those steps were needed, but it did ultimately work.


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.


in my case I enter submodule directory without doing

  • git submodule init
  • git submodule update

So git was linked to the parent folder that indeed missed that branch.


I encountered this same issue when I was first playing around with git. When attempting my first commit...

git commit -m 'first commit!'

I got the error mentioned by the OP...

error: pathspec 'commit!'' did not match any file(s) known to git.

I thought I might have been confusing git by using a keyword in the commit message, so I tried a few other words and received the same error.

Finally I used double-quotes in the message...

git commit -m "first commit!"

This turned out to be successful...

[master (root commit) 0000000] first commit!
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 dummyDoc.txt

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.


I had a different root cause

I had a script that basically searches all branches matching jira issue key in the for "PRJ-1234" among all branches to execute a git branch checkout command on the matching branch

The problem in my case was 2 or more branches shared the same jira key and hence caused my script to fail with the aforementioned error

By deleting the old unused branch and making sure only a single branch had the jira key reference fixed the problem

Here's my code in case someone wants to use it

git remote update
git fetch --all --prune 
git branch -r --list *$1* | xargs git checkout --force

save this as switchbranch.sh

Then use it from the terminal ./switchbranch.sh PRJ-1234


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>


For me, it was a problem with my credentials


After trying some of the answer, one of them helped me to solve the problem:

Running git fetch threw the following error:

Could not resolve host: bitbucket.org

All I had to do was force my IDE (VS Code in my case) to remember my credentials:

git config --global credential.helper wincred

Git immediately synched all the changes, and git checkout <branche> works fine now!


I was getting the same pathspec error on git-bash. I used Tortoise git on windows to switch/checkout the branch.


This can be caused when upstream rewrites history.

When this happens, I toss all affected repos, clone them fresh from upstream, and use 'git format-patch' / 'git am' to ferry any work in progress from old world to new.


I faced a similar issue. What led me into this trouble was: I had multiple remote branches and I deleted the folder that had the code. I did a get pull. :

git pull git@git.corp......

Then I added remote repository :

git remote add upstream git@git.corp.......

Then I tried to change branch to some other branch say AAAA and I got error

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

After spending an hour I found a solution. I deleted the source folder again. Then I did a git pull :

git pull git@git.corp......

Then I changed branch before linking it to remote repository :

git checkout AAA

then I added it to remote repository

git remote add upstream git@git.corp......

After this I can easily switch branches. Although this is not a standard way but it worked for me after I tried all of above options.

참고URL : https://stackoverflow.com/questions/5989592/git-cannot-checkout-branch-error-pathspec-did-not-match-any-files-kn

반응형