[Git] stash

2022. 1. 24. 23:36· Server/Git
목차
  1. Git stash

Git stash

프로젝트를 진행하면서, 하던 작업을 잠시 멈추고 잠깐 다른 브랜치로 이동 할 일이 생각 보다 많다.

그 때, 사용하는것이 stash !

수정 사항을 스택에 잠시 저장했다가 나중에 다시 적용 할 수 있다.

물론 다른 브랜치에서도 사용 할 수 있다.

정말 많이 쓰기도 해서 정리를 한번 하려고 한다.
보통 사용하는건 6개 정도?



  • git stash
    ㄴ stack 에 저장 하는 명령어
    limjian@Jians-MacBook-Pro-13 coding_practice % git status
    On branch master
    Your branch is up to date with 'origin/master'.
    
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
            modified:   golang/a+b.go
            modified:   golang/atm.go
            modified:   golang/average_score.go
            
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            golang/biggest_number.go
            golang/find_fractional_numbers.go
            golang/k_number.go
            
            
    
    
    limjian@Jians-MacBook-Pro-13 coding_practice % git stash
    Saved working directory and index state WIP on master: de21669 Add adding_spaces.go
     
    참고로
    git stash save "작업 내용"
    이런식으로 많이 저장하는데...

    git stash save 에 대해서 찾아보니까..
    git stash push 대체 사용한다는 말이 있다.

git stash push 로의 이동

2017년 10월 말 Git 메일링 리스트에는 엄청난 논의가 있었습니다. 논의는 git stash save명령을 은퇴시키고  git stash push`로 대체하는 내용에 대한 것이었습니다. `git stash push 명령의 경우 pathspec 으로 선택하여 Stash하는 옵션이 추가되었는데 git stash save 명령이 지원하지 못하는 것이었습니다.

git stash save 명령이 곧바로 삭제되는 것은 아니기에 아직 이 명령을 쓰는 것에 대해 걱정할 필요는 없지만 git stash push 명령으로 대체하는 것에 대해 생각해볼 필요가 있습니다.


  • git stash push -m "작업 내용"
    limjian@Jians-MacBook-Pro-13 coding_practice % git stash push -m "push test"
    Saved working directory and index state On master: push test


    *참고*

    git stash push 는 git version 2.13.7 부터 사용가능 합니다.
    (2.13.7 이전 버전은 git stash save -m "작업 내용")
    # git version 확인
    
    limjian@Jians-MacBook-Pro-13 coding_practice % git --version
    git version 2.32.0 (Apple Git-132)

 

 

  • git stash list
    ㄴ stack 에 있는 저장 list 확인하는 명령어
limjian@Jians-MacBook-Pro-13 coding_practice % git stash list
stash@{0}: On master: push test



  • git stash apply
    ㄴ stack 에 저장되어있는 stash list 중 마지막에 저장 된 stash 적용 (git stash list 에는 남아있음)
    limjian@Jians-MacBook-Pro-13 coding_practice % git stash apply
    On branch master
    Your branch is up to date with 'origin/master'.
    
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
            modified:   golang/a+b.go
            modified:   golang/atm.go
            modified:   golang/average_score.go
            
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            golang/biggest_number.go
            golang/find_fractional_numbers.go
            golang/k_number.go
            
            
            
    # git stash apply stash@{1}
    # 이런식으로 특정 stash 를 불러올수있다.



  • git stash pop
    ㄴ stack 에 저장되어있는 stash list 중 마지막에 저장 된 stash 적용 (git stash list 에서 삭제)
    limjian@Jians-MacBook-Pro-13 coding_practice % git stash pop
    On branch master
    Your branch is up to date with 'origin/master'.
    
    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git restore <file>..." to discard changes in working directory)
            modified:   golang/a+b.go
            modified:   golang/atm.go
            modified:   golang/average_score.go
            
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            golang/biggest_number.go
            golang/find_fractional_numbers.go
            golang/k_number.go
            
    
    # git stash list 에 존재하지 않음 (stack 에서 삭제)
    limjian@Jians-MacBook-Pro-13 coding_practice % git stash list
    limjian@Jians-MacBook-Pro-13 coding_practice %


  • git stash drop
    ㄴ stack 에 저장되어있는 stash list 중 마지막에 저장 된 stash drop
    limjian@Jians-MacBook-Pro-13 coding_practice % git stash
    Saved working directory and index state WIP on master: de21669 Add adding_spaces.go
    limjian@Jians-MacBook-Pro-13 coding_practice %
    limjian@Jians-MacBook-Pro-13 coding_practice % git stash list
    stash@{0}: WIP on master: de21669 Add adding_spaces.go
    
    
    
    limjian@Jians-MacBook-Pro-13 coding_practice % git stash drop
    Dropped refs/stash@{0} (abbf2444c98f9a0b2963306d4700c5f72aead9d8)
    
    
    
    limjian@Jians-MacBook-Pro-13 coding_practice % git stash list
    limjian@Jians-MacBook-Pro-13 coding_practice %​


  • git stash clear
    ㄴ
    stash 에 저장되어 있는 stash list 전부 삭제
limjian@Jians-MacBook-Pro-13 coding_practice % git stash clear
limjian@Jians-MacBook-Pro-13 coding_practice % git stash list
limjian@Jians-MacBook-Pro-13 coding_practice %

'Server > Git' 카테고리의 다른 글

[Git] stash drop 복구 (stash drop rollback)  (0) 2022.01.24
[Git] stash untracked file  (0) 2022.01.24
[Git] invalid active developer path  (0) 2021.12.19
[Git] 로그(Log)  (0) 2021.12.12
[Git] 태그(Tag) 추가, 변경, 삭제  (0) 2021.12.02
  1. Git stash
'Server/Git' 카테고리의 다른 글
  • [Git] stash drop 복구 (stash drop rollback)
  • [Git] stash untracked file
  • [Git] invalid active developer path
  • [Git] 로그(Log)
임쟌
임쟌
임쟌
Jian's Blog
임쟌
전체
오늘
어제

공지사항

  • [자기소개]
  • 쟌's Blog (227)
    • Language (32)
      • Python (8)
      • Go (24)
      • Java (0)
    • Framework (10)
      • Django (9)
      • Gin (1)
      • Spring boot (0)
      • Fiber (0)
    • Database (10)
      • PostgreSQL (8)
      • MySQL (0)
      • Redis (2)
    • Server (51)
      • Linux (16)
      • Git (12)
      • Oracle Cloud Infrastructure (13)
      • Mac (4)
      • Docker (4)
      • RabbitMQ (0)
      • ETC (2)
    • Operating System (0)
      • OS (0)
    • Algorithm (22)
      • Go (22)
      • Python (0)
    • Exam Certification (4)
    • Daily Life (27)
      • Review (21)
      • Diary (6)
    • 이공계전문기술연수 (71)
      • Java (17)
      • Database (8)
      • HTML | CSS (13)
      • JavaScript | jQuery (6)
      • Servlet | JSP (16)
      • Spring Framework (11)

인기 글

최근 댓글

최근 글

hELLO · Designed By 정상우.v4.2.2
임쟌
[Git] stash
상단으로

티스토리툴바

개인정보

  • 티스토리 홈
  • 포럼
  • 로그인

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.