Troubleshooting
git에 모든 코드 다 올려 버렸을 때...
바우푸터
2023. 11. 1. 09:41
Git push 잘못해서 필요없는 코드 다 올라갔을 때.
- Git repository를 초기화
- 로컬 저장소인 .git를 삭제한다. (.git이 있는 경로에서 rmdir /s .git)
- git init 입력해 로컬 저장소 초기화.
Initialized empty Git repository in C:/Users/back_/.vscode/test/python/.git/
- 초기화 된 로컬 저장소에 git add (필요한 파일) 입력 or source control의 change의 하위 목록에서 + 체크 후 초기화에 등록 될 파일 커밋.
-
- warning: in the working copy of 'df', LF will be replaced by CRLF the next time Git touches it
- 유닉스 시스템에서는 한 줄의 끝이 LF(Line Feed)로 이뤄짐.
- 윈도우에서는 줄 하나가 CR(Carriage Return)와 LF(Line Feed), 즉 CRLF로 이뤄짐.
- Git이 이 둘 중 어느 쪽을 선택할지 혼란이 온 것. (왜? 맥과 윈도우 사용자의 충돌?)
- Git 의 core.autocrlf 라는 기능 켜서 자동 변환.
- Git config --global core.autocrlf true - 시스템 전체에 적용.
- Git config core.autocrlf true
- warning: in the working copy of 'df', LF will be replaced by CRLF the next time Git touches it
- Git commit -m 'commit message' 입력했는데.
-
- error: pathspec 'message'' did not match any file(s) known to git
- 로컬 저장소의 git과 리모트 저장소의 git 정보가 동기화 되지 않아서, 새로 만들어진 리모트 저장소 브랜치를 참조할 수 없기에 발생하는 에러다.
- Git remote update 입력.
- 모든 원격 브랜치를 업데이트하여 최신 상태로 갱신한다. 하지만 로컬 저장소에서 변동사항을 병합(merge)하지 않는다.)
- git checkout 브랜치명, 입력으로 원격 브랜치를 업데이트해 보자.
- Git checkout main 입력해도 같은 오류 나와서 git fetch 했는데도 같은 오류.
- Git commit -m '' 여기 따옴표를 큰 따옴표를 바꾸니 됨…
- error: pathspec 'message'' did not match any file(s) known to git
-
- 초기화 시킬 원격 저장소에 연결. git remote add origin https://github.com/ShoothingsTeam/kiosk.git
- git remote -v 로 확인.
- 현재 상태를 원격 저장소에 저장하는 git push --force --set-upstream origin main 입력.
- error: src refspec main does not match any 오류 나옴. -> 로컬 브랜치인 'main'에 대한 이력이 없거나 빈 브랜치일 때 발생.
- git checkout -b main 을 입력해 main 브랜치로 전환 or 생성했다.
- error: src refspec main does not match any 오류 나옴. -> 로컬 브랜치인 'main'에 대한 이력이 없거나 빈 브랜치일 때 발생.
vscode에서 + 버튼으로 add 하는 것과 명령어로 git add 하는 것이 동일한 과정!
반응형