上个周末
学习
了git和github的使用,而本周主要学习了Linux 上电启动过程和Grub的相关内容,github,git这块就暂时放下了。这两天我装个3个Liunx系统,还有熟悉我新买的kindle fire HD,没写一篇git和github的文章,昨天我又复习了下,今天就写篇文章。
git是啥我就不说了,我觉这是Linus这个大神对世界的另一个巨大贡献,github是个很好的创意,它可以让你的项目托管其上, 自己辛苦积累的代码,如果不托管在github,一旦硬盘坏了,或者重装系统很容易丢失自己重要的代码。
我就把我的第一个github的项目建立的方法写一遍。可能方式不太正规,请路过的高手指正。
第一步安装git
第二步 设置自己的名字和Email,这是你提交commit时候的签名。
这时候,会在你的home目录创建一个隐藏文件.gitconfig:
第三步 生成SSH key
你会在自己输入的路径下看到两个文件:
第四步注册一个github号,这个就不多说了。和普通的注册一样。
第五步设置github的SSH key。
点击中间那个图表,设计帐号信息。选择SSH keys,然后选择Add SSH key.
给ssh key起个名字,然后将生成的id_rsa.pub的内容拷贝进key输入框中。
--------------------------------------------------------------------------------------------
至此,git 和github之间配置部分就结束了,剩下的就是如何建一个工程,如何在本地修改后提交上github。
第一步:
github上创建一个空工程。
比如我创建一个buddy的工程,点击上面图表第一个图标就行。
第二步
把 github上的空工程拉下来:
第三步:为工程添加或者修改你的代码
第四步:把更新的内容添加到索引中
现在就为commit 做好的准备,你可以使用git diff 再加上--cached参数,可以看那些改动将被提交:
第五步:git commit
这时候,github的buddy工程中还没有没有我们的改动:
第六步:推送提交到github
这个步骤完成后,我们可以看到,我们新增的3个文件,在github上可以看到了。
我们可以看下git 的log :
备注:github我用的也不熟,在高手眼里,可能不太正规,git命令理解的也还不深入,还是记录下来整个流程,欢迎大牛前来指导。本来这周应该学习git的使用的,但是必须要先把工作中遇到的问题解决好,所以花了很多的时间学习init 启动过程和grub的内容。等有时间间,我希望能学习整理出一份grub的学习心得出来。
参考文献:
1 Git Community Book 中文版
2 github help :Create A Repo
git是啥我就不说了,我觉这是Linus这个大神对世界的另一个巨大贡献,github是个很好的创意,它可以让你的项目托管其上, 自己辛苦积累的代码,如果不托管在github,一旦硬盘坏了,或者重装系统很容易丢失自己重要的代码。
我就把我的第一个github的项目建立的方法写一遍。可能方式不太正规,请路过的高手指正。
第一步安装git
- sudo apt-get install git-core
- root@manu:~# git config --global user.name "manuscola"
- root@manu:~# git config --global user.email "manuscola@163.com"
- root@manu:~# cat ~/.gitconfig
- [user]
- name = manuscola
- email = manuscola@163.com
- root@manu:~#
- root@manu:~# mkdir .ssh
- root@manu:~# ssh-keygen -C "manuscola@163.com" -t rsa
- Generating public/private rsa key pair.
- Enter file in which to save the key (/root/.ssh/id_rsa): /home/manu/.ssh/id_rsa
- Enter passphrase (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in /home/manu/.ssh/id_rsa.
- Your public key has been saved in /home/manu/.ssh/id_rsa.pub.
- 。。。。。。。
- root@manu:~# cd .ssh/
- root@manu:~/.ssh# ll
- 总用量 16
- drwxr-xr-x 2 root root 4096 11月 10 23:11 ./
- drwxr-xr-x 34 manu manu 4096 11月 10 23:06 ../
- -rw------- 1 root root 1766 11月 10 23:11 id_rsa
- -rw-r--r-- 1 root root 399 11月 10 23:11 id_rsa.pub
第五步设置github的SSH key。
点击中间那个图表,设计帐号信息。选择SSH keys,然后选择Add SSH key.
给ssh key起个名字,然后将生成的id_rsa.pub的内容拷贝进key输入框中。
--------------------------------------------------------------------------------------------
至此,git 和github之间配置部分就结束了,剩下的就是如何建一个工程,如何在本地修改后提交上github。
第一步:
github上创建一个空工程。
比如我创建一个buddy的工程,点击上面图表第一个图标就行。
第二步
把 github上的空工程拉下来:
- root@manu:~/code/c# git clone https://github.com/manuscola/buddy.git
- Cloning into 'buddy'...
- warning: You appear to have cloned an empty repository.
- root@manu:~/code/c# ll
- 总用量 12
- drwxr-xr-x 3 root root 4096 11月 10 23:16 ./
- drwxr-xr-x 4 root root 4096 11月 10 20:40 ../
- drwxr-xr-x 3 root root 4096 11月 10 23:19 buddy/
- root@manu:~/code/c# cd buddy/
- root@manu:~/code/c/buddy# ll
- 总用量 12
- drwxr-xr-x 3 root root 4096 11月 10 23:19 ./
- drwxr-xr-x 3 root root 4096 11月 10 23:16 ../
- drwxr-xr-x 7 root root 4096 11月 10 23:19 .git/
- root@manu:~/code/c/buddy# ll
- 总用量 28
- drwxr-xr-x 3 root root 4096 11月 10 23:30 ./
- drwxr-xr-x 3 root root 4096 11月 10 23:16 ../
- -rw-r--r-- 1 root root 5698 11月 10 23:30 buddy.c
- -rw-r--r-- 1 root root 522 11月 10 23:27 buddy.h
- -rw-r--r-- 1 root root 938 11月 10 23:30 buddy_test.c
- drwxr-xr-x 7 root root 4096 11月 10 23:19 .git/
- root@manu:~/code/c/buddy# git add .
- root@manu:~/code/c/buddy#
- root@manu:~/code/c/buddy# git diff --cached
- diff --git a/buddy.c b/buddy.c
- new file mode 100644
- index 0000000..189cc62
- --- /dev/null
- +++ b/buddy.c
- @@ -0,0 +1,209 @@
- +#include"buddy.h"
- +#include<stdio.h>
- +#include<assert.h>
- +#define _XOPEN_SOURCE 600
- +#define _GNU_SOURCE
- +#include<stdlib.h>
- +#define IS_POWER_OF_2(x) (!((x)&((x)-1)))
- 。。。。。。。
- git commit -m "most code implementation"
第六步:推送提交到github
- root@manu:~/code/c/buddy# git push -u origin master
- Username for 'https://github.com': manuscola
- Password for 'https://manuscola@github.com':
- To https://github.com/manuscola/buddy.git
- * [new branch] master -> master
- Branch master set up to track remote branch master from origin.
我们可以看下git 的log :
- root@manu:~/code/c/buddy# git log
- commit e16877291c4f650f894922647872000be9353105
- Author: manuscola <manuscola@163.com>
- Date: Sat Nov 10 23:42:26 2012 +0800
-
- most code implementation
备注:github我用的也不熟,在高手眼里,可能不太正规,git命令理解的也还不深入,还是记录下来整个流程,欢迎大牛前来指导。本来这周应该学习git的使用的,但是必须要先把工作中遇到的问题解决好,所以花了很多的时间学习init 启动过程和grub的内容。等有时间间,我希望能学习整理出一份grub的学习心得出来。
参考文献:
1 Git Community Book 中文版
2 github help :Create A Repo