programing

로컬 변경을 무시한 채 git pull을 하려면 어떻게 해야 합니까?

css3 2023. 4. 10. 22:09

로컬 변경을 무시한 채 git pull을 하려면 어떻게 해야 합니까?

어떻게 할 수 있을까요?git pull로컬 파일 변경을 무시합니다.디렉토리를 삭제하거나git clone?

풀로 로컬 변경을 덮어쓰려면 작업 트리가 깨끗한 것처럼 병합을 수행하고 작업 트리를 청소합니다.

git reset --hard
git pull

추적되지 않은 로컬 파일이 있는 경우git clean제거할 수 있습니다.

  • git clean -f추적되지 않은 파일을 삭제하다
  • -df추적되지 않은 파일 및 디렉터리를 제거하다
  • -xdf추적되지 않거나 무시된 파일 또는 디렉터리를 제거하다

한편 로컬 수정 내용을 유지하려면 저장 공간을 사용하여 꺼내기 전에 숨긴 다음 나중에 다시 적용합니다.

git stash
git pull
git stash pop

풀의 절반은 Marge이며 콘텐츠의 커밋된 버전과 가져온 버전을 Marge해야 하지만 문자 그대로 변경을 무시하는 것은 의미가 없다고 생각합니다.

저는 다음과 같은 작업을 수행했습니다.

(1) 먼저 모든 변경 내용을 가져옵니다.

$ git fetch --all

(2) 다음으로 마스터를 리셋합니다.

$ git reset --hard origin/master

참고 - 2020년 10월 github 사용자의 경우 "master"를 "main"으로 대체하였습니다.그 이후에 작성된 프로젝트의 경우 다음과 같은 "메인"을 대신 사용해야 할 수 있습니다.

$ git reset --hard origin/main

(3) 풀/업데이트:

$ git pull

명령어를 사용하면 다음과 같은 결과를 얻을 수 있습니다.rm -rf local_repo && git clone remote_url,그렇죠?저도 이 기능을 원합니다.git은 왜 그런 명령어를 제공하지 않는지 궁금합니다(예:git reclone또는git syncsvn도 이러한 명령어를 제공하지 않습니다(예:svn recheckout또는svn sync).

다음 명령을 사용해 보십시오.

git reset --hard origin/master
git clean -fxd
git pull

bellow 명령은 항상 작동하지 않습니다.다음과 같은 경우:

$ git checkout thebranch
Already on 'thebranch'
Your branch and 'origin/thebranch' have diverged,
and have 23 and 7 different commits each, respectively.

$ git reset --hard
HEAD is now at b05f611 Here the commit message bla, bla

$ git pull
Auto-merging thefile1.c
CONFLICT (content): Merge conflict in thefile1.c
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.

기타 등등...

다시 시작하려면 브랜치를 다운로드하고 모든 로컬 변경 사항을 덮어씁니다.


$ git checkout thebranch
$ git reset --hard origin/thebranch

이거면 잘 될 거야

$ git checkout thebranch
Already on 'thebranch'
Your branch and 'origin/thebranch' have diverged,
and have 23 and 7 different commits each, respectively.

$ git reset --hard origin/thebranch
HEAD is now at 7639058 Here commit message again...

$ git status
# On branch thebranch
nothing to commit (working directory clean)

$ git checkout thebranch
Already on 'thebranch'

가장 빠른 방법은 다음과 같습니다.

git pull --rebase --autostash

이것은 나에게 효과가 있었다.

git fetch --all
git reset --hard origin/master
git pull origin master

승인된 답변으로 충돌 오류가 발생함

git fetch --all && git reset --hard origin/master

나는 보통 다음을 한다.

git checkout .
git pull

프로젝트의 루트 폴더에 있습니다.

git stash를 보고 모든 로컬 변경을 "stash 파일"에 저장하고 마지막 커밋으로 되돌립니다.이 시점에서 저장된 변경 사항을 적용하거나 취소할 수 있습니다.

Linux 를 사용하고 있는 경우:

git fetch
for file in `git diff origin/master..HEAD --name-only`; do rm -f "$file"; done
git pull

for 루프는 로컬 repo에서 변경된 모든 추적 대상 파일을 삭제합니다.git pull문제없이 동작합니다.
여기서 가장 좋은 점은 추적된 파일만 repo 파일에 의해 덮어쓰게 되고 다른 모든 파일은 변경되지 않은 상태로 남게 된다는 것입니다.

늦은 감이 있지만 누군가가 이것을 유용하게 사용할 수 있다.(나를 위해 일함)

  1. git restore < fileName >또는 git restore를 선택합니다.
  2. git 당김

현재 분기를 가져오고 마스터로 빨리 감기를 시도합니다.

git fetch && git merge --ff-only origin/master

상에 하고 리모트브런치를.Your branch and 'origin/<branch_name>' have diverged브랜치에 머무르는 동안 다음과 같이 해결할 수 있습니다.

git fetch --all
git reset --hard origin/<branch_name>

무시하다

"원하지 않는 파일을 .gitignore에 추가하는 것은 처음에 브런치에 커밋하지 않은 한 유효합니다."

또한 다음을 실행할 수 있습니다.

git update-index --assume-unchanged filename

https://chamindac.blogspot.com/2017/07/ignoring-visual-studio-2017-created.html

또, 로컬 커밋으로부터의 변경을 보관해, 새로운 커밋으로서 푸시 할 수도 있습니다.저는 지역 커밋이 엉망일 때 이 단계를 사용합니다.

  1. git reset --소프트 오리진/메인
  2. 저장하다
  3. git pull --기본값 변경
  4. git stash pop

언급URL : https://stackoverflow.com/questions/4157189/how-to-git-pull-while-ignoring-local-changes