久聞git大名,但是一直不知道為何物。現在認真的過了一遍。原來是和svn一樣的版本控制器。
具有速度快,分布式管理等優點。
現在就來看看git的使用過程,我這裡是用開源中國來Managed 程式碼的,如果是使用github也是一樣的。
1 先下載git for windows
然後一直點下一步安裝.
2 安裝之後,選擇git gui.產生ssh 連結 git 公開金鑰.
用命令也可以:
$ ssh-keygen -t rsa -C "your_emali@youemal.com"
然後輸入密碼.
建議用第一種方式。第二種網上說是可以,但是我沒成功過。
然後輸入密碼。
3 將公開金鑰添加到開源中國上,或者是github中
在開源中國中建立一個公開金鑰,然後將.ssh檔案夾下的id_ras_pub中的內容複寫到文字框中,這裡的title可以隨意.
4 測試連結:
輸入命令:$ ssh -T git@git.oschina.net
然後輸入yes
如果成功可以看到你的使用者名稱和郵箱.
出現錯誤可以測試:$ ssh -Tv git@git.oschina.net
5 設定使用者名稱和郵箱
$ git config user.name"you name"
$git config user.email"you_email@youemal.com"
6 然後在web開源中國中建立一個project.
7 測試上傳檔案
建立檔案夾,需要和你建立的projexct同名。
mkdir hello
cd hello
git init
touch README
git add README
git commit -m 'frist commit'
8 提交
git remote add test git@git.oschina.net:web使用者名稱/hell.git
git push -u test master
如裡有報錯誤:
To git@git.oschina.net:yangzhi/hello.git ! [rejected] master -> master (fetch first)error: failed to push some refs to 'git@git.oschina.net:yangzhi/hello.git'hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushinhint: to the same ref. You may want to first merge the remote changes (e.g.hint: 'git pull') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.
可以輸入:
git push -f
可以ok了.
10 複製代碼
git clone git@github..com:使用者名稱/項目名.git