Git 命令

stash

git stash、git stash save '信息':備份當(dāng)前的工作區(qū),從最近一次提交中讀取相關(guān)內(nèi)容,讓工作區(qū)保持和上一次提交的內(nèi)容一致。同時,將工作區(qū)的內(nèi)容保存到git棧中。
git stash popgit 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)容。

注意:

  1. git stash不針對特定的分支,切換分支后,stash內(nèi)容不變,所以彈出時要小心;
  2. 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.

  1. 生成token
    GitLab->Edit Profile->Access Tokens
  2. 克隆
    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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容