什么是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 git@github.com //检测是否链接上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 git@github.com: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官方中文参考手册: