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

git使用指南

时间:2017-02-24 12:53:14      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:git


为什么要使用GIt?

Git是目前世界上最先进的开源分布式版本管理工具,尤其在分支管理上表现突出,能够极为方便地解决开发中的版本问题。


Git如何使用?

工作区:当前目录下除.git外的目录和文件

版本库:当前路径下的.git目录

暂存区:版本库中等待提交的内容所在区域


git命令

基本命令
git init
在当前目录下创建一个版本库
git add file
将文件从工作区添加到暂存区
git commit -m "message"
将暂存区中的内容提交到版本库的当前分支
git status
查看git仓库当前状态
git diff file
查看文件修改内容
git diff HEAD -- file
查看工作区和仓库最新版的差别
git log [--graph][--pretty=oneline][--abbrev-commit]
查看历史commit日志,不能查看已删除的commit记录
git reset --hard HEAD~x
回到历史版本
git reflog
查看所有分支的所有操作(包括commit和reset)
git rest --hard commit_id
回到任意版本
git checkout -- file
丢弃工作区的修改
git rm file
删除文件
远程仓库
git remote add origin remote_address
关联远程git仓库
git push -u origin master
首次向远程仓库推送master分支所有内容
git push origin branch_name从本地推送分支
git pull
从远程抓取当前分支
git clone remote_address
将远程仓库克隆到本地
git checkout -b branch-name origin/branch_name
在本地创建和远程分支对应的分支(分支名称最好一致)
git branch --set-upstream branch_name origin/branch_name
建立本地分支和远程分支的关联
git remote -v查看远程库信息
分支管理
git branch branch_name
创建分支
git checkout branch_name
切换分支
git checkout -b branch_name
创建并切换分支
git branch
列出所有的分支
git merge [--abbrev-commit] [-m "message"] branch_name
合并指定分支到当前分支
git branch -d branch_name
删除分支
git branch -D branch_name
强行删除未合并的分支
git stash
存储当前工作区
git stash list
查看保存的工作区
git stash apply stash@{0}
恢复stash但不删除
git stash drop
删除stash
git stash pop
恢复stash同时删除stash
标签管理
git tag tag_name
在当前分支的最新commit上创建标签
git tag
查看所有标签
git tag tag_name commit_id
在当前分支的指定commit_id上创建标签
git tag -a tag_name -m "message" commit_id
在当前分支的指定commit_id上创建带说明的标签
git show tag_name
查看标签信息
git tag -d tag_name
删除标签
git tag push origin :refs/tags/tag_name
将本地删除的标签推送到远程(即删除远程标签)
git push origin tag_name
将标签推送到远程
git push origin --tags
推送所有未推送的本地标签到远程
其它
git check-ignore -v file
检查文件是否被忽略
git config --global alias.xx yy
配置yy命令的别名为xx
配置git lg为各种git log附加效果的别名:

git config --global alias.lg "log --color --graph --pretty=format:‘%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset‘ --abbrev-commit"


参考教程:

http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

本文出自 “Aioria” 博客,请务必保留此出处http://aioria.blog.51cto.com/12582050/1900764

git使用指南

标签:git

原文地址:http://aioria.blog.51cto.com/12582050/1900764

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