什麼是git,什麼是github,說概念我真的不懂,我知道這些東西能夠用於源代碼的管理。
我爲什麼要學習github,原因很簡單,有次我看到一位牛人的博客說:現在的程序員如果還不會掌握github的使用你還算是一名程序員麼?
哎,自己確實也不會,既然這樣提到了github,我當時就有了一種要學習github的想法,平常也見過不少人用github,比如很著名的的就是cocos2dx 開源項目:https://github.com/cocos2d/cocos2d-x.git.
於是就馬上註冊了一個github的賬號:
裏面有方法教如何創建repository,如何fork,如何follow等等,哎這些都感覺挺簡單的。
簡單就是簡單,但是有些概念我很模糊,git到底是什麼,github倒是又是什麼?我一直很混淆。
這裏極力推薦一個關於git的英文網站:
http://git-scm.com/book/en/v2/Getting-Started-About-Version-Control
裏面講得很詳細,這裏說說git得歷史,
As with many great things in life, Git began with a bit of creative destruction and fiery controversy.
The Linux kernel is an open source software project of fairly large scope. For most of the lifetime of the Linux kernel maintenance (1991–2002), changes to the software were passed around as patches and archived files. In 2002, the Linux kernel project began using a proprietary DVCS called BitKeeper.
In 2005, the relationship between the community that developed the Linux kernel and the commercial company that developed BitKeeper broke down, and the tool’s free-of-charge status was revoked. This prompted the Linux development community (and in particular Linus Torvalds, the creator of Linux) to develop their own tool based on some of the lessons they learned while using BitKeeper. Some of the goals of the new system were as follows:
-
Speed
-
Simple design
-
Strong support for non-linear development (thousands of parallel branches)
-
Fully distributed
-
Able to handle large projects like the Linux kernel efficiently (speed and data size)
Since its birth in 2005, Git has evolved and matured to be easy to use and yet retain these initial qualities. It’s incredibly fast, it’s very efficient with large projects, and it has an incredible branching system for non-linear development (See Chapter 3).
Cocos2dxMyMM
$ ssh -T [email protected] //檢測是否鏈接上github了
如果出現以下信息就表明已經連接上了
Hi aiwobiezoukainnn! You've successfully authenticated, but GitHub does not provide shell access.
然後cd到你需要提交的源代碼目錄,比如我的:
cd MM
接着,輸入,
git init //初始化git倉庫,
接着輸入git status,查看狀態,比如我的餓項目下有兩個文件夾Classes 和 Resources出現下圖:
接着將你項目裏面的文件添加進來,當然這時候,你添加的文件並不是真正添加到.git裏面,而是添加到索引index裏面,
這個索引保存的是變化緩存,直到輸入提交命令git commit才添加到.git裏面。
輸入git add * //這裏的*表明將全部的文件添加進來
然後我們在查看下狀態,輸入git status, 如下圖:
接着輸入:git commit -m "first commit" // 注意這裏-m表示添加的註釋,不應該位空
這樣就將項目下的文件全部添加到了本地.git庫,但這並沒有提交到遠程的git上,所以還需要輸入:
remote add gg [email protected]:aiwobiezoukainnn/Cocos2dxMyMM.git
這裏的gg隨便取
然後我們查看下遠程連接地址,
git remote -v最後一步就是:push一下:
git push gg master
如果不成功的話,那就先將遠程的拉下來下:
git pull gg master
然後再push.
OK, 先到此吧
推薦學習關於git的學習:
http://www.ihref.com/read-16369.html
git官方中文參考手冊: