Typography

活版印字


  • Home
  • Archive
  • Categories
  • Tags
  •  

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo

使用 git stash

Posted at 2016-03-06 git 

當從 SVN 轉換使用到 GIT 後,最大的改變是什麼?除了沒網路還可以看到 log history 之外,我想就是不斷切來切去的 Branch。

我必須要坦誠的說,雖然我用 GIT 有好幾年了,但只有當初為了在公司導入 GIT,有認真的把一本 GIT 的原文翻譯書看完,有基本觀念後,就沒有在繼續摸下去了。

其實 git stash 也是不很難的東西,但就一直沒有需要用到這個指令,因為我還是會稍微把 code 整理一下,然後 commit 進去,大不了 push 前,在做一次合併 commit,或許也是我對於 stash 的概念,沒有很有把握,總覺得先 comment 會比較保險。

最近為了找 git submodule 的資料,偶然再次遇見它,這次就實際 try 了一下用法。

git stash

主要是使用在一個很尷尬的狀態,就是你已經改了一些東西,還不能 comment 進去,你又想切去其他分支,但切去其他分支前提是 git status 已經沒有東西。

這時你就可以 git stash 把改過的東西先丟進 stash 中,等你處理完其他事情,再切回你剛剛中斷的分支,把放進 stash 的東西再拿出來。

需要用到的指令

將改到一半的 code ,放到stash

1
2
git add .
git stash

查看有多少 stash

1
git stash list

取出最後一個 stash 的 code

1
git stash pop

GIT 觀念

基本觀念

  • log
  • add / rm
  • stash
  • commit / reset
  • push / pull / fetch
  • remote repo / local repo
  • branch / merge
  • 初階 rebase
  • Git Flow
  • 衝突排解

進階觀念

  • 合併 comment
  • 分離 comment
  • delete 掉的 branch 救回
  • cherry-pick
  • format-patch
  • pull-request
  • 略…

我覺得 GIT 其實是入門簡單,真正在用到熟練,還是有難度在的。

Share 

 Previous post: JWT (5) Client Side 實作範例 Next post: 將 hexo 部署到 github page 

© 2020 alincode

Theme Typography by Makito

Proudly published with Hexo