항해99 TIL 23일차_053122

열공이·2022년 5월 31일
0

Git Terminal 에러남.

알고리즘 주차가 시작되면서 전과는 다르게 (미니프로젝트 때는 이런 일이 없었다) 매번 git pull origin main하면 에러가 났다.

이 사진에서처럼 아주 시작부터 다른 파일들을 합치려니까 그랬다.

에러가 난 상황이다

hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.

그래서 다른 애들을 합치려고 merge시켜주려고 했는데 그것도 안 됬다. 밑에 진한 글씨로 된 에러가 났다.
git fetch origin
git merge origin/main
fatal: refusing to merge unrelated histories

-Xours라는 방법이 있다해서 해봤는데 안 됬다. ours랑 theirs랑 잘 헷갈릴 수 있는데 이 사이트가 도움이 많이 되었다.
https://nitaym.github.io/ourstheirs/

git fetch origin
git merge -Xours origin/main
fatal: refusing to merge unrelated histories

그래서 hint: git config pull.rebase false # merge 방법을 써봤다. 이렇게 하고 바로 다음에 git pull origin main해봤는데, 긴 hint에러 메시지 대신 짧은 에러 메시지가 떴다.

From https://github.com/nowlcode/hanghae-algorithm-7E

  • branch main -> FETCH_HEAD
    fatal: refusing to merge unrelated histories

그래서 merge unrelated histories부분을 고치자고 생각했고, 이 사이트에서 (https://www.educative.io/edpresso/the-fatal-refusing-to-merge-unrelated-histories-git-error!) --allow-unrelated-histories라는 코드가 있어서 사용해보기로 했다.

git pull origin main --allow-unrelated-histories

이걸 쓰니 되긴 했는데 중간과정이 헷갈렸다.

위에 git pull origin main --allow-unrelated-histories을 ENTER하면 밑 사진처럼 나오는데 (내 사진이 아니다. 나도 이거랑 비슷하게 나왔는데 스크린 캡쳐를 못 했다. 그래서 구글에서 가져다 쎴다.)

https://velog.io/@ssmin0606/개발툴-Please-enter-a-commit-message-to-explain-why-this-merge-is-necessary-especially-if-it-merges-an-updated-upstream-into-a-topic-branch-해결하기-git-bash

다행이도 이 사이트에서 해결책을 찾았고, 근데 내 경우에는 i가 아무것도 안 해줬다. 그냥 i 아무리 눌러도 안 되길래 CTRL+C 했는데 밑에 무슨 record한다고 떠서 커밋 메시지 쓰고 ESC누르고 :wq 쓰고 ENTER해서 잘 끝났다.

결과적으로 이렇게 되었다.
git pull origin main --allow-unrelated-histories
From https://github.com/nowlcode/hanghae-algorithm-7E

  • branch main -> FETCH_HEAD
    Merge made by the 'ort' strategy.
    README.md | 1 +
    1 file changed, 1 insertion(+)
    create mode 100644 README.md

잘 처리가 되어 git push origin <branch이름>써서 메인 브랜치가 아닌 다른 브랜치에 현재 파일들 다 올리고 github에 갔는데 "There isn’t anything to compare.main and master are entirely different commit histories." 에러 메시지가 뜨는 일 없이 Pull Request를 누르니 잘 작동 되었다.

다음 번에 비슷한 일이 있으면 이렇게 써야겠다.

추가!

GitHub 디렉토리 화살표 표시 -> 폴더 접근 불가능

https://zzang9ha.tistory.com/346

폴더를 볼 수가 없어 이 사이트 내용대로 그 특정 폴더에 가서 cd ~/foldername/ rm -rf .git을 해줬다. 그런데 궁금했던 건 ls -al을 했을 때 .idea는 있어도 .git파일은 볼 수가 없었다. 그래도 어딘가 숨어있을지도 모르니 rm -rf .git을 써줬다.

다 지우고 나서 git add . 하고, git commit -m "remove .git files"를 해주었다. 그리고 git push origin <branch이름>에 먼저 보내주고 github에서 main브랜치와 현재 파일들 올려둔 브랜치를 Pull Request를 시도해 merge 시켰다.

Pull Request탭에 들어가면 보통은 PR할 내용들이 뜨는데 (open pull request로 나온다) 그게 없어도 New Pull Request버튼 눌러서 base는 main, compare는 현재 브랜치 이름으로 골라주고 PR 진행시켜주면 된다.

만약 이렇게 했는데도 PR merge시켜주는 부분이 안 나오면 There isn’t anything to compare. 에러가 났다고 생각해볼 수 있다.

다른 공부한 것들

최단 거리: 다익스트라

one-directional인 node들과 길이가 있는 간선 그래프

A에서 D까지 갈 때 가장 짧은 거리를 구하는 자료구조이다.

profile
프로그래머가 되자! 열공!

0개의 댓글