[Git] 將 git stash 記錄重新應用到正確的分支上
先去修另一個臨時的 bug,
之後再用 git stash pop 還原原本的進度。
不過今天卻不小心在錯誤的分支上,下了 git stash pop 指令,
結果導致了一堆衝突:
testuser@localhost ~ $ git stash pop Auto-merging src/util.py CONFLICT (content): Merge conflict in src/util.py Auto-merging src/handler.py CONFLICT (content): Merge conflict in src/handler.py Auto-merging src/common.py CONFLICT (content): Merge conflict in src/common.py
用 git status 看一下,因為合併出了問題,
所以有好幾個檔案都顯示 both modified:
On branch dev Your branch is up to date with 'origin/dev'. Unmerged paths: (use "git reset HEAD ..." to unstage) (use "git add ..." to mark resolution) both modified: common.py both modified: handler.py both modified: util.py
問題是就算切到正確的分支上,
也沒辦法再用 git stash pop,因為 stash 的紀錄已經被用掉了…
查了一下,網友說可以用下面落落長的 git log 指令,
來檢視所有的 commit (包含 git stash 的操作):
testuser@localhost ~ $ git log --graph --decorate --pretty=oneline --abbrev-commit --all $(git fsck --no-reflogs | grep commit | cut -d' ' -f3) Checking object directories: 100% (256/256), done. Checking objects: 100% (8228/8228), done. * d3f1b70 (origin/feature/support-file-types) Show filetype when calling listall | * 03675ff (origin/bug/fix-unicode, bug/fix-unicode) Fix unicode chars | | * 473eed7 (origin/feature/modify-graph) Merge branch 'dev' of adc.github.test.com:test/TestProj into feature/modify-graph | | |\ | | |/ | |/| | | * 450c3ca Add L10N | | | * 323fc89 (refs/stash) WIP on feature/gen-xml: e51f013 Merge branch 'dev' into feature/gen-xml | | | |\ | | | | * 180d208 index on feature/gen-xml: e51f013 Merge branch 'dev' into feature/gen-xml | | | |/ | | | * e51f013 (HEAD -> feature/gen-xml) Merge branch 'dev' into feature/gen-xml
從上面的 git log 來看,可以看到 stash 的記錄是在 323fc89,
因此我們可以直接在正確的分支上,
重新應用上這個 stash 記錄:
testuser@localhost ~ $ git stash apply 323fc89 On branch feature/gen-xml Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: common.py modified: handler.py modified: util.py
這次 stash 記錄就成功的應用上去了~
(本頁面已被瀏覽過 572 次)