环境:Ubuntu Server 12.04


  1. 安装Git

    apt-get install git git-core
    

      

  2. 配置本机Git
    git config --global user.name "evilxr"
    git config --global user.email evilxr@gmail.com
    git config --global color.ui true

      

  3. 列出所有配置

    tp@Evilxr:/tmp$ git config --list
    user.name=evilxr
    user.email=evilxr@gmail.com
    color.ui=true
    tp@Evilxr:/tmp$

      以上操作实际上修改的是这个文件

    tp@Evilxr:/tmp$ cat ~/.gitconfig
    [user]
    name = evilxr
    email = evilxr@gmail.com
    [color]
    ui = true

      

      

  4. 生成密钥
    ssh-keygen -t rsa -C evilxr@gmail.com
    

      

  5. 提交密钥
    vim /root/.ssh/id_rsa.pub
    

      复制里面的密钥,到github网页中登陆自己的账号,然后再account setting中,找到SSH KEY讲复制的密钥加入(需要github密码确认)

  6. 检验是否链接上了github
    ssh git@github.com
    

    PTY allocation request failed on channel 0
    Hi evilxr! You've successfully authenticated, but GitHub does not provide shell access.
    Connection to github.com closed.


    推荐:Git练兵场


    补充:

         git的版本查询    git --version
    git的路径查询 which git

  7. 创建一个repository
    # mkdir Python_urllib
    # git init
    # vim Python_urllib # coding:utf8 import urllib
    import chardet def automatic_detect(url):
    """" doc """
    content = urllib.urlopen(url).read()
    result= chardet.detect(content)
    encoding = result['encoding']
    return encoding url_list = ["http://www.sina.com.cn/",
    "http://www.cnblogs.com/evilxr",
    "http://bbs.hackav.com/",
    "http://www.baidu.com/",
    "http://fuli.ba/"]
    for url in url_list:
    print url, automatic_detect(url)

      

  8. git status
    tp@Evilxr:/tmp/Python_urllib$ git status
    位于分支 master 初始提交 未跟踪的文件:
    (使用 "git add <file>..." 以包含要提交的内容) Python_urllib.py 提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)

      

  9. git add
    tp@Evilxr:/tmp/Python_urllib$ git add Python_urllib.py
    tp@Evilxr:/tmp/Python_urllib$ git status
    位于分支 master 初始提交 要提交的变更:
    (使用 "git rm --cached <file>..." 撤出暂存区) 新文件: Python_urllib.py

      

  10. git commit -m 'something you need say.'
    tp@Evilxr:/tmp/Python_urllib$ git commit -m 'Python Scrip'
    [master (根提交) 7555373] Python Scrip
    1 file changed, 20 insertions(+)
    create mode 100644 Python_urllib.py
    tp@Evilxr:/tmp/Python_urllib$ git status
    位于分支 master
    无文件要提交,干净的工作区

      

  11. git status -s
    # 再次修改Python_urllib.py文件,在其最后加上一条语句
    # print 'made by evilxr.'
    # 然后git status -s
    tp@Evilxr:/tmp/Python_urllib$ git status -s
    M Python_urllib.py

      

  12. git diff  查看文件差别
    tp@Evilxr:/tmp/Python_urllib$ git diff
    diff --git a/Python_urllib.py b/Python_urllib.py
    index 806e0fa..b99aadb 100644
    --- a/Python_urllib.py
    +++ b/Python_urllib.py
    @@ -18,3 +18,4 @@ url_list = ["http://www.sina.com.cn/",
    for url in url_list:
    print url, automatic_detect(url) +print 'made by evilxr.'

      

    tp@Evilxr:/tmp/Python_urllib$ git diff --staged
    diff --git a/Python_urllib.py b/Python_urllib.py
    index 806e0fa..b99aadb 100644
    --- a/Python_urllib.py
    +++ b/Python_urllib.py
    @@ -18,3 +18,4 @@ url_list = ["http://www.sina.com.cn/",
    for url in url_list:
    print url, automatic_detect(url) +print 'made by evilxr.'

      

    tp@Evilxr:/tmp/Python_urllib$ git diff HEAD
    diff --git a/Python_urllib.py b/Python_urllib.py
    index 806e0fa..b99aadb 100644
    --- a/Python_urllib.py
    +++ b/Python_urllib.py
    @@ -18,3 +18,4 @@ url_list = ["http://www.sina.com.cn/",
    for url in url_list:
    print url, automatic_detect(url) +print 'made by evilxr.'

      

    # 将不同的地方显示为一行,以不同颜色为对比
    git diff --color-words
  13. git reset 撤销操作
    tp@Evilxr:/tmp/Python_urllib$ git diff
    tp@Evilxr:/tmp/Python_urllib$ git status -s
    M Python_urllib.py
    tp@Evilxr:/tmp/Python_urllib$ git reset Python_urllib.py
    重置后撤出暂存区的变更:
    M Python_urllib.py
    tp@Evilxr:/tmp/Python_urllib$ git status -s
    M Python_urllib.py
    tp@Evilxr:/tmp/Python_urllib$

      

  14. git checkout
    tp@Evilxr:/tmp/Python_urllib$ git status
    位于分支 master
    尚未暂存以备提交的变更:
    (使用 "git add <file>..." 更新要提交的内容)
    (使用 "git checkout -- <file>..." 丢弃工作区的改动) 修改: Python_urllib.py 修改尚未加入提交(使用 "git add" 和/或 "git commit -a")
    tp@Evilxr:/tmp/Python_urllib$ git checkout Python_urllib.py
    tp@Evilxr:/tmp/Python_urllib$ git status
    位于分支 master
    无文件要提交,干净的工作区
    tp@Evilxr:/tmp/Python_urllib$

      还可以用git checkout HEAD filename从

  15. git rm filename    撤销
    tp@Evilxr:/tmp/Python_urllib$ ls
    notuse.py Python_urllib.py
    tp@Evilxr:/tmp/Python_urllib$ git rm notuse.py
    rm 'notuse.py'
    tp@Evilxr:/tmp/Python_urllib$ git status
    位于分支 master
    要提交的变更:
    (使用 "git reset HEAD <file>..." 撤出暂存区) 删除: notuse.py tp@Evilxr:/tmp/Python_urllib$ git status -s
    D notuse.py
    tp@Evilxr:/tmp/Python_urllib$ git commit -m 'deletd old.py'
    [master 4e0a415] deletd old.py
    1 file changed, 7 deletions(-)
    delete mode 100644 notuse.py
    tp@Evilxr:/tmp/Python_urllib$ git status
    位于分支 master
    无文件要提交,干净的工作区

      

  16. git pull
    从其他的版本库(既可以是远程的也可以是本地的)将代码更新到本地,例如:'git pull origin master'就是将origin这个版本库的代码更新到本地的master主枝,该功能类似于SVN的update
    
  17. git新建分支并切换到该分支
    git checkout -b now-function
    
  18. git合并分支,当需要在现有系统上添加一个新功能时,往往另外开一个分支来弄,

     比如,如果要将开发中的分支(test),合并到稳定分支(master),
    首先切换的master分支:git checkout master
    然后执行合并操作:git merge test
    如果有冲突,会提示你,调用git status查看冲突文件。
    解决冲突,然后调用git add或git rm将解决后的文件暂存。
    所有冲突解决后,git commit 提交更改。
  19. 修改commit最后一次提交内容,加入大段注释
     git commit --amend
    
  20. git查看某文件修改历史
    1.切换到目录
    2.git log --pretty=oneline filename
    #you will see
    test8b43a808cfe86fc90dde852c4a49e28f4ca6
    testa2033c785154f2400b179a15ef090f5a9cb6
    test6e8eb956dc41a1db54080a6bca2adc348ed8
    testd5e0306088d9bc0217c2ece4ced4e3870db9
    test72f220e19bde8eb87be3076a383cea8951d7
    test46632b93a86ddde029594e1d1a6f9b82932d
    test3f15f46105c1e61107068cef987e6838e5e0
    testc6d31cfbbf65c53e24571cd67057c66ad6ce
    test54827582044a3e8b1d6165b5f82fce0d51ac
    test4fc6ecaa3b519cb0f781ad4fbbe340b26bec
    test0d09df4653a800a0f4cedbcab1e3d2702000 3.git show test4fc6ecaa3b519cb0f781ad4fbbe340b26bec
  21. 查看某文件每一行最后修改日期和修改者信息

    git blame filename
    

Git连接Github的更多相关文章

  1. WebStorm和sublime上使用git连接github(转)

    WebStorm使用git连接github的方法: 用webstorm上传代码时,首先要先下载git,网址一搜就可以搜到,安装git,并且把ssh配置到github上.然后开始配置webstorm,打 ...

  2. Git连接github以及gitee等使用教程

    Git连接github以及gitee等使用教程 一.初始化本次仓库 在想要放置仓库的文件夹出git bash输入命令 git init 二.生成ssh 在github或者gitee注册账户, 在本地生 ...

  3. 转:sublime上使用git连接github

    "工欲善其事,必先利其器." 这是古人的教诲,也是一个高效率的工程师需要遵循的法则之一.从大学开始写Java使用了JBuilder,Eclipse,后来写PHP用了Zend,写Ja ...

  4. vscode git连接github

    上一篇文章中介绍了vscode中git的简单使用方法vscode git的简单使用 上次只讲到了本地库的创建,这次说明下怎么push到github上 首先需要有一个github的账号  github官 ...

  5. git 连接github的配置

    这段时间要先在git上开发,上传代码到github上,所以首先需配置本地的git和github. 这几篇文章都不错,可以参考一下,大体的配置都很清楚. 1:https://blog.csdn.net/ ...

  6. OS X Git连接github

    1. 运行到.local 2. cd ~/.ssh查看文件是否存在 3. ssh-keygen(创建public & private key) 4. 或者运行如下命令:cd ~/.ssh &a ...

  7. Git连接GitHub仓库详解

    [Annotation]本文将从标题八开始,因为前七个标题是关于Git的基本操作,如果对Git的基本操作不了解的话,可以点击下方链接先看一下Git怎么使用. 关于Git的详细使用 八:创建SSH Ke ...

  8. Git 连接github

    大概如下: 详细如下:如果使用本文命令,请仔细选择,因为添加一些相关命令以供参考. 1 本地仓库 1.1 创建git 仓库 git init # 初始化本地仓库 git --version # 查看G ...

  9. mac下git连接github远程仓库

    git配置 一.安装git 官方网站下载安装,如果有安装homebrew,在终端输入brew install git,安装后的位置在/Users/计算机用户名目录下安装完成后,在终端输入git --v ...

  10. 使用乌龟Git连接github

    之前自己是在Gitee+乌龟Git来进行管理项目,因为特殊的需求,需要再Github+乌龟Git来进行管理项目,这盘博客主要讲解的就是这个. 安装环境 Git 安装参考链接:https://www.c ...

随机推荐

  1. Android 应用按两下返回键退出应用程序

    在android应用开发中,有时候应用会用到按两下返回键退出应用的功能,今天介绍一下这个功能,直接上代码: @Override public boolean dispatchKeyEvent(KeyE ...

  2. Swift 实现下拉刷新 JxbRefresh

    JxbRefresh 是采用Swift 实现的 iOS 下拉刷新. 正常下拉刷新: 1 2 3 4 5 self.taleView.addPullRefresh({ [weak self] in    ...

  3. 团队开发——冲刺1.a

    冲刺阶段一(第一天) 1.今天准备做什么? 在了解C#的基础上,深入熟悉Windows窗体应用程序,熟练掌握基本功能. 2.明天做什么:简单设计界面.

  4. IOS9适配 MARK

    最近做了iOS 9的适配,程序出现大量警告也做了些处理,写出来分先给大家. 一.iOS 9适配 问题一: <Error>: CGContextSaveGState: invalid con ...

  5. 算法题----称硬币: 2n(并不要求n是2的幂次方)个硬币,有两个硬币重量为m+1, m-1, 其余都是m 分治 O(lgn)找出假币

    Description: 有2n个硬币和一个天平,其中有一个质量是m+1, 另一个硬币质量为m-1, 其余的硬币质量都是m. 要求:O(lgn)时间找出两枚假币 注意: n不一定是2的幂次方 算法1: ...

  6. IOS 作业项目(4)步步完成 画图 程序(中)

    一,承接上文,继续本文  [UIButton buttonWithType:UIButtonTypeRoundedRect]; 如此声明的按钮才会有点击闪动的效果!如果直接frame方式声明就不会有. ...

  7. Oracle修改字段类型方法总结(转)

    有一个表名为tb,字段段名为name,数据类型nchar(20). 1.假设字段数据为空,则不管改为什么字段类型,可以直接执行:alter table tb modify (name nvarchar ...

  8. HDU 5040

    http://acm.hdu.edu.cn/showproblem.php?pid=5040 题意比较难懂,有摄像头的位置是可以走的,每回合开始看做人先走摄像头再转,也就是说如果你这回合走之前没有摄像 ...

  9. Magento架构师的笔记-----Magento显示当前目录的父分类和子分类的分类名

    在Magento目录的分类页面里,希望在左侧导航获取到父分类和子分类,可以用以下方法:打开app/your_package/your_themes/template/catalog/navigatio ...

  10. 第一个Sprint冲刺第六天

    讨论成员:邵家文.李新.朱浩龙.陈俊金 讨论问题:解决编写代码的问题 讨论地点:宿舍 进展:已开始对代码的编写