R's Workshop

Push Part of Commits to Remote

紀錄一下 push 部份 commit(s) 到 remote 的方法. 以免再發生因為沒有把未完成的文章 git add 到 staging area 而被 git clean 誤刪的憾事 QQ.

Git Push

通常我們要 push commits 到 remote 時, 我們會用以下指令將目前 branch 的 tip push 到 remote.

$ git push origin branch_name

實際上, 這個指令應該展開成以下格式. 當沒有寫 remote branch name 時, 則把 local branch name 作為 remote branch name.

$ git push origin local_branch_name[:retmote_branch_name]

下一步, git 把 local branch name 視為 commit-ish object, 抓出 branch tip 指向的 commit, 再將該 commit (以及 parent commits) push 到 remote. 所以, 指令可以進一步展開成

$ git push origin commit_of_local_branch_tip:remote_branch_name

到這裡, 我們就可以知道要怎 push 部份 commit(s) 到 remote 啦. 只要寫上要 push 的最後的 commit 的 SHA-1 ID 就可以了.

$ git push origin last_commit_to_psuh:remote_branch_name

Video Resource

也可以高見龍老師的影片教學喔

Reference

Git