파일 체크 아웃없이 git 분기 전환
git에서 모든 파일을 체크 아웃하지 않고 다른 브랜치로 전환 할 수 있습니까? 브랜치를 전환 한 후 모든 파일을 삭제하고 재생성하고 커밋하고 다시 전환해야합니다. 따라서 파일 체크 아웃은 시간 낭비 일뿐입니다 (약 14000 개의 파일이 있으며 긴 작업입니다).
모든 것을 명확하게하려면 :
문서 를 github 에 업로드하려면이 모든 것이 필요합니다 .
gh-pages 지점에 repo가 있습니다. 문서를 로컬로 다시 빌드 할 때 repo 디렉터리에 복사하고 커밋하고 github에 푸시합니다. 하지만 로컬에 두 개의 문서 사본이있어서 행복하지 않았습니다. 그리고 나는 빈 가지를 만들고 파일을 비우고 삭제하기로 전환 한 후 만들기로 결정했습니다. 그러나 다시 전환하는 것은 긴 작업이므로이 질문을했습니다.
gh-pages 브랜치에 남겨두고 파일을 삭제할 수 있다는 것을 알고 있지만 더러운 작업 트리를 좋아하지 않습니다.)
예, 할 수 있습니다.
git symbolic-ref HEAD refs/heads/otherbranch
이 브랜치에서 커밋해야하는 경우 인덱스도 재설정해야합니다. 그렇지 않으면 마지막으로 체크 아웃 한 브랜치를 기반으로 무언가를 커밋하게됩니다.
git reset
기본 git 명령 만 사용 :
이 답변은 Charles의 답변보다 약간 길지만, 제가 이해할 수 있고 기억할 수있는 기본적인 git 명령으로 만 구성되어 있으므로 계속 검색 할 필요가 없습니다.
현재 위치를 표시 (필요한 경우 먼저 커밋) :
git checkout -b temp
작업 디렉토리를 변경하지 않고 마커를 다른 분기로 재설정 (이동)합니다.
git reset <branch where you want to go>
이제 임시 및 기타 분기가 동일한 커밋을 가리키고 작업 디렉토리는 변경되지 않습니다.
git checkout <branch where you want to go>
HEAD가 이미 동일한 커밋을 가리키고 있으므로 작업 디렉토리가 건드리지 않습니다.
git branch -d temp
이러한 명령은 모든 그래픽 클라이언트에서도 쉽게 사용할 수 있습니다.
두 개의 작업 디렉토리 (두 개의 작업 영역)와 하나의 저장소 또는 두 개의 저장소를 갖는 것이 더 나은 솔루션이 아닐까요?
이 자식 새로운-WORKDIR의 에서 도구 contrib/
이 당신을 도울 수있는 부분은.
독자의 이익을 위해 :
Charles Bailey의 솔루션 이 옳다고 생각하지만 이 솔루션은 로컬 브랜치가 아닌 것으로 전환 할 때 조정이 필요합니다. 또한 이해하기 쉬운 일반 명령으로 수행하는 방법이 있어야합니다. 내가 생각해 낸 것은 다음과 같습니다.
git checkout --detach
git reset --soft commitish
git checkout commitish
설명 :
git checkout --detach
git checkout HEAD^{}
현재 분기를 뒤로하고 "분리 된 헤드 상태" 가되는 것과 동일 합니다. 따라서 다음 수정은HEAD
더 이상 분기에 영향 을 주지 않습니다. 분리HEAD
는 작업 트리 나 색인에 영향을주지 않습니다.git reset --soft commitish
그런 다음HEAD
주어진의 SHA 로 이동 합니다commitish
. 색인도 업데이트하려면 그대로 두십시오--soft
. 그러나 그렇게하지 않는 것이 좋습니다. 이것은 다시 작업 트리를 건드리지--soft
않고 ( ) 인덱스를 건드리지 않습니다.git checkout commitish
그런 다음HEAD
주어진commitish
(분기)에 다시 연결 합니다. (commitish
SHA 라면 아무 일도 일어나지 않습니다.) 이것 역시 인덱스 나 워크 트리에 영향을주지 않습니다.
This solution accepts everything which refers to a commit, so this is ideal for some git
alias. The rev-parse
below is just a test to make sure, nothing breaks in the chain, such that typos do not accidentally switch into detached head state (error recovery would be way more complex).
This leads to following git switch treeish
alias:
git config --global alias.switch '!f() { git rev-parse --verify "$*" && git checkout "HEAD^{}" && git reset --soft "$*" && git checkout "$*"; }; f'
FYI, you can find it in my list of git
aliases.
I think you're looking for the plumbing command git read-tree
. This will update the index but will not update any files in your working directory. For example, assuming branch
is the name of the branch to read:
git read-tree branch
If you want to then commit to the branch you just read, you will also need to:
git symbolic-ref HEAD refs/heads/branch
You can overwrite your HEAD file with a different branch name:
echo "ref: refs/heads/MyOtherBranch" > .git/HEAD
With so many files, you may be best off just keeping two repos, one for each branch. You can pull changes back and forth as needed. This is going to be less surprising than trying to play scurvy tricks with git.
If you are simply trying to change where a remote branch points, you can do it with "git push" without touching your local copy.
http://kernel.org/pub/software/scm/git/docs/git-push.html
The format of a <refspec> parameter is an optional plus +, followed by the source ref <src>, followed by a colon :, followed by the destination ref <dst>. It is used to specify with what <src> object the <dst> ref in the remote repository is to be updated.
eg, to update foo to commit c5f7eba do the following:
git push origin c5f7eba:foo
Not sure if that's what you were after or not.
you can make use of
1. git checkout -f <new-branch>
2. git cherry-pick -x <previous-branch-commit-id>
previous-branch-commit-id is the commit from where you want to copy old the data.
참고URL : https://stackoverflow.com/questions/1282639/switch-git-branch-without-files-checkout
'Programing' 카테고리의 다른 글
GitHub에서 단일 commit-diff를 다운로드하는 방법은 무엇입니까? (0) | 2020.09.14 |
---|---|
각도 표현식 {{::}} 안의 두 콜론은 무엇을 의미합니까? (0) | 2020.09.14 |
Git의 서버 저장소에서 단일 파일을 가져 오는 방법은 무엇입니까? (0) | 2020.09.14 |
x86-64 시스템에 48 비트 가상 주소 공간 만있는 이유는 무엇입니까? (0) | 2020.09.14 |
여러 열에서 중복 항목을 찾으려면 어떻게합니까? (0) | 2020.09.14 |