zoukankan      html  css  js  c++  java
  • git使用技巧

    git使用技巧

    git使用技巧

    文章概览:

    • windows下git使用
    • vim编码设置
    • git ls显示中文乱码问题

    windows下git使用

    从网盘下载安装即可

    • 使用git连接github

    1)生成本机的密钥

    ssh-keygen -C 'urmyfaith.qq.com' -t rsa

    2)将生存的密钥添加到github网站中

    a)登陆https://github.com/settings/ssh

    b)Add an SSH Key

    3)测试是否可以登录github使用,添加用户名和邮箱

    $ ssh -T git@github.com
    $ git config --global user.email "urmyfaith@qq.com"
    
    $ git config --global user.name "urmyfaith"
    $ git config --global push.default matching
    

    4)本地git初始化

    $    git init  

    5) 拉取服务器项目

    $ git pull  https://github.com/urmyfaith/NotesOfDjangoBook.git 
    或者
    $ git pull git@github.com:urmyfaith/NotesOfDjangoBook.git

    6) 修改,添加文件,提交

    git add filname_here
    
    git commit -m "notes_here"

    7) 提交更改到服务器

    git remote add origin https://github.com/urmyfaith/NotesOfDjangoBook
    # also:
    # git remote add origin https://github.com/urmyfaith/NotesOfDjangoBook.git
    # git remote add origin git@github.com:urmyfaith/NotesOfDjangoBook.git
    git push -u origin
    
    • 提交时候密码的问题:

    如果不想每次提交都输入密码,可以更改“.git/config”文件中的url值格式为:

     url = git@github.com:[user_name]/[project_name].git
    [core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
        hideDotFiles = dotGitOnly
    [remote "origin"]
        url = git@github.com:urmyfaith/NotesOfDjangoBook.git
        fetch = +refs/heads/*:refs/remotes/origin/*
    [branch "master"]
        remote = origin
        merge = refs/heads/master

    git ignore file

    To ignore file,edit:

    .gitinfoexclude

    add the filetype you want to igonre to commit .
    eg:

    *.md~
    

    git 打tag

    显示历史提交

    git log --pretty=oneline --abbrev-commit

    给某个提交打tag

    git tag v0.9 4224935

    更多参考廖学峰-git-tag

    你可以使用 git tag 命令来添加新标签
    
    git tag -a v1.0 -m 'version 1.0'
    
    可以使用 git push 命令来将标签推送到远程仓库
    
    git push origin v1.0:v1.0

    vim编码设置

    (显示中文乱码问题,最后一行解决)
    vimrc文件位置:

    C:Program FilesGitsharevim

    添加如下设置

    set nocompatible
    set number
    filetype on
    set history=1000
    set background=dark
    syntax on
    set autoindent
    set smartindent
    set tabstop=4
    set shiftwidth=4
    set showmatch
    set guioptions-=T
    set vb t_vb=
    set ruler
    set nohls
    set incsearch
    if has("vms")
    set nobackup
    else
    set backup
    endif
    set fileencodings=utf-8,gbk

    git ls显示中文乱码问题

    编辑

    C:Program FilesGitetcgit-completion.bash

    添加:

    alias ls="ls --show-control-chars"

    git view history

    git log --pretty=oneline

    查看某个文件的版本历史

    git log --follow -p file

    git rm file git删除文件

    移动文件,然后从git里移除文件,再添加,最后提交。

    mv file_form file_path_to
    git rm file_from
    git add file_path_to_full_name.
    git commit -c "move file"

    git 放弃本地修改

    git checkout . 搜索#本地所有修改的。没有的提交的,都返回到原来的状态
    git stash #把所有没有提交的修改暂存到stash里面。可用git stash pop回复。
    git reset --hard HASH #返回到某个节点,不保留修改。
    git reset --soft HASH #返回到某个节点。保留修改
    使用命令:
    
    git reset --hard ORIGIN/BRANCH
    
    比如master分支:
    
    git reset --hard origin/master

    git commit –amend

    修改刚才提交的commit信息

    git diff

    HEAD commit 版本
    Index staged版本

    git diff
    git diff –cached (add之后的不同)
    git diff –staged (add之后的不同)

    git diff HEAD (commit之后的修改本地后的不同)
    git diff HEAD^ HEAD (最后两次commit的不同)

    加快git pull的速度

    • 先输入命令ssh -N git@gitcafe.com保持连接
    • 然后新建窗口git pull/push
    • 测试时间可以使用
    x:panda zx$ time git pull
    Already up-to-date.
    real    0m1.043s
    user    0m0.058s
    sys 0m0.054s

    参考:

  • 相关阅读:
    新四军的7个师,以及粟裕的山头背景
    基于easyui的webform扩展
    Mac入门(一)基本用法
    HtmlAgilityPack实战代码
    摄像头、麦克风、扬声器测试程序
    依赖注入(IOC)
    类型
    C#私房菜[二][提供编程效率的技巧]
    Fluent Nhibernate code frist简单配置
    Ubuntu环境搭建系列—JavaEE篇
  • 原文地址:https://www.cnblogs.com/xilifeng/p/4601997.html
Copyright © 2011-2022 走看看