Programming

Git에 의해 커밋되지 않은 변경 사항을 Master에서 새 지점으로 변경

procodes 2020. 5. 14. 21:04
반응형

Git에 의해 커밋되지 않은 변경 사항을 Master에서 새 지점으로 변경


지점에있을 때 어떻게 커밋되지 않은 변경 사항을 지점 테스트에 적용 할 수 master있습니까?


테스트 브랜치를 체크 아웃 한 다음 커밋하면됩니다. 다른 지점으로 이동할 때 커밋되지 않은 변경 사항은 손실되지 않습니다.

마스터 지점에 있다고 가정합니다.

git checkout test
git add .
git add deletedFile1
git add deletedFile2
...
git commit -m "My Custom Message"

삭제 된 파일에 대해 잘 모르겠지만 사용할 때 포함되지 않은 것 같습니다. git add .


또한 다음을 수행하여 새 분기를 작성하고 전환 할 수 있습니다.

git checkout -b new_branch
git add .

코드 편집을 시작하기 전에 항상 새 브랜치를 시작하는 것을 잊기 때문에 항상 이것을 사용합니다.


왜 git stash를 사용하지 않습니까? 복사하여 붙여 넣기처럼 더 직관적이라고 생각합니다.

$ git branch
  develop
* master
  feature1
  TEST
$

현재 분기에 이동할 파일이 있습니다.

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#      modified:   awesome.py
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#
#      modified:   linez.py
#
$
$ git stash
Saved working directory and index state \
  "WIP on master: 934beef added the index file"
HEAD is now at 934beef added the index file
(To restore them type "git stash apply")
$
$ git status
# On branch master
nothing to commit (working directory clean)
$
$
$ git stash list
stash@{0}: WIP on master: 934beef ...great changes
$

다른 지점으로 이동하십시오.

$ git checkout TEST

그리고 적용

$ git stash apply
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#
#      modified:   awesome.py
#      modified:   linez.py
#

I also like git stash because I use git flow, which complains when you want to finish a feature branch whilst having changes still in your working directory.

Just like @Mike Bethany, this happens to me all the time because I work on a new problem while forgetting I am still on another branch. So you can stash your work, git flow feature finish..., and git stash apply to new git flow feature start ... branch.


git checkout TEST
git add file1 file2
git commit

참고URL : https://stackoverflow.com/questions/1351567/putting-uncommitted-changes-at-master-to-a-new-branch-by-git

반응형