Sean's Note: Git
顯示具有 Git 標籤的文章。 顯示所有文章
顯示具有 Git 標籤的文章。 顯示所有文章

2016年10月14日 星期五

[Git] 如何更改 push 後的 commit 內容?

How to change git commit message after push?


若只是要更改近幾次的 commit message 可以用以下指令:
git commit --amend
然後在 force push 到 remote server:
git push --force <repository> <branch>
如果同時也有人在修改該 branch 時,最好是用 --force-with-lease 比較安全,因為如果 upstream 已經有更改時,push 會被 abort:
git push --force-with-lease <repository> <branch>
Ref: http://stackoverflow.com/questions/8981194/changing-git-commit-message-after-push-given-that-no-one-pulled-from-remote

2014年12月28日 星期日

Setting up TortoiseGit with GitHub

安裝環境

  1. 安裝 TortoiseGit 1.8.12.0。
  2. 安裝 Git for Windows 1.9.5。

建立 Git 的 repository

  1. 在要作為 repository 的資料夾上按右鍵 "Get Create repository here...",跳出視窗時
    不需勾選 "Make it Bare",完成後資料夾裡就會出現一個 .git 的隱藏資料夾。
  2. 在 Git 的 Settings -> Git 裡設定 User Info。

Commit 到 Local 端

  1. 在資料夾上按滑鼠右鍵 "Git Commit -> "master"...",此時只是 commit 程式碼到  Local 端而已,還沒 commit 到 GitHub。

Push/Pull 到 GitHub

  1. 先到 GitHub 上建立一個新的 repository。
  2. 點進該新的 repository 後,右側欄可以看到 clone URL 的選項,複製 SSH 的。
  3. 在 Git 的 Settings -> Remote 裡加入一個新的 remote,名字隨便取,URL 貼上剛剛所複製的。

    SSH URL
  4. 要上傳程式碼到 GitHub 之前,要先建立 key,在 TortoiseGit 的資料夾裡找到 "PuTTYgen" 後開啟,滑鼠在中間空白的區域亂滑以建立 key,然後 "Save private key" 到某個地方。

    PuTTY Key Generator
  5. 再把 Public Key 給 copy 下來,到 GitHub 的 Settings -> Personal settings -> SSH keys -> Add SSH key,然後貼上。
  6. 在 TortoiseGit 的資料夾裡找到 "Pageant" 開啟,加入剛剛建立的 private key。

    Pageant
  7. 終於,可以開始 Push 程式碼啦!?
    在資料夾上按滑鼠右鍵 "TortoiseGit" -> "Push ...",跳出 Push 的視窗,OK 送出。

    Push
  8. 如果遇到 error: failed to push some refs to '...........'
    git did not exit cleanly (exit code 1),那就先把 repository 從 GitHub Pull 回來一次,就可以 Push 了!
git did not exit cleanly (exit code 1)