힘내 : "현재 지점에 없습니다." 변경 사항을 유지하면서 지점으로 돌아갈 수있는 쉬운 방법이 있습니까?
그래서 저장소에서 약간의 작업을 수행했으며 커밋하려고 할 때 현재 어느 지점에도 있지 않다는 것을 알고 있습니다.
이것은 서브 모듈로 작업 할 때 많이 발생하며 해결할 수는 있지만 프로세스가 번거롭고 더 쉬운 방법이 있어야한다고 생각했습니다.
변경 사항을 유지하면서 지점으로 돌아갈 수있는 쉬운 방법이 있습니까?
커밋하지 않은 경우 :
git stash
git checkout some-branch
git stash pop
다음 이후에 커밋하고 변경하지 않은 경우 :
git log --oneline -n1 # this will give you the SHA
git checkout some-branch
git merge ${commit-sha}
추가 작업을 수행 한 후 수행 한 경우 :
git stash
git log --oneline -n1 # this will give you the SHA
git checkout some-branch
git merge ${commit-sha}
git stash pop
이것은 나를 도왔다
git checkout -b newbranch
git checkout master
git merge newbranch
git branch -d newbranch
git checkout master
결과는 다음과 같습니다.
Warning: you are leaving 2 commits behind, not connected to
any of your branches:
1e7822f readme
0116b5b returned to clean django
If you want to keep them by creating a new branch, this may be a good time to do so with:
git branch new_branch_name 1e7822f25e376d6a1182bb86a0adf3a774920e1e
이제 해봅시다 :
git merge 1e7822f25e376d6a1182bb86a0adf3a774920e1e
여기 다른 길을 떠나
git branch newbranch
git checkout master
git merge newbranch
또는 기본적으로 분리 된 헤드 상태가 아닌 분기를 체크 아웃하도록 서브 모듈을 설정할 수 있습니다.
추가하기 위해 편집 :
한 가지 방법은 -b 플래그와 함께 서브 모듈을 추가 할 때 서브 모듈의 특정 분기를 체크 아웃하는 것입니다.
git submodule add -b master <remote-repo> <path-to-add-it-to>
또 다른 방법은 하위 모듈 디렉토리로 가서 체크 아웃하는 것입니다.
git checkout master
최근 에이 문제가 다시 발생했습니다. 마지막으로 서브 모듈을 다루고 git에 대해 더 많이 알게 된 지 오래되었습니다. 커밋하려는 브랜치를 체크 아웃하는 것으로 충분하다는 것을 깨달았습니다. Git은 작업 트리를 숨기지 않아도 유지합니다.
git checkout existing_branch_name
새로운 지점에서 일하고 싶다면 다음과 같이하십시오.
git checkout -b new_branch_name
작업 트리에서 충돌이 발생하면 체크 아웃이 실패하지만 매우 드문 일이며 발생하면 숨기고 팝업하여 충돌을 해결할 수 있습니다.
허용 된 답변과 비교 하여이 답변은 어쨌든 실행하는 데 오래 걸리지 않는 두 명령의 실행을 절약합니다. 그러므로 나는 현재 받아 들여진 답보다 기적적으로 더 많은 찬사를 받거나 (또는 적어도 가까운)이 대답을 받아들이지 않을 것이다.
다음 방법이 효과적 일 수 있습니다.
git rebase HEAD master
git checkout master
이렇게하면 현재 HEAD 변경 사항이 마스터 위에 리베이스됩니다. 그런 다음 지점을 전환 할 수 있습니다.
다른 방법은 지점을 먼저 체크 아웃하는 것입니다.
git checkout master
그런 다음 Git은 분리 된 커밋의 SHA1을 표시해야합니다. 예를 들어 체리를 선택할 수 있습니다.
git cherry-pick YOURSHA1
또는 최신 것을 병합 할 수도 있습니다.
git merge YOURSHA1
서로 다른 브랜치에서 커밋을 모두 보려면 (이를 확인하십시오) git reflog
.
I know I told babay in 2012 that I thought it was unlikely that someone wouldn't realize that they weren't on a branch and commit. This just happened to me, so I guess I have to admit that I was wrong, but considering that it took until 2016 for this to happen to me, you could argue that it is in fact unlikely.
Anyway, creating a new branch is overkill in my opinion. All you have to do is:
git checkout some-branch
git merge commit-sha
If you didn't copy the commit-sha before checking out the other branch, you can easily find it by running:
git reflog
One way to end up in this situation is after doing a rebase from a remote branch. In this case, the new commits are pointed to by HEAD
but master
does not point to them -- it's pointing to wherever it was before you rebased the other branch.
You can make this commit your new master
by doing:
git branch -f master HEAD
git checkout master
This forcibly updates master
to point to HEAD
(without putting you on master
) then switches to master
.
'Programing' 카테고리의 다른 글
DOS의 재귀 디렉토리 목록 (0) | 2020.05.14 |
---|---|
가장 큰 GWT 함정? (0) | 2020.05.14 |
Windows 용 최고의 경량 웹 서버 (정적 컨텐츠 만) (0) | 2020.05.14 |
문자열이 양의 정수인지 확인 (0) | 2020.05.14 |
.jar 파일의 내용보기 (0) | 2020.05.14 |