码迷,mamicode.com
首页 > 其他好文 > 详细

git的使用总结

时间:2015-06-26 13:25:33      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

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:

.git\info\exclude

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 Files\Git\share\vim

添加如下设置

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 Files\Git\etc\git-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

参考:

git的使用总结

标签:

原文地址:http://www.cnblogs.com/xilifeng/p/4601997.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!