개발환경, 도구/Git

20220506_git stash

gu9gu 2022. 5. 6. 00:37

상황

현재 A 브랜치에서 작업 파일 중 일부 파일(.gitIgnore)만 develop브랜치에 merge 한 다음 commit and push 하고 싶음

 

 

해결

develop브랜치 merge 하려면 checkout을 해야하는데 현재 a브랜치에서 수정한 파일들을 commit하지 않고 checkout 하면 에러가 발생함.(에러는 아니고 꼬이는건가..?)

그래서 stash에 수정한 파일들을 임시 저장 해놓고 checkout함.

 

 

git clone 주소

git brach A

 

.gitignore 파일에 .history 추가

기타 파일 수정, 기타 파일 추가

   .

   .

 

// 여러 파일 수정했는데 .gitIgnore만 develop 브랜치에 merge하려는 상황

git add .gitignore ( 파일은 절대경로 or 상대 경로로 적어주면 됨)

git commit -m "chore : .gitignore에 .history 추가"

git push

git status -s(간단하게 status를 표현)

git stash(untarcked file 즉 추가한 파일은 제외하고 임시저장소에 넣음)

git stash list(임시 저장소에 추가한 목록)

git stash -u(추가한파일도 임시 저장소에 넣어줌)

git stash list

git checkout develop

git merge A

git status -s

git push

git checkout A

git stash list

git stash pop

git status -s