Just writing

Rollback a commit on remote git repository


第一種方式是先 git reset 然後做 force push, 例如;

~/testGit/gittest$ git reset --hard 36b6b053ff9980ce7934f9f9c4a5a849ca7fcc7a
HEAD is now at 36b6b05 use "git mv" to move file out of folder
~/testGit/gittest$ git push origin 3d_test --force #也可以 git push --force 就好
Total 0 (delta 0), reused 0 (delta 0)
To [email protected]:group_name/gittest.git
 + 0d811ef...36b6b05 3d_test -> 3d_test (forced update)

第二種方式是直接做 force push, 把 branch 的頭直接指向某個 commit 去,例如:

~/testGit/gittest$ git push --force origin HEAD^:3d_test
Total 0 (delta 0), reused 0 (delta 0)
To [email protected]_url:group_name/gittest.git
 + 62f6af0...36b6b05 HEAD^ -> 3d_test (forced update)

兩種的差別可以這樣看,第一種方式會直接把 local 的最後一次 commit 給捨棄掉,然後同步回 server 上;第二種方式是直接對 server 操作,強迫 branch head 指到某個 commit 去,所以 local 還會保留有後來的更新。

Original link: Phanix's Blog

Like my work??
Don't forget to support or like, so I know you are with me..


Want to read more ?

Login with one click and join the most diverse creator community.