2013-10-13 3 views
4

master 브랜치 - no changes to commit에 대한 작업을 시작한다고 가정 해 보겠습니다. 일부 로컬 변경 작업을 수행하지만이 수정 사항은 master 대신 branch으로 분리되어야 함을 알고 있습니다.새 분기를 만들고 거기에있는 기존 코드를 이동하는 방법

이동에이 branch 새로운 분리 상태 no changes to commitmaster 분기를 재 작성 변경 방법 방법이 있나요? 단계를 수행 할 때

편집

git branching - how to make current master a branch and then revert master back to previous version?에 대한 허용 대답에 따라이 ..., 나의 주인은 여전히 ​​최근 코멘트 7 files.See 수정 한 것입니다.

누락 된 것이 있습니까? 당신은 아무것도 커밋하지 않은 경우

$ git branch         # 1. starting on master          
# On branch master 
    nothing to commit, working directory clean 


# On branch master        # 2.modifying a file 
# Changes not staged for commit: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# modified: test.txt 
# 
no changes added to commit (use "git add" and/or "git commit -a") 



$ git stash         # 3. stashing changes 
Saved working directory and index state WIP on master: 393bfad initial commit 
HEAD is now at 393bfad initial commit 
$ git status 
# On branch master 
nothing to commit, working directory clean 


$ git checkout -b experiment     # 4. creating new branch experiment 
Switched to a new branch 'experiment' 


$ git stash pop        # 5. pop staged changes in exper. 
# On branch experiment 
# Changes not staged for commit: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# modified: test.txt 
# 
no changes added to commit (use "git add" and/or "git commit -a") 
Dropped refs/[email protected]{0} (16b6871d43f367edd03f59558eca4163cd1a2b2f) 


$ git checkout master       #6. going back to master 
M test.txt 
Switched to branch 'master' 
git status 
# On branch master 
# Changes not staged for commit: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# modified: test.txt    #7. in master test.txt is still modified !!! 
+1

가능한 중복 (http://stackoverflow.com/questions/6764893/git-branching-how-to -make-current-master-a-branch-and-then-revert-master-back) –

답변

4

git stash pop 후에는 새로운 지점으로 커밋해야합니다. master을 확인하기 전에 커밋하십시오.

$ git stash pop 
$ git commit -m "Committing changes to branch experiment" 
$ git checkout master 

다음 시퀀스를 고려하십시오. 처음부터 (즉, 당신은 작업 디렉토리에 지역 unstaged 변경 지점 마스터에), 당신은 다만 수 :

$ git checkout -b experiment 
$ git add test.txt 
$ git commit -m 'Commit message' 
$ git checkout master 

숨김의 장점은/팝는 당신을 위해 '추가'않는다는 것입니다 변경된 파일을 지정할 필요가 없습니다. 그러나 당신은 여전히 ​​새로운 지회에 전념해야합니다.

-1

에서 사용 자식 숨겨 놓은 와 자식 숨겨 놓은 팝업, git stash 갈 아무 문제 없습니다. 이미 커밋을했다면 (그리고 정말로해야합니다) git stash 도움이되지 않습니다. 이 경우 가장 쉬운 방법은 다음과 같습니다.

  • 체크 아웃 마스터.
  • 코드를 작성하고 커밋하십시오. 절대에는 커밋되지 않은 변경 사항이 있습니다.
  • 마스터를 기반으로하는 새 분기를 원한다는 것을 알고 있습니다.
  • 브랜치 이름을 간단히 바꿉니다. git branch -m feature-xy.
  • 이 브랜치가 여전히 원격 마스터를 추적하므로 잠재적 업스트림 변경 사항을 통합하기 위해 git pull --rebase과 같은 작업을 수행 할 수 있습니다.
  • 이 완료되면 푸시 그것은 : git push -u feature-xy:feature-xy. (참고 -u하는 당신에게 상류 지점을 업데이트)
  • 로컬 깨끗한 마스터가 단순히 그것을 확인 얻으려면 : 로컬 마스터 더 이상 없기 때문에 (git checkout master을, 자식은 생성됩니다 업스트림의 새로운 버전)
+0

이것은 지나치게 복잡한/혼란스러운 대답입니다. 필요한 유일한 단계는 새 분기를 작성하고 커밋하는 것입니다. 실제로 마스터 브랜치의 이름을 바꾸기 위해 -1 (무엇?). – AD7six

+0

이미 커밋 한 경우 포인터를 재설정하는 것보다 해당 분기의 이름을 간단히 변경하는 것이 훨씬 쉽습니다. 이 방법으로 생각하십시오 : 당신은 기능을 다루고 있었으므로 커밋은 그 기능에 속합니다. 따라서이 방법으로 지사 이름을 지정해야합니다. – michas

+0

복잡성 :'git branch -m'과'git stash; git checkout -b; git stash pop' - 결과는 같습니다. – michas

0

나는 이것을 시험하지 않았으며 (나는 맹목적으로 신뢰할 수있는 녀석이 아니다), stashing (http://git-scm.com/book/en/Git-Tools-Stashing)을 읽은 후에는 다음 명령이 가장 좋을 것처럼 보인다.

git stash 
git stash branch testchanges 
[자식 분기? - 어떻게 현재 마스터 지점 확인하고 다시 이전 버전으로 마스터를 되돌리려]의
관련 문제