清屏:ctrl+l

1 在linux下安装git
yum -y install git

查看版本 git --version

4 设置git的用户名和邮箱地址
git config --global user.name "savadika"
git config --global user.email "ylf8708@126.com"

2 生成ssh的key文件
ssh-keygen -t rsa -C "ylf8708@126.com"
此时会出来两个确认:
enter file which to save the key(/root/.ssh/id_rsa): 点回车
enter the passphrase(empty for no passphrase): 意思是确认密码,点回车
enter same passphrase again: 再次确认密码,点回车
然后找到/root/.ssh 下面的文件,找到id_rsa.pub(公钥文件),复制其中的key

3 然后打开网页上的github,在github上填写key,见图

此时进入/root 下可以看到这个y文件和y.pub文件,打开y.pub(公钥密匙),看到内容为很长一串文件,copy下来:
copy的办法:使用ssh终端连接登录到linux,然后ctrl+c,需要的地方再ctrl+v;

4 测试连接,OK
[root@localhost .ssh]# ssh -T git@github.com
The authenticity of host 'github.com (192.30.252.129)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.252.129' (RSA) to the list of known hosts.
Hi savadika! You've successfully authenticated, but GitHub does not provide shell access.
[root@localhost .ssh]#

到目前为止,git已经安装成功,先来学习本地仓库
在/tmp下新建gitpro文件夹,进入gitpro,然后建立本地仓库
初始化命令: git init
利用ls -ah 命令可以看到这个.git的隐藏文件,这个就是仓库

[root@localhost gitpro]# git init
Initialized empty Git repository in /tmp/gitpro/.git/
[root@localhost gitpro]# ls -ah
. .. .git
[root@localhost gitpro]# cd .git/
[root@localhost .git]# ls
branches config description HEAD hooks info objects refs
[root@localhost .git]#

在 gitpro 文件夹下,注意:不要进.git文件
新建readme.txt,然后随便写点内容,保存

提交到git仓库,两步
git add readme.txt
git commit -m "create a txt"

修改readme.txt 后,就可以查看状态了,
git status 显示git状态
[root@localhost gitpro]# git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: readme.txt
#
no changes added to commit (use "git add" and/or "git commit -a")

如果你要看具体修改了什么
git diff

[root@localhost gitpro]# git diff
diff --git a/readme.txt b/readme.txt
index 69f9b26..d64807a 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
-hello ,this is a new txt
+hello ,this is a new distrube txt
let us start
[root@localhost gitpro]#

总结下,就是三步:1 修改文件 2 git add 文件 3 git commit -m "备注"

如果需要看日志的话
git log
[root@localhost gitpro]# git log
commit adedce902c5bf1f57cedd4f971b2ce98f6b86509
Author: savadika <ylf8708@126.com>
Date: Tue Jan 5 17:18:07 2016 +0800

this is a third work

commit 55ac577532aa97fbb4295303a664a5ad7505e540
Author: savadika <ylf8708@126.com>
Date: Tue Jan 5 17:14:51 2016 +0800

add distribu

commit c80957880f0618ba0f682a94498d50e8afe5a674
Author: savadika <ylf8708@126.com>
Date: Tue Jan 5 17:02:35 2016 +0800

create a txt

好了,现在我们启动时光穿梭机,准备把readme.txt回退到上一个版本,也就是“add distributed”的那个版本,怎么做呢?

首先,Git必须知道当前版本是哪个版本,在Git中,用HEAD表示当前版本,也就是最新的提交3628164...882e1e0(注意我的提交ID和你的肯定不一样),
上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。

[root@localhost gitpro]# git reset --hard HEAD^
HEAD is now at 55ac577 add distribu

也就是说,此时已经退回到了55ac57这个版本了

那万一回退错了,想撤销呢?先要保证这个版本号你记得

使用git reset --hard adedce(想回退过去的那个版本的前6位)

万一实在忘记了呢,没事,还是有后悔药
git reflog,能够看到那个版本的东西
[root@localhost gitpro]# git reflog
adedce9 HEAD@{0}: adedce: updating HEAD
55ac577 HEAD@{1}: HEAD^: updating HEAD
adedce9 HEAD@{2}: commit: this is a third work
55ac577 HEAD@{3}: commit: add distribu
c809578 HEAD@{4}: commit (initial): create a txt

现在,你又理解了Git是如何跟踪修改的,每次修改,如果不add到暂存区,那就不会加入到commit中。

关于删除:
在工作区的删除回滚:
git checkout --readme.txt

已经add,后怎么删除全部文件
git rm test.txt
git checkout --readme.txt

测试远程仓库
上传:
问题1 :出现已有origin仓库出错
1 删除原有的origin仓库(有出现错误的时候做这个操作)
git remote rm origin

问题2 :直接在远程仓库里面修改后再推送报错,因为已经修改过,所以需要先pull到本地
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.

解决:[root@localhost gitpro]# git pull 将github仓库上的文件覆盖到本地
然后再
[root@localhost gitpro]# git push origin master

2 在web上新建一个项目用来测试推送,地址为:git@github.com:savadika/gitpro.git

推送上去:
[root@localhost gitpro]# git remote add origin git@github.com:savadika/gitpro.git //添加远程git仓库
[root@localhost gitpro]# git push -u origin master //第一次添加
$ git push origin master //以后添加

下载:
git clone https://github.com/yiiext/chart 或者使用ssh协议更快 git clone git@github.com:yiiext/chart
然后就能看到下载的这个软件了,可以进行查看等

oK.大工告成!

github在liunx上的搭建的更多相关文章

  1. <转>git,github在windows上的搭建

    http://www.cnblogs.com/yixiaoyang/archive/2012/01/06/2314190.html Git在源码管理领域目前占很大的比重了,而且开源的项目很多都转到Gi ...

  2. 上一周,小白的我试着搭建了两个个人博客:在github和openshift上

    上一周,突发奇想,想搭建个自己的博客. 由于是突发奇想,自然想先找免费的试试手.仔细搜索下,选定了目标Openshift和Github. Openshift 安装WordPress OpenShift ...

  3. 将 Hexo 个人博客同时部署到 GitHub 和 Coding 上

    一.将个人博客托管到 GitHub 上 关于如何快速搭建自己的个人博客,如何完善自己的个人博客,什么是 GitHub ,如何将自己的博客代码托管到 GitHub 上面等等问题,我之前写过三篇文章已经做 ...

  4. 将`VuePress`建立的博客部署到GitHub或Gitee上

    将VuePress建立的博客部署到GitHub或Gitee上 在上一篇中,我们详细介绍了如何利用VuePress搭建起个人博客系统,但这只是在本地debug启动的,接下来,我们把它部署到Github网 ...

  5. 在GitLab pages上快速搭建Jekyll博客

    前一段时间将我的Jekyll静态博客从github pages镜像部署到了 zeit.co(现vercel)上了一份,最近偶然发现gitlab pages也不错,百度也会正常抓取,于是动手倒腾,将gi ...

  6. 在阿里云服务器(ECS)上从零开始搭建nginx服务器

    本文介绍了如何在阿里云服务器上从零开始搭建nginx服务器.阿里云服务器(ECS)相信大家都不陌生,感兴趣的同学可以到http://www.aliyun.com/product/ecs去购买,或到体验 ...

  7. [转]Liunx上安装svn客户端

    [转]Liunx上安装svn客户端 虽然说很简单的用yum install subversion就可以将svn安装到系统中,但是yum库中的版本实在是有点低——1.4.2.因此我选择以源码方式安装.安 ...

  8. WAMP Server助你在Windows上快速搭建PHP集成环境

    WAMP Server助你在Windows上快速搭建PHP集成环境 原文地址 我想只要爬过几天网的同学都会知道PHP吧,异次元的新版本就是基于PHP的WordPress程序制造出来的,还有国内绝大部分 ...

  9. C#在局域网中连接Liunx上的MySql数据库

    前期准备工作: 我所用的平台是VS2010和Ubuntu 14.04.3  LTS 一.由于MySql并没有集成在VS2010中所以要先安装MySQL Connector Net 6.9.8连接工具, ...

随机推荐

  1. 简易版C语言程序设计语法

    源程序 → 外部声明 | 子程序(外部声明) 外部声明   → 函数定义| 函数声明 函数定义 → 类型标识符(复合句) 标识符类型 → 无类型 | 字符型 | 整型 | 浮点型 整型→ 长整型 | ...

  2. Open Live Writer 安装

    Open Live Writer来源 Windows Live Writer在2012年就停止了更新,Open Live Writer是由Windows Live WriterWriter更名而来,是 ...

  3. ipxe引导远程的windows

    使用ipxe解决本地引导远程系统 本地安装的centos7,然后修改grub.cfg来使用ipxe技术引导远程windows,实现双系统 os-->centos7 修改grub.cfg 在文件最 ...

  4. itellij idea导入web项目并部署到tomcat

    概述 主要分为项目配置和tomcat配置两大步骤. 一.项目配置 打开idea,选择导入项 选择将要打开的项目路径后,继续选择项目的原本类型(后续引导设置会根据原本的项目类型更新成idea的项目),此 ...

  5. JAVASE02-Unit010: 多线程基础 、 TCP通信

    多线程基础 . TCP通信 * 当一个方法被synchronized修饰后,那么 * 该方法称为同步方法,即:多个线程不能同时 * 进入到方法内部执行. package day10; /** * 当多 ...

  6. 使用jsonp跨域请求后可以获得数据,但是进入error方法,返回parseerror

    $.ajax({ url:url, dataType:'jsonp', jsonp: 'callback',//回调函数名字 jsonpCallback: 'success_jsonpCallback ...

  7. JUnit4:Test注解的两个属性:expected和timeout

    JUnit4:Test文档中的解释: The Test annotation supports two optional parameters. The first, expected, declar ...

  8. Python之路-python(mysql介绍和安装、pymysql、ORM sqlachemy)

    本节内容 1.数据库介绍 2.mysql管理 3.mysql数据类型 4.常用mysql命令 创建数据库 外键 增删改查表 5.事务 6.索引 7.python 操作mysql 8.ORM sqlac ...

  9. LoadRunner连接Genymotion

  10. oracle归档模式和非归档模式的切换

    Oracle从未归档日志改成归档日志: SQL> shutdown immediate; 数据库已经关闭. 已经卸载数据库. Oracle 例程已经关闭. SQL> startup mou ...