“每个理性的IT人士都置顶了吴柯的运维笔记”
Git是一款免费、开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。
Git是一个开源的分布式版本控制系统,可以有效、高速的处理从很小到非常大的项目版本管理。Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。
安装git:
# yum -y install git
生成ssh key,使用github邮箱:
# ssh-keygen -t rsa -C "xxx@xxx.com"
复制ssh key:
# cat ~/.ssh/id_rsa.pub
进入github--右上角--Settings--SSH and GPG keys--New SSH key--title随便填,Key粘贴复制的ssh key--Add SSH key
测试ssh key是否成功(successfully表示成功连接github):
# ssh -T git@github.com
Hi wuke! You've successfully authenticated, but GitHub does not provide shell access.
配置git用户名和邮箱:
# git config --global user.name "wuke"
# git config --global user.email "xxx@xxx.com"
新建一个repository,必须在github上创建
创建一个本地仓库(wuke为git用户名,hello-world为github上已有的仓库):
# git remote add origin git@github.com:wuke/hello-world
添加文件xx到本地仓库:“git add xxx”
自动判断添加哪些文件:“git add .”,然后把这个添加提交到本地的仓库
使用命令 ”git commit -m ”说明这次的提交
最后把本地仓库origin提交到远程的GitHub仓库,使用命令 “git push origin master”
备注:
git help #可查看git的常用命令
git config --global user.name "Your Name Here" #设置commit的署名
git config --global user.email "your_email@example.com" #设置commit的email
git config [--local|--global|--system] --list/-l #查看本地的global信息
git config [--local|--global|--system] --unset[-all] user.name #删除user.name信息。如果user.name对应多个值,可用unset-all来删除
git remote add XXX https://github.com/username/repo_name.git #设置github的连接
git clone git://github.com/your_account/aimed_repo.git #复制一个repo到本地
git remote -v #查看本地设置的url连接信息
git status #查看当前工作的
branch git branch #查看本地所有的
branch git branch -a #查看远程的所有分支
git branch -d branch_name #删除本地branch_name这一分支
git push origin --delete branch_name #删除名为branch_name的远程分支
git checkout branch_name #切换到名为branch_name的分支上
git chechout -b branch_name #在本地新建一个名为branch_nam的分支
git diff test_branch_name #查看当前branch与test_branch_name中代码的区别
git mv filename newfilename #文件重命名
git push XXX branch_name #上传指定的branch到远端
git pull #将远程上的版本与本地版本进行合并,相当于get fetch + git merge
git reset --hard #将刚才进行的git pull所进行的操作取消,恢复本地版本合并前的原貌