Stash
작업 공간에 unstaged 파일들을 백업하고 작업 공간을 깨끗이 HEAD의 상태로 만들수 있는 도구 입니다.
작업공간의 변경사항으로 인해 원격 저장소에서 git pull 을 하는 경우에 충들이 발생하거나, git rebase 를 시도할때 실패를 하는 경우가 발생할 수 있습니다.
이러한 경우에 git stash 를 이용하여 변경사항을 일시적으로 백업하고 깨끗한 HEAD 로 만들수 있습니다.

Usage
git stash 의 기능들은 아래와 같습니다.
사용하는 방법은 work flow를 확인하세요.
$ git stash help
usage: git stash list [<options>]
or: git stash show [<stash>]
or: git stash drop [-q|--quiet] [<stash>]
or: git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
or: git stash branch <branchname> [<stash>]
or: git stash save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
[-u|--include-untracked] [-a|--all] [<message>]
or: git stash [push [--patch] [-k|--[no-]keep-index] [-q|--quiet]
[-u|--include-untracked] [-a|--all] [-m <message>]
[-- <pathspec>...]]
or: git stash clear
|
work flow
git stash
unstaged 파일들을 백업할 수 있습니다.
git status로 깨끗한 HEAD 상태로 변경됨을 확인하세요.
$ 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 checkout -- <file>..." to discard changes in working directory)
modified: utility /initialize .sh
no changes added to commit (use "git add" and /or "git commit -a" )
$ git stash
Saved working directory and index state WIP on master: 4cab31a Add .out, layer into .gitignore
$ git status
On branch master
Your branch is up to date with 'origin/master' .
nothing to commit, working tree clean
$ _
|
git stash list
stash 로 백업한 내역들을 조회할 수 있습니다.
$ git stash list
stash@{0}: WIP on master: 4cab31a Add .out, layer into .gitignore
|
git stash show
stash 내역들 중 하나를 선택하여 백업한 내용을 확인할 수 있습니다.
$ git stash show 0
utility /initialize .sh | 1 +
1 file changed, 1 insertion(+)
|
git stash pop
작업 공간에 백업한 stash 를 다시 적용할 수 있습니다.
작업 공간에 적용이 되면 stash 내역에서는 이를 제거합니다.
제거 하지 않고 적용하려면 git stash apply 를 사용할 수 있습니다.
$ git stash pop 0
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 checkout -- <file>..." to discard changes in working directory)
modified: utility /initialize .sh
no changes added to commit (use "git add" and /or "git commit -a" )
Dropped refs /stash @{0} (b10a21e55e8397a6c8319d63bfb3982701432f8a)
$ 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 checkout -- <file>..." to discard changes in working directory)
modified: utility /initialize .sh
no changes added to commit (use "git add" and /or "git commit -a" )
$ _
|
git stash clear
백업한 stash 내역들을 모두 지웁니다.
$ git stash
Saved working directory and index state WIP on master: 4cab31a Add .out, layer into .gitignore
$ git stash list
stash@{0}: WIP on master: 4cab31a Add .out, layer into .gitignore
$ git stash clear
$ git stash list
$ _
|
댓글
댓글 쓰기