github -help
常用命令:
git克隆項(xiàng)目(下載代碼)
git clone http://192.168.0.223/git/test
git clone git@github.com:laiweiwei/vms.git
git clone git@github.com:syking/smrt-lbs-new.git
復(fù)制粘帖方法:
git bash控制臺(tái)--標(biāo)題欄--右鍵--編輯--標(biāo)記/粘帖
git更新內(nèi)容
cd /d
cd play/smrt-lbs
git pull origin
提交到本地
cd /d
cd play/smrt-lbs
git add .
git commit -m "some string"
提交到服務(wù)器
git push -u origin master
刪除文件(直接刪除后需要重新用命令刪除)
$ git rm app/views/Application/index.html
rm 'app/views/Application/index.html'
查看文件狀態(tài)
git status
假設(shè)你的資料庫(kù)默認(rèn)分支為 master,當(dāng)你有一個(gè)新的項(xiàng)目或者想法時(shí)
創(chuàng)建一個(gè)分支,然后在分支上開發(fā),最后再合并到 master 上
創(chuàng)建新分支并命名,此處我們創(chuàng)建名為 new_sub 的分支
git branch new_sub
移到新分支上
git checkout new_sub
開始你的工作并保存結(jié)果
添加所改動(dòng)的文件以便提交
git add .
提交改動(dòng)
git commit -m "made some changes"
回到 master 主分支
git checkout master
合并到主分支
git merge new_sub
git branch 可顯示所有的分支
刪除分支
git branch -d new_sub
==========================================
Git和GitHub入門
- Git和GitHub簡(jiǎn)單文字說(shuō)明
Git是一個(gè)開源的分布式版本控制系統(tǒng),用以有效、高速的處理各種規(guī)模的項(xiàng)目版本管理, 它是 Linux Torvalds 為了幫助管理 Linux 內(nèi)核開發(fā)而開發(fā)的一個(gè)開放源碼的版本控制軟件,后來(lái)得到廣泛的使用。
GitHub可以托管各種git庫(kù),并提供一個(gè)web界面,但與其它像 SourceForge或GoogleCode這樣的服務(wù)不同,GitHub的獨(dú)特賣點(diǎn)在于從另外一個(gè)項(xiàng)目進(jìn)行分支的簡(jiǎn)易性。為一個(gè)項(xiàng)目貢獻(xiàn)代碼非常簡(jiǎn)單:首先點(diǎn)擊項(xiàng)目站點(diǎn)的“fork”的按鈕,然后將代碼檢出并將修改加入到剛才分出的代碼庫(kù)中,最后通過(guò)內(nèi)建的“pull request”機(jī)制向項(xiàng)目負(fù)責(zé)人申請(qǐng)代碼合并。已經(jīng)有人將GitHub稱為代碼玩家的MySpace。
- 安裝Git on Windows
下載 msysgit(http://code.google.com/p/msysgit/), 安裝時(shí)保留默認(rèn)選項(xiàng), 不要使用putty作為客戶端,GitHub只支持openssh. 安裝完成后需要生成SSH Key.
windows可視化操作界面客戶端(和svn很類似) http://code.google.com/p/tortoisegit/ - 配置
3.1 檢查是否已經(jīng)存在KEY
$ cd ~/.ssh
$ ls
config id_rsa id_rsa.pub known_hosts
$ mkdir key_backup
$ cp id_rsa* key_backup
$ rm id_rsa*
如果已經(jīng)存在KEY(id_rsa, id_rsa.pub),把他們拷貝到key_backup目錄備份, 因?yàn)镾SH默認(rèn)會(huì)使用”.ssh”目錄下的KEY
注:windows7在C:\Users\ZDZ.ssh目錄下可以找到
3.2 生成SSH KEY
代碼
$ ssh-keygen -t rsa -C "your_mail_addr@gmail.com"
Enter file in which to save the key (/c/Users/Tekkub/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Tekkub/.ssh/id_rsa.
Your public key has been saved in /c/Users/Tekkub/.ssh/id_rsa.pub.
The key fingerprint is:
e8:ae:60:8f:38:c2:98:1d:6d:84:60:8c:9e:dd:47:81 your_mail_addr@gmail.com
在這里會(huì)要求輸入key 目錄和 密碼,可根據(jù)自己的情況輸入
注:這里生成的key可以在多個(gè)網(wǎng)站上使用(例如github和bitbucket),只要本地的和對(duì)應(yīng)網(wǎng)站的key保持一致就可以了
3.3 將Public Key 添加到GitHub
打開你的GitHub->SSH Public Key->點(diǎn)擊“Add another public key”, 將你的public key(id_rsa.pub)的內(nèi)容拷貝到GitHub中
bitbucket添加方式:帳號(hào)下來(lái)-->Account-->SSH keys 里面的 Add a new key , 將你的public key(id_rsa.pub)的內(nèi)容拷貝到SSH key文本框
3.4 測(cè)試
$ ssh git@github.com
ERROR: Hi tekkub! You've successfully authenticated, but GitHub does not provide
shell access
Connection to github.com closed.
成功!!
下載你的項(xiàng)目
$git clone git://github.com/schacon/simplegit.git提交變更
5.1 配置
git config --global user.name "Your Name"
git config --global user.email your_email@gmail.com
5.2 創(chuàng)建Repository
1 mkdir clrs
2 cd clrs
3 git init
4 touch README
5 git add README
6 git commit -m 'first commit'
7 git remote add origin git@github.com:your_name/clrs.git
8 git push origin master
5.3 提交已經(jīng)存在的Repository
1 cd existing_git_repo
2 git remote add origin git@github.com:your_name/clrs.git
3 git push origin master
http://gitref.org/ Git參考文檔及命令使用
http://help.github.com/ GitHub幫助
http://code.google.com/p/msysgit/