stash
git stash、git stash save '信息':備份當(dāng)前的工作區(qū),從最近一次提交中讀取相關(guān)內(nèi)容,讓工作區(qū)保持和上一次提交的內(nèi)容一致。同時,將工作區(qū)的內(nèi)容保存到git棧中。
git stash pop、git stash pop stash@{n}:從git棧中讀取最近一次保存的內(nèi)容,恢復(fù)工作區(qū)的相關(guān)內(nèi)容。由于可能存在多個stash的內(nèi)容,所以用棧來管理,pop會從最近一個stash中讀取內(nèi)容并恢復(fù)到工作區(qū)。
git stash pop == git stash pop stash@{0}
git stash drop、git stash drop stash@{0}:丟棄
git stash drop == git stash drop stash@{0}
git stash list:顯示git棧內(nèi)的所有備份,可以利用這個列表來決定從那個地方恢復(fù)。
git stash clear:清空git棧。
git show stash@{n}:當(dāng)有多條記錄并且過了一段時間忘記stash內(nèi)容時通過該命令可以查看stash的具體內(nèi)容。
注意:
- git stash不針對特定的分支,切換分支后,stash內(nèi)容不變,所以彈出時要小心;
- git stash pop或drop后,stash的序號會自動改變,連續(xù)彈出時要注意。
常見問題
1. error: please commit or stash them.
git stash
git pull
git stash pop
2. stash@{n} 異常

PowerShell 中,花括號是代碼塊執(zhí)行標(biāo)識符,需要使用反引號(`)轉(zhuǎn)義。
git stash pop stash@`{0`}
3. Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of password.
- 生成token
GitLab->Edit Profile->Access Tokens - 克隆
git:https://gitlab-xx.com/harmony/app.git
格式:git clone https://{username}:{token}@{URL}
git clone https://{username}:{token}@gitlab-xx.com/harmony/app.git