원격을 특정 커밋으로 재설정
커밋 후 모든 변경 사항을 취소하고 싶습니다 <commit-hash>
. 그래서 나는 :
git reset --hard <commit-hash>
이제 리모컨으로도 똑같이하고 싶습니다. 어떻게 할 수 있습니까? 이후에 몇 가지 커밋 (및 푸시)을 수행 <commit-hash>
했으며 모두 삭제하고 싶습니다. 그저 뭔가 끔찍하게 잘못 됐고 이미 상황을 악화시키고 싶지 않습니다. ; (
기본적으로 되 감고 싶습니다 origin/master
.<commit-hash>
지점이 master
여기와 원격으로 모두 호출 되고 리모컨이 호출 되었다고 가정하면 origin
다음을 수행 할 수 있습니다.
git reset --hard <commit-hash>
git push -f origin master
그러나 다른 사람이 원격 저장소로 작업하고 변경 사항을 가져온 경우에는이 작업을 피해야합니다. 이 경우 원하지 않는 커밋 을 되 돌린 다음 정상적으로 푸시하는 것이 좋습니다 .
업데이트 : 푸시 한 변경 사항을 다른 사람들이 가져 왔다고 아래에서 설명 했으므로 모든 변경 사항을 되 돌리는 새 커밋을 만드는 것이 좋습니다 . Jakub Narębski의이 답변 에는 이 작업을 수행하는 옵션에 대한 좋은 설명이 있습니다 . 가장 편리한 것은 되돌리려는 커밋 수와 가장 적합한 방법에 따라 다릅니다.
귀하의 질문에서 이미 브랜치 git reset --hard
를 재설정 하는 데 사용 했음이 분명하므로을 사용 하여 master
브랜치 git reset --hard ORIG_HEAD
를 이전 위치로 다시 이동 해야 할 수도 있습니다 . (언제나와 git reset --hard
, 있는지 확인하십시오 git status
당신이 바로 그 지점에 걸 깨끗하고 당신의있는 거 알고 git reflog
도구는 분명히 손실 커밋을 복구하는 것처럼.) 당신은 또한 확인해야 ORIG_HEAD
와 오른쪽 커밋에 포인트를 git show ORIG_HEAD
.
문제 해결:
" ! [원격 거부 됨] a60f7d85-> 마스터 (사전 수신 후크 거부 됨) " 와 같은 메시지가 표시되는 경우
그런 다음 특정 분기에 대한 분기 기록 다시 쓰기를 허용해야합니다. 예를 들어 BitBucket에서는 "지점 기록 다시 쓰기가 허용되지 않습니다"라고 말했습니다. 라는 체크 박스가 Allow rewriting branch history
당신이 확인해야합니다.
로컬 변경 사항을 잃어도 괜찮다면 다른 답변을 사용하십시오. 이 방법은 잘못된 커밋 해시를 선택하면 여전히 리모컨을 망칠 수 있습니다.
로컬 브랜치에 이미있는 커밋과 원격 매치를 만들고 싶다면 :
- 마십시오 하지 어떤 재설정을한다.
git log
리모컨이 위치 할 커밋의 해시를 찾는 데 사용 합니다.git log -p
변경 사항을 보거나git log --graph --all --oneline --decorate
간결한 트리를 볼 수 있습니다. (마지막 이름을 셸의 별칭으로 사용하면 매우 편리합니다.)- 해시를 복사하십시오.
다음과 같은 명령을 실행하십시오.
git push --force <remote> <the-hash>:<the remote branch>
예 :
git push --force origin 606fdfaa33af1844c86f4267a136d4666e576cdc:master
이 명령으로 당신과 같은 문제를 해결했습니다.
git reset --hard <commit-hash>
git push -f <remote> <local branch>:<remote branch>
GitLab에서는 이를 수행하기 전에 분기를 보호되지 않음으로 설정해야 할 수 있습니다 . [repo]> 설정> 저장소> 보호 된 분기에서이 작업을 수행 할 수 있습니다. 그러면 Mark의 답변 방법이 작동합니다.
git reset --hard <commit-hash>
git push -f origin master
이전 답변에 대한 나의 2 센트 : 만약
git push --force <remote> <the-hash>:<the remote branch>
여전히 작동하지 않는 경우 <your-remote-repo>.git/config
파일의 수신 섹션 을 편집 할 수 있습니다 .
[receive]
#denyNonFastforwards = true
denyNonFastforwards = false
이전 버전의 파일을 원하면 git checkout을 사용하는 것이 좋습니다.
git checkout <commit-hash>
이렇게하면 시간을 거슬러 올라가고 프로젝트의 현재 상태에 영향을주지 않습니다. 메인 라인 git checkout mainline으로 올 수 있습니다.
그러나 인수에 파일을 추가하면 해당 파일은 이전 시간에서 현재 프로젝트 시간으로 다시 가져옵니다. 즉, 현재 프로젝트가 변경되어 커밋되어야합니다.
git checkout <commit-hash> -- file_name
git add .
git commit -m 'file brought from previous time'
git push
The advantage of this is that it does not delete history, and neither does revert a particular code changes (git revert)
Check more here https://www.atlassian.com/git/tutorials/undoing-changes#git-checkout
If your branch is not development or production, the easiest way to achieve this is resetting to a certain commit locally and create a new branch from there. You can use:
git checkout 000000
(where 000000 is the commit id where you want to go) in your problematic branch and then simply create a new branch:
git remote add [name_of_your_remote]
Then you can create a new PR and all will work fine!
Do one thing, get the commit's SHA no. such as 87c9808 and then,
- move yourself ,that is your head to the specified commit (by doing git reset --hard 89cef43//mention your number here )
- Next do some changes in a random file , so that the git will ask you to commit that locally and then remotely Thus, what you need to do now is. after applying change git commit -a -m "trial commit"
- Now push the following commit (if this has been committed locally) by git push origin master
- Now what git will ask from you is that
error: failed to push some refs to 'https://github.com/YOURREPOSITORY/AndroidExperiments.git' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Integrate the remote changes (e.g. hint: 'git pull ...') before pushing again.**
- Thus now what you can do is
git push --force origin master
- And thus, i hope it works :)
Learn section: Undo Public Commits with Revert on Atlasssian Blog https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting
참고URL : https://stackoverflow.com/questions/5816688/resetting-remote-to-a-certain-commit
'Nice programing' 카테고리의 다른 글
Git에서 마스터에서 브랜치로 변경 사항 가져 오기 (0) | 2020.10.02 |
---|---|
디렉토리의 모든 파일과 폴더를 삭제하는 방법은 무엇입니까? (0) | 2020.10.02 |
한 분기에서 다른 분기로 커밋을 복사하는 방법은 무엇입니까? (0) | 2020.09.30 |
속성 값으로 객체 배열에서 JavaScript 객체 가져 오기 [duplicate] (0) | 2020.09.30 |
파이썬에서 파일 크기를 확인하는 방법은 무엇입니까? (0) | 2020.09.30 |