"치명적 :이 작업은 작업 트리에서 실행해야합니다."라는 메시지가 나타나는 이유는 무엇입니까?
방금 Windows에 git을 설치했습니다. GIT_DIR 변수를 c : \ git \로 설정하고이 환경 변수가 cygwin에 의해 유지되는지 확인했습니다 (즉, echo $ GIT_DIR이되어야합니다). git 저장소를 만들려는 폴더 (c : \ www)로 이동 한 다음 실행했습니다.
git init
git add .
그런 다음 오류가 발생합니다.
fatal: This operation must be run in a work tree
무엇이 잘못되었는지 확실하지 않지만 c : \ git 디렉토리에는 다음과 같은 구성 파일이 있습니다.
[core]
repositoryformatversion = 0
filemode = false
bare = true
symlinks = false
ignorecase = true
나는 이것이 드러나서는 안되며 그것이 우리의 문제라고 확신합니다.
오류의 직접적인 이유는 예, git-add
베어 리포지토리 에서 사용할 수 없기 때문 입니다. 정의상 베어 저장소에는 작업 트리가 없습니다. git-add
커밋을 준비하기 위해 작업 트리에서 파일을 가져와 색인에 추가합니다.
하지만 여기서 설정에 대해 약간의 생각을해야 할 수도 있습니다. GIT_DIR은 모든 git 명령에 사용되는 저장소 디렉토리입니다. 추적하는 모든 항목에 대해 단일 저장소를 만들려고하고 있습니까? 본질적으로 git 저장소는 단일 디렉토리의 내용을 추적합니다. GIT_WORK_TREE
추적하려는 모든 항목이 포함 된 경로 를 설정 해야하며 .gitignore
추적에 관심이없는 모든 항목을 차단 하려면이 필요합니다 .
어쩌면 당신은 단지 추적 할 저장소를 만들려고 시도하고 c:\www
있습니까? 그런 다음 넣어야합니다 c:\www
(GIT_DIR을 설정하지 마십시오). 이것은 "모듈"의 최상위 디렉토리의 .git 디렉토리에있는 저장소와 함께 git의 일반적인 사용법입니다.
정말 타당한 이유가 없다면 git이 일하는 것을 좋아하는 방식을 고수하는 것이 좋습니다. 추적 할 항목이 여러 개인 경우 여러 저장소를 원할 것입니다!
또한 .git 하위 폴더 안에있을 수 있으므로 한 폴더 위로 프로젝트 루트로 이동합니다.
나에게 일어난 일이 다른 사람에게 일어나고있는 경우를 대비하여 다음과 같이 말해야합니다.이 오류가 발생했을 때 프로젝트 내의 .git 디렉토리에있었습니다. 나는 답을 찾고 샅샅이 뒤졌지만 아무런 효과가 없었다. 내가해야 할 일은 올바른 디렉토리로 돌아가는 것뿐이었습니다. 제게는 일종의 얼굴 손바닥 순간이었습니다. 저만큼 어리석은 사람이 있다면이 답변이 도움이 되었기를 바랍니다.
그냥 복제 다른 폴더에 같은 프로젝트를하고 복사 .git / 프로젝트에 폴더를.
예
임시 폴더 만들기 :
mkdir temp
임시 폴더로 전환
cd temp/
임시 폴더 에서 동일한 프로젝트를 복제하십시오 .
git clone [-b branchName] git@path_to_your_git_repository
.git 폴더를 projet에 복사합니다.
cp -R .git/ path/to/your/project/
프로젝트로 전환하고 실행 git status
완료되면 임시 폴더를 삭제 하십시오 .
이것이 누군가를 도울 수 있기를 바랍니다.
GIT_DIR
환경 변수를 명시 적으로 설정하면 git은 지정된 디렉토리를 git 저장소로 사용합니다. 정상적인 사용 중에는 필요하지 않습니다.
귀하의 예에서 a를 지정하고 GIT_DIR
이름 이 지정 되지 않았고 .git
(선행 점이 중요합니다) --work-tree
옵션을 제공하지 않았 거나 GIT_WORK_TREE
환경 변수를 설정 하지 않았기 때문에 git init
.
베어 리포지토리에는 작동하는 트리가 없기 때문에 베어 리포지토리에서는 많은 명령을 선택하는 것이 의미가 없습니다. git add
하나입니다.
.git
작업 트리 루트 아래의 하위 폴더가 아닌 git 저장소에 비표준 위치를 사용해야하는 특별한 이유가 있습니까? 이를 조정하는 것이 가능하지만 작업이 더 많고 사용자 실수에 더 취약한 경향이 있습니다.
베어 GIT 저장소 만들기
작은 폭언 : git은 자체적으로 일반 베어 저장소를 만들 수 없습니다. 참으로 멍청한 자식.
정확히 말하면 빈 저장소는 복제 할 수 없습니다. 따라서 빈 저장소는 쓸모없는 저장소입니다. 실제로 일반적으로 빈 저장소를 만들고 즉시 채 웁니다.
git init
git add .
그러나 베어 저장소를 생성 할 때는 git add가 불가능합니다.
git --bare init
git add .
gives an error "fatal: This operation must be run in a work tree".
You can't check it out either:
Initialized empty Git repository in /home/user/myrepos/.git/
fatal: http://repository.example.org/projects/myrepos.git/info/refs not found: did you run git update-server-info on the server?
git --bare init
git update-server-info # this creates the info/refs file
chown -R <user>:<group> . # make sure others can update the repository
The solution is to create another repository elsewhere, add a file in that repository and, push it to the bare repository.
mkdir temp; cd temp
git init
touch .gitignore
git add .gitignore
git commit -m "Initial commit"
git push (url or path of bare repository) master
cd ..; rm -rf temp
hope this can help u
This should solve it:
git config --unset core.bare
In my case, I was in the same folder as ".git" file for my repo. I had to go one directory level up, it solved it.
I had this issue, because .git/config
contained worktree = D:/git-repositories/OldName
. I just changed it into worktree = D:/git-repositories/NewName
I discovered that, because I used git gui, which showed a more detailed error message:
If an existing (non-bare) checkout begins giving this error, check your .git/config file; if core.bare
is true, remove that config line
If none of the above usual ways help you, look at the call trace underneath this error message ("fatal: This operation . . ."
) and locate the script and line which is raising the actual error. Once you locate that error() call, disable it and see if the operation you are trying completes even with some warnings/messages - ignore them for now. If so, finally after completing it might mention the part of the operation that was not completed successfully. Now, address this part separately as applicable.
Relating above logic to my case, I was getting this error message "fatal: This operation . . ."
when I was trying to get the Android-x86 code with repo sync . . .
. and the call trace showed raise GitError("cannot initialize work tree")
as the error() call causing the above error message ("fatal: . . ."
). So, after commenting that GitError()
in .repo/repo/project.py
, repo sync . . .
continued and finally indicated error for three projects that were not properly synced. I just deleted their *.git
folders from their relevant paths in the Android-x86 source tree locally and ran repo sync . . .
again and tasted success!
Same issue i got, i did following steps,
- git init
- git add .
- git commit -m"inital setup"
- git push -f origin master
then it work starts working.
Edited the config file and changed bare = true to bare = false
If nothing else seems to work, double-check the path in git config core.worktree
. If that path doesn't point to your working directory, you may need to update it.
The way I got this error was that I created a Git repository on a network drive. It worked fine on one computer but returned this error on another. It turned out that I had the drive mapped to a Windows drive letter on the computer where I created it, but not on the other computer, and Git saved the path to the work tree as the mapped path and not the UNC path.
'Program Tip' 카테고리의 다른 글
Django는 특정 순서로 id 배열에서 QuerySet을 가져옵니다. (0) | 2020.11.12 |
---|---|
작업 표시 줄의 검색보기가 작동하지 않습니다. (0) | 2020.11.12 |
문자열에서 부분 문자열 추출 (0) | 2020.11.12 |
0.-5가 -5로 평가되는 이유는 무엇입니까? (0) | 2020.11.12 |
Rails : 데이터베이스에 요소가 없을 때 메시지를 표시하는 우아한 방법 (0) | 2020.11.12 |