git及SVN基本用法

一、Git基本用法

1、配置

1)在網上下載git軟件。我的是Git-1.9.5-preview20150319.exe和TortoiseGit-1.8.14.0-64bit.msi。

安裝完後,從開始菜單點擊git bash

2)輸入

ssh-keygen -C "[email protected]" -t rsa

來生成一對密鑰,默認保存到~/.ssh目錄。

3)輸入git config --global user.email [email protected]
git config --global user.name shixin來設置賬戶信息。

4)然後將公鑰添加到對方機器,git clone [email protected]:android-autoEasy.git即可下載服務器項目。

2、常用命令

git branch -a

查看所有分支

git checkout develop

切換分支

git add .

將修改文件添加到git索引

git status

查看修改了的文件

git commit -a -m "comment"

提交修改的內容到本地分支

git pull origin develop

將服務端項目同步到本地

git push origin develop

將本地修改的文件上傳到服務端

二、GitHub配置

1)註冊GitHub賬號,安裝GitHub軟件

http://github.com註冊賬號

我用的GitHub客戶端爲Git-1.8.5.2-preview20131230.exe,下載地址爲http://pan.baidu.com/s/1mgG2FUw

從官網http://windows.github.com/下載來的客戶端跟我的不太一樣,應該是最新版。兩個都行。

2)創建ssh keys並將其添至GitHub

從開始菜單找到並點擊Git Bash

運行cd ~/.ssh查看電腦是否存在ssh keys,若不存在則運行ssh-keygen -t rsa -C "[email protected]"

輸入文件完整目錄名/c/Users/shixin/.ssh/github_rsa及密碼shixin58

在GitHub網站點擊Account Settings->SSH Keys->Add SSH Key

將.pub密鑰文件所有內容粘貼進去

輸入ssh -T [email protected]測試上述操作是否成功

SSH Key的作用可參見http://www.cnblogs.com/lqminn/archive/2013/03/16/2963218.html

3)設置本地用戶名和郵箱

git config --global user.name "shixin58"

git config --global user.email "[email protected]"

4)將local項目上傳至GitHub

在github.com創建倉庫android,見圖

mkdir android;cd android;git init

touch file

mkdir google source;touch google/about.txt source/file{0..5}.txt
git add file google/about.txt source/*
git commit -m 'some message'

git remote add origin [email protected]:shixin58/android.git

(git remote rm origin)

git push -u origin master

上面命令行操作也可通過圖形界面操作,更方便也更易掌握:

​​具體操作見我的百度網盤提供的文檔 github圖形界面上傳文件.docx​,鏈接爲

http://pan.baidu.com/s/1c0f5svI

5)從Eclipse安裝Git插件,下載GitHub上開源項目

點擊Eclipse的Help->Install New Software,在Work with輸入egit,

即egit - http://download.eclipse.org/egit/updates,見下圖

,然後等待下載安裝。

點擊File->import->Projects from Git->Clone URI,依次操作。

過程中若碰到失敗提示git repository clone failed.Read timed out after 30,000 ms,則見下圖操作

,將30調至180即可

三、SVN用法總結

在上家公司用過SVN,體驗了SVN的好處,但卻不曉得如何安裝。來到新公司,需要自己安裝,才現學了一點。

需要安裝兩個東西一個是SVN客戶端,另一個是eclipse上的SVN插件。

首先客戶端好說,到官網download一個安裝唄,我用的是http://tortoisesvn.net/downloads.html。按電腦位數下載最新版。

1、裝好後右擊鼠標,選擇TortoiseSVN下的Repo-browser

 

輸入URL地址,點OK

 

然後就可看到SVN上的資源

 

2、右擊鼠標,選擇SVN Checkout

 

在URL of reposity輸入資源URL,在Checkout directory輸入下載到的路徑,點擊OK,即可下載。

3、然後在Eclipse上安裝svn插件。

官網爲http://subclipse.tigris.org/,點擊裏面的Download and Install。爲Eclipse選擇相應版本的SVN插件。我沒有從這裏下載,只是拷貝下載地址,因爲下載到本地不知如何安裝及放在什麼地方。更好的方法是從Eclipse直接下載。

裝完後重啓Eclipse即可使用。

從SVN服務器下載項目,可點擊Eclipse上File-->Import-->SVN-->雙擊“從SVN檢出項目”,選擇創建新的資源庫位置,點Next

在下面的URL裏輸入地址即可

4、在Eclipse裏提交修改和更新

5、問題總結

1)Eclipse安裝SVN(http://subclipse.tigris.org/update_1.10.x)或ADT插件時遇到問題“需要org.eclipse.draw2d 3.2.0”

解決方案:從http://download.eclipse.org/tools/gef/updates/releases/下載GEF插件

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章