安装设置 git
下载最新版本的git
http://git-scm.com/downloads
当你安装完成git的时候,你需要简单的配置一下,打开终端:
简易的命令行入门教程:
Git 全局设置:
git config --global user.name "xxxxx"
git config --global user.email "xxxxxx@xxx.com"
创建 git 仓库:
mkdir no-temp
cd no-temp
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://gitee.com/xxxx/xxxx.git
git push -u origin master
已有仓库?
cd existing_git_repo
git remote add origin https://gitee.com/deveuper/no-temp.git
git push -u origin master
用户名
第一步,你需要告诉git你的名字,这个名字会出现在你的提交记录中。
git config --global user.name "你的名字"
然后是你的Email,同样,这个Email也会出现在你的提交记录中,请尽量保持此Email和您的码云的注册Email一致。
git config --global user.email "你的Email"
init初始化
git init
Clone 、Pull、Push
Clone 项目
git clone http://gitee.com/xxxxxx/xxxxxx.git
Checkout 创建特性分支
git checkout -b $feature_name
Commit 写代码,提交变更
git commit -am "My feature is ready"
Push 将你的提交推送
git push origin $feature_name
Pull 拉取远程库到本地
git pull <别名> <分支名>:把远程库的修改拉取到本地
eg:
git pull origin master
Reset 版本控制
git reset --hard 简洁/完整哈希索引值:回到指定哈希值所对应的版本
git reset --hard HEAD:强制工作区、暂存区、本地库为当前HEAD指针所在的版本
git reset --hard HEAD^:后退一个版本
tip:一个^表示回退一个版本
git reset --hard HEAD~1:后退一个版本
tip:波浪线~后面的数字表示后退几个版本
Diff 比较差异
显示暂存区和工作区的差异
git diff
显示暂存区和上一个commit的差异
git diff --cached [file]