[git][branch]stash??


stash


stashの語源定義は「隠す」

branchでは働いていますが、別のbranchでチェックアウトして他のことをする場合は、まだ仕事中の内容を提出してもピンぼけてしまい、提出しないとチェックアウトできません。


その場合、stashを使用して作業内容を隠すことができます.
headのバージョンに移動して、現在のbranchの状態を暗くし、他のbranchでcheckoutを行うことができます.
でも.
このstash機能は,分岐機能が活発でなければ学習しなくてもよい機能である.知ってから必要なときに使ったほうがいいです(頭の中の認知度だけ)
$ git init 
$ f1.txt ( a 입력 ) 
$ git add f1.txt 
$ git commit -m 1  
$ git checkout -b exp # exp 브렌치를 생성하고 체크아웃까지 동시에
$ vim f1.txt
a
b
仕事がまだ終わっていないのに、チェックアウトするとどんな問題が発生しますか?
$ git checkout master 

expで修正した内容はmasterに影響します
git checkoutexpに戻ります.statusコマンドで相変わらずの様子を確認できます.

ではf 1.どうすればいいの?git stash-helpコマンドの使い方を見てみましょう.
$ git stash --help 
$ git stash 
warning: LF will be replaced by CRLF in f1.txt.
The file will have its original line endings in your working directory
Saved working directory and index state WIP on exp: 2441228 1
4行目には、作業ディレクトリとWIP(working in process)exp brunchインデックスが格納されている文が表示されます.
つまり、私たちの作業ディレクトリと作業中の変更は保存されています.
$ git status 
On branch exp
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        common.txt
        exp.txt
        master.txt

nothing added to commit but untracked files present (use "git add" to track)
最後の9行目を見ると、「nothingtocommit」という言葉が出てきます.つまり、提出できるものがないということです.ではこの状態で.
git checkout masterコマンドの使用
$ git checkout master
Master Branchで作業すると楽になりますその後、Git checkout expを再ロードし、master checkoutの前の作業履歴を使用して完了できます.
$ git stash apply

では、次のmodified:f 1です.txtという言葉が見えるはずですstashで隠した事項を再適用して復活しました
$ git stash list
stash@{0}: WIP on exp: 2441228 1
$ git reset --hard HEAD 
# 가장 최신 커밋 상태로 만드는건데, 다 지우는거에요. 
nothing added to commit but untracked files present (use "git add" to track)
$ git stash list
stash@{0}: WIP on exp: 2441228 1

# 여전히 stash 이력이 남아  있어요. 

$ git stash apply 
On branch exp
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:   f1.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        common.txt
        exp.txt
        master.txt

no changes added to commit (use "git add" and/or "git commit -a")
$ git reset --hard 
HEAD is now at 2441228 1

$ git stash apply
On branch exp
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:   f1.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        common.txt
        exp.txt
        master.txt

no changes added to commit (use "git add" and/or "git commit -a")
特にgit stashを明確に削除しない限り、常に生きています.
$ git stash list 
stash@{0}: WIP on exp: 2441228 1
次に、現在の変更の履歴を再設定します.
$ git reset --hard
HEAD is now at 2441228 1
$ vim f2.txt(a 입력) 
$ git add f2.txt
$ git stash 
Saved working directory and index state WIP on exp: 2441228 1

$ git status 
On branch exp
nothing to commit, working tree clean

$ git stash list
stash@{0}: WIP on exp: 2441228 1
stash@{1}: WIP on exp: 2441228 1
13行目git stashの履歴は、5行目の処理のgit stashを指す.では、14行目は前に隠された歴史を話しますか?
したがってgit stash applyコマンドを直接適用するとgit stash listの0番目のコマンドが適用されます.
では、0からstashlistの履歴を順次適用したい場合は、どうすればいいのでしょうか.次と一緒にやろう
$ git stash apply # 가장 최근(0번째) stash 리스트 내역 적용! 
$ git stash drop  # 가장 최근(0번째) 리스트 삭제 
Dropped refs/stash@{0} (b0de4a37c4cb3e9f2b105f4cd4c0b4394d15a

$ git stash apply; git stash drop; # 2개의 명령 수행 
5行目の行の同時適用と削除
上の方法はやはり何度も仕事を繰り返しています.一度解決策を見てみましょう.まずはstatusコマンドで状態を確認
$ git status
On branch exp
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   f2.txt

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:   f1.txt
きれいに拭きます
$ git reset --hard
HEAD is now at 2441228 1

$ git status
On branch exp
nothing to commit, working tree clean

$ vim f1.txt( b추가 입력 ) 
$ git add f1.txt 
$ git stash 
Saved working directory and index state WIP on exp: 2441228 1

$ git status 
On branch exp
nothing to commit, working tree clean
10番目のstashコマンドで隠し、11行目のstatusコマンドですぐにステータスを確認できます.
次のコマンドを異常状態で実行します.
$ git stash pop # == git stash apply; git stash drop;동일

しかしstash機能は、少なくともバージョン管理を行うファイルのみが使用できます。


下を見せてください.
$ git reset --hard 
HEAD is now at 2441228 1

$ vim f1.txt(a입력, 이미 있다면 b입력후 저장) 
$ vim f2.txt(a 입력) 

$ git status
On branch exp
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:   f1.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        f2.txt

no changes added to commit (use "git add" and/or "git commit -a")
12行目で修正:f 1.txtは見えますか?
追跡されています.これは追跡中のファイルです.
ただし、14行目で圧縮されていないfiles:~f 2.txtは見えますか?
つまり追跡されたファイルはありません.
さあ.異常の場合はgit stashを使用します.
$ git stash 
$ git status 
On branch exp
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        f2.txt

nothing added to commit but untracked files present (use "git add" to track)
f2.txtは追跡されていないのでstash機能は適用できません.
少なくとも、バージョン管理されたファイルにのみ格納されることを覚えておいてください.