git stash 可用來(lái)暫存當(dāng)前正在進(jìn)行的工作闸婴, 比如想pull 最新代碼, 又不想加新commit芍躏, 或者另外一種情況邪乍,為了fix 一個(gè)緊急的bug, 先stash, 使返回到自己上一個(gè)commit, 改完bug之后再stash pop, 繼續(xù)原來(lái)的工作。
基礎(chǔ)命令:
$git stash
$do some work
$git stash pop
進(jìn)階:
Git stash save "work in progress for foo feature"
當(dāng)你多次使用’git stash’命令后,你的棧里將充滿(mǎn)了未提交的代碼庇楞,這時(shí)候你會(huì)對(duì)將哪個(gè)版本應(yīng)用回來(lái)有些困惑榜配,
’git stash list’ 命令可以將當(dāng)前的Git棧信息打印出來(lái),你只需要將找到對(duì)應(yīng)的版本號(hào)吕晌,例如使用’git stash apply stash@{1}’就可以將你指定版本號(hào)為stash@{1}的工作取出來(lái)蛋褥,當(dāng)你將所有的棧都應(yīng)用回來(lái)的時(shí)候,可以使用’git stash clear’來(lái)將棧清空睛驳。
git stash # save uncommitted changes
# pull, edit, etc.
git stash list # list stashed changes in this git
git show stash@{0} # see the last stash
git stash pop # apply last stash and remove it from the list
git stash --help # for more info