全能電路設計實戰

2016年10月12日 星期三

TortoiseGit與GitHub



Git 是一種分散式 Source code 管理系統, 相對於SVN , SVN 則是屬於Client/Server 架構.

在SVN 裡, 每一次的commit 都是送到Server的 Repository上, 而在Git 每一次commit 都是送到Local Repository , 若要分享每次變更的狀態, 則用git push  一次送到Remote Repository。如此相較於SVN, 版本更迭版頻率就不會太快,且每次commit 也不用連在網路上, 除非要push。





Remote Repository 可以選擇免費的Git Server平台, 如SourceforgeBitbucketGitHub, 可以自己先去申請一個帳號. 不過免費帳號是Public Repository, 任何人都可以找到並clone 你的專案, 若付費可以做成private Repository. (一個月大約是7美金, 以GitHub來說的話) 


Github


Git Client 端工具

Git Client 端工具也有很多, 因為過去已習慣使用TortoiseSVN 的界面, 所以使用Git, 也就使用
TortoiseGit。安裝方式,就是從頭到尾到只按"下一步" 就可以安裝完成。

使用TortoiseGit 必須要有 command line 的 git.exe , 故安裝TortoiseGit 須先行安裝 Git for Windows 2.0+

Tortoise 裝完後, 對資料匣按右鍵可以看到TortoiseGit 相關的工具選單



Git 和Remote Repository 有兩種溝通方式,可以使用 https 方式和 ssh 方式。
若使用SSH 會有RSA public/private key 要去產生及設定, 相對而言複雜許多.用 https 設定上其實簡單許多。 

常用的動作:


  • Git clone: 貼上GitHub上的"Clone With HTTPS"的網址, 即可獲得整個專案程式碼



與Local Repository 相關指令


  • git add : 於local repository 中,新增檔案/目錄 (staged)
  • git del :  於local repository 中,刪除檔案/目錄 (staged)
  • git commit : commit只發生在local repository, 並且會記錄在修改歷程記錄檔案中, 若要將此歷程記錄分享到Remote repository, 就執行git push
  • revert: 這個動作就如同 svn update (以Local Repository所記錄的狀態為更新還原的狀態)



與Remote Repository 有關指令


"Git Sync" : 使Local Repository和Remote Repository 達到一致
  • git push : 將Local repository 送到 remote repository, 別人才看得見。git push之前, 要先git pull 取得最新的遠端變更,才能進行git push (此如同svn update 才進行svn commit 以防止版本衝突)。
  • git fetch: 只取得最新的 HEAD
  • git pull : git fetch + merge to local (會從Remote Repository下載最新的歷程記錄,並且自動Merge到Local Repository)

your local repository consists of three "trees" maintained by git. the first one is your Working Directory which holds the actual files. the second one is the Index which acts as a staging area and finally the HEAD which points to the last commit you've made.































TortoiseGit與GitHub 基本操作


  1. 複製git code : git clone https://github.com/xxxxx/project.git
  2. git add  <files>
  3. git commit   <files or *>  
    單純執行 git commit 僅會顯示那些檔案有改過 (即Un-staged 狀態) 
  4. Push 到GitHub: 對clone下來的資料匣, 按右鍵push, 輸入GitHub的username/password。若不是受邀的username , 則必須在Github 上邀請此username成為collaborators
  

輸入GitHub 帳密

push 成功


----------------

其他Git指令: 

查看變更記錄 git log





git Revert : 還原



參考


沒有留言 :

張貼留言