Git/Github的使用並與Eclipse整合
Git簡介
Git是一個免費的、分佈式的版本控制工具,或是一個強調了速度快的源代碼管理工具。每一個Git的工作目錄都是一個完全獨立的代碼庫,並擁有完整的歷史記錄和版本追蹤能力,不依賴於網絡和中心服務器。
Git 在管理項目時,在本地會有三個工作區域:Git 的本地數據目錄,工作目錄以及暫存區域。如下圖所示:
因此對於任何一個文件,在 Git 內都只有三種狀態:已提交(committed),已修改(modified)和已暫存(staged)。
安裝及配置Git
- sudo apt-get install git git-core
首先去https://github.com/ 註冊一個賬戶,當然是free and opensource的用戶了。
- mkdir ~/git
初始化兩個參數:
- git config --global user.name = "username"
- git config --global user.email = "[email protected]"
因爲本機是通過ssh鏈接github的,所以先創建ssh密鑰。
- cd ~/.ssh
提示沒有文件或者目錄的話說明本機還沒有創建過,繼續執行
- ssh-keygen -t rsa -C "[email protected]"
一路Enter,在根目錄下面就會生產.ssh文件夾(隱藏,查看隱藏文件夾的話按Ctrl+H),裏面有生產的密鑰文件。
- ssh -T [email protected]
成功連接的結果就想這樣:
- Agent admitted failure to sign using the key.
- Permission denied (publickey).
執行
- ssh-add
使用git
- git clone https://github.com/SimonVT/android-menudrawer.git
會自動下載整個工程到當前的目錄。
- mkdir ~/git/repos
- cd ~/git/repos
- git clone [email protected]:***/***.git
執行完畢後,repos文件夾下就拷貝好了github上的項目。
- git add . //往暫存區域添加已添加和修改的文件,不處理刪除的文件
- git status //比較本地數據目錄與暫存區域的變化
- git commit -m "commit directions" //提到代碼到本地數據目錄,並添加提交說明
- git pull //更新代碼
- 根據提示修改衝突文件中的代碼
- git add .
- git commit -m "commit directions"
- git push
Create a new repository on the command line
touch README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/user_name/repository_name.git
git push -u origin master
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
git config --global credential.helper 'cache --timeout 3600'
在Eclipse中整合git
- git remote add origin https://github.com/SilangQuan/LinearCompiler.git
再執行
- git push -f
參考:
git所需安裝包下載 http://pan.baidu.com/s/1mgh0dRi