git使用总结

下载git,进入git命令行后配置用户名和邮箱

git config --global user.name cl90326

git config --global user.email 90cl@sina.com

创建版本库

cd f:/www/20171221

mkdir rrdai

git init

在rrdai文件夹下即为仓库区域,会自动生成一个.git文件夹

查看仓库状态

git status

git add index.php

把index.php提交到暂存区

git add .

把有变化的文件提交到暂存区

git commit -m "新建index.php"

把index.php提交到版本库

修改文件和添加文件的命令是一样的:

git add index.php

git commit -m "改了第2行"

删除文件

git rm index.php

git commit -m "删除index.php"

git在线仓库网址

国外:http://www.github.com

国内:http://git.oschina.net

在http://git.oschina.net上注册账号并创建项目

 

添加远程仓库别名

git remote add lianshou https://xxxxxxx.git

把本地代码推到远程仓库

git push lianshou master

master是分支名的意思

网站可根据需要添加项目角色

把远程库复制一份到本地

定位到要复制的目录

cd f:/

git clone https://xxxxxx.git

本地获得远程仓库最新代码

git pull lianshou master

lianshou是远程仓库别名

 

.git文件夹是暂存区+版本库

添加多个文件 git add <file1> <file2> #添加file1,file2

git add *.txt #添加当前目录下的.txt文档 

git add . #添加当前目录的所有变化

删除文件

git rm <file>

移动或改名 git mv 源文件 新文件

例 移动:git mv config.php ./inc/config.php

改名:git mv config.php config.inc.php

git log 查看项目的日志

git log <file> 查看某文件的日志

git log . 查看本目录的日志

git log --pretty=oneline   让日志单行显示.

git reflog 查看版本变化

git reset --hard 6207e59   利用版本号进行切换日志 

 

查看所有分支 git branch 

创建wechat分支 git branch wechat

切换到wechat分支 git checkout wechat

合并分支

在wechat分支进行修改后,切换到master分支

git merge wechat  则合并分支

删除分支

git branch -d wechat

git checkout -b dev # 创建dev分支并立即切换到dev分支 即起到git branch dev和git checkout dev的共同作用.

 

查看远程仓库:git remote

查看仓库地址:git remote -v 

删除远程库别名
命令:git remote remove <远程库名>

示例:git remote remove lianshou

添加远程库别名

git remote add <远程库名> <远程库地址> 

git remote add lianshou https://xxxxxxx.git

修改远程库别名

git remote rename <旧名称> <新名称> 

git remote rename lianshou xinlianshou

 

公钥登录

配置ssh格式的远程仓库地址

git remote add 远程仓库名 远程仓库地址 

git remote add lianshou git@xxxx.git

创建ssh key

ssh-keygen -t rsa -C "youremail@example.com"

一路回车

记事本打开.ssh/id_rsa.pub,复制公钥内容

登录网站,在对应位置填写保存公钥。

 

posted @ 2017-12-21 14:47  mayer326  阅读(168)  评论(0编辑  收藏  举报