Posts

Showing posts from 2022

git 指令

remote 的 origin 上有 branch A,local 沒有 branch A。想建立一個跟 origin/A 進度相同的 local branch A git switch -c A origin/A 遠端分枝名稱寫錯了,想改名字。先刪除 remote 的 origin 上的 A 分支,然後再用正確名字 push 一次 git push origin --delete A 參考: How To Rename a Local and Remote Git Branch How to delete remote branches in Git 把本地的 A 分枝 push 到遠端 origin 上的 B 分枝 git push origin A:B 複製其他分枝的 commit 到當前所在的分枝 git cherry-pick <commit hash code> // 只複製一個 commit git cherry-pick <commit hash code 1>..<commit hash code 2> // 複製多個連續的 commit(不包含 hash code 1 的那個 commit) 參考: 你那招很厲害,我不要一整套,可以只要一招嗎?git cherry-pick Git Cherry Pick 的後遺症 暫存目前未 commit 的程式碼 git stash 取出暫存的程式碼 git stash pop 強制蓋掉 remote 的分枝(非常確定這個分支沒有其他人在 commit 時才用,以免把別人的 commit 蓋掉) git push --force-with-lease 參考: Git Force vs Force with Lease