Git 풀이 파일을 업데이트하지 않음

John Wachira 2023년1월30일
  1. 정보 누락으로 인해 git pull이 파일을 업데이트하지 않음
  2. 로컬 리포지토리의 커밋되지 않은 파일로 인해 git pull이 파일을 업데이트하지 않음
Git 풀이 파일을 업데이트하지 않음

이 기사에서는 git pull 명령이 원격 저장소의 파일로 로컬 저장소의 파일을 업데이트하지 못하는 이유에 대해 설명합니다.

git pull 기능은 여러 가지 이유로 오작동할 수 있습니다. 자주 발생하는 원인과 해결 방법에 대해 알아보겠습니다.

정보 누락으로 인해 git pull이 파일을 업데이트하지 않음

Git에 작업할 정보가 충분하지 않으면 아래와 같은 오류 메시지가 표시될 수 있습니다.

$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
    git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
    git branch --set-upstream-to=<remote>/<branch> master

이러한 메시지가 표시되면 Git은 현재 로컬 분기로 추적할 원격 분기를 지정하도록 요구합니다. git branch --set-upstream-to=<remote>/<branch> master 명령을 사용한 다음 git pull 명령을 실행하여 Git이 변경 사항을 가져올 위치를 가리키도록 합니다.

로컬 리포지토리의 커밋되지 않은 파일로 인해 git pull이 파일을 업데이트하지 않음

Git은 소스 코드 관리 시스템으로서 파일 및 데이터 손실을 방지하기 위해 최선을 다합니다. 이러한 이유로 Git은 git pull 명령을 수행할 때 로컬 파일을 원격 저장소의 파일과 병합하는 것을 거부할 수 있습니다.

Git에는 forced git pull 명령이 없으므로 시스템을 호출하여 변경 사항을 병합할 수 있습니다. 커밋되지 않은 변경 사항이 있는 경우 아래와 같은 오류 메시지가 나타날 수 있습니다.

$ git pull
From REPOSITORY_URL
 * branch            master     -> FETCH_HEAD
   a152b19..171e4a2  master     -> origin/master
Updating a152b19..171e4a2
error: Your local changes to the following files would be overwritten by merge:
  file1.txt
  file2.txt
Please commit your changes or stash them before you merge.
Aborting

이 문제를 해결하려면 git pull 명령을 실행하기 전에 git stash 명령을 실행하여 로컬 변경 사항을 숨깁니다.

마지막 단계는 git pull 명령 다음에 git stash apply를 실행하는 것입니다. 이 명령은 작업 디렉토리에 숨긴 변경 사항을 적용합니다.

$ git stash
Saved working directory and index state WIP on master: d91368b Previous commit message
$ git pull
From REPOSITORY_URL
 * branch            master     -> FETCH_HEAD
   a152b19..171e4a2  master     -> origin/master
Updating a152b19..171e4a2
Fast-forward
 file1.txt | 1 +
 file2.txt | 1 +
 2 files changed, 2 insertions(++)
$ git stash apply

git pull 명령을 실행하기 전에 변경 사항을 커밋할 수도 있습니다.

$ git commit -am 'Committing two files before git-pull'
[master d91368b] Committing two files before git-pull
 2 files changed, 2 insertions(++)
$ git pull
From REPOSITORY_URL
 * branch            master     -> FETCH_HEAD
   a152b19..171e4a2  master     -> origin/master
Updating a152b19..171e4a2
Fast-forward
 file1.txt | 1 +
 file2.txt | 1 +
 2 files changed, 2 insertions(++)

로컬 변경 사항이 필요하지 않은 경우 git pull 명령을 실행하기 전에 해당 변경 사항을 삭제할 수 있습니다.

git rest --hard 명령과 git clean -fd 명령을 사용하여 추적되지 않은 파일을 삭제할 수 있습니다. 삭제를 취소할 수 없으므로 이러한 변경 사항이 필요하지 않은지 확인하십시오.

작가: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn