Git简单教程
该笔记总结廖雪峰Git教程, 参考网站: https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000
一. 简介
二. Git install
$ git config --global user.name "Your name" $ git config --global user.email "email@example.com"
三. 创建repository
$ mkdir git #创建git目录 $ cd git $ git init #创建repository
通过以下命令可以看到git目录中有隐藏的.git文件
$ ls -a
把文件添加入repository
# Snapshots the file in preparation for versioning $ git add [file] # Records file snapshots permanently in version history $ git commit -m "[descriptive message]"
四. 版本控制
一些简单的命令:
# Lists all new or modified files to be committed $ git status # Shows file differences not yet staged $ git diff # Lists version history for the current branch $ git log $ git log --pretty=oneline
版本回退:
$ git reset --hard HEAD^
版本回退后, 新版本会消失, 如果想恢复至新版本必须知道新版本的ID号, 之前 git log 会打印出新版本的ID号.
# 版本号没必要写全,前几位就可以了,Git会自动去找。当然也不能只写前一两位,因为Git可能会找到多个版本号,就无法确定是哪一个了。 $ git reset --hard ID
Git概念理解:
撤销修改:
$ git checkout -- fileName
二: 文件已经 git add, 提交至stage中, 此时需要首先将文件从stage中撤回至work directory中, r然后成为一的情况.
$ git reset HEAD fileName
删除文件:
# Deletes the file from the working directory and stages the deletion $ git rm [file] $ git commit -m "message"
如果误删想要回复文件, 使用如下命令:
$ git checkout -- [file]
五. 远程仓库
$ ssh-keygen -t rsa -C "youremail@example.com"
如果一切顺利的话,可以在用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人。
$ git remote add origin git@github.com:[github_ID_name]/[repository_name].git
添加后,远程库的名字就是origin,这是Git默认的叫法,也可以改成别的,但是origin这个名字一看就知道是远程库。
$ git push -u origin master
从现在起,只要本地作了提交,就可以通过命令, 把本地master分支的最新修改推送至GitHub:
$ git push origin master
第一次链接时会出现警告, 该警告关于SSH警告, 直接Yes即可.
删除远程库内容:
$ git rm [filename] #删除本地文件 $ git add . $ git commit -m "clear" $ git push origin master
$ git clone git@github.com:***/***.git
分支管理
简单的命令:
#表示创建并切换 $ git checkout -b dev #or $ git branch dev $ git checkout dev # Lists all local branches in the current repository $ git branch # Switches to the specified branch and updates the working directory $ git checkout master # Combines the specified branch’s history into the current branch $ git merge dev # Deletes the specified branch $ git branch -d [branch-name] # 分支合并图 $ git log --graph # 禁用Fast forward模式, merge时生成新的commit $ git merge --no-ff -m "merge with no-ff" [branch-name] # Temporarily stores all modified tracked files $ git stash # Lists all stashed changesets $ git stash list # 强行删除 $ git branch -D feature-vulcan # 查看远程库的信息, 加-v会将信息详细化 $ git remote
合并方式:
分支策略:
Bug分支:
多人合作:
七. 标签管理
简单命令:
# 打一个新标签, 加ID号可为以前的增加标签 $ git tag <name> [commit ID] # 查看标签 $ git tag # 查看标签信息 $ git show <tagname> # 删除标签 $ git tag -d <tagname> # 推送某个标签到远程,使用命令 $ git push origin <tagname> # 一次性推送全部尚未推送到远程的本地标签 $ git push origin --tags # 删除远程标签 $ git tag -d <tagname> $ git push origin :refs/tags/<tagname> 转载清注明出处, O(∩_∩)O谢谢!
Git简单教程的更多相关文章
- git 简单教程更新
0.初始化 $ git config --global user.name "xxx" $ git config --global user.email "xxx@gma ...
- Git和Github简单教程
原文链接:Git和Github简单教程 网络上关于Git和GitHub的教程不少,但是这些教程有的命令太少不够用,有的命令太多,使得初期学习的时候需要额外花不少时间在一些当前用不到的命令上. 这篇文章 ...
- Git和Github简单教程(收藏)
原文链接:Git和Github简单教程 目录: 零.Git是什么 一.Git的主要功能:版本控制 二.概览 三.Git for Windows软件安装 四.本地Git的使用 五.Github与Git的 ...
- Git和Github简单教程【转】
转自:https://www.cnblogs.com/schaepher/p/5561193.html#clone 原文链接:Git和Github简单教程 网络上关于Git和GitHub的教程不少,但 ...
- 转:Git和Github简单教程
转自:https://www.cnblogs.com/schaepher/p/5561193.html Git和Github简单教程 原文链接:Git和Github简单教程 网络上关于Git和Gi ...
- Git简易教程-安装及简单使用
Git是一种版本控制器,在项目开发中可以用来托管代码 一.下载安装Git 1. Git下载 地址:https://git-scm.com/download/win 2. 安装 检验是否安装成功 电脑桌 ...
- Git使用教程【转】
Git使用教程 一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是 ...
- Git 使用教程
Git 使用教程 更详细请参考:廖雪峰的官方网站 - Git教程 1. 安装Git客户端软件 Git for Windows http://msysgit.github.io/ 2. 创建版本库 两点 ...
- Git版本控制教程
Git 版本控制入门 不了解Git请查看权威Git书籍 ProGit(中文版). 一份很好的 Git 入门教程,点击这里查看. Git客户端下载地址: 官方Git - TortoiseGit - So ...
随机推荐
- python 大小写转换方法(全)
http://blog.csdn.net/liuxincumt/article/details/7945337 python大小写转换(全)
- 通俗易懂,什么是.NET?什么是.NET Framework?什么是.NET Core? .Net Web开发技术栈
通俗易懂,什么是.NET?什么是.NET Framework?什么是.NET Core? 什么是.NET?什么是.NET Framework?本文将从上往下,循序渐进的介绍一系列相关.NET的概念 ...
- 开关电路_MOS和三极管
https://blog.csdn.net/acelit/article/details/70171312 绍过一般的电源开关电路,控制电源的目的是省电,控制静态电流.不过以下的电路存在着几个缺点: ...
- OpenCV for Python 学习笔记 一
本人的学习笔记主要记录的是学习opencv-python-tutorials这本书中的笔记 今天晚上简单学习OpenCV for Python如何绘图,主要用了这几个函数(这几个函数可在:http:/ ...
- AQS实现公平锁和非公平锁
https://www.cnblogs.com/chengdabelief/p/7493200.html AQS(AbstractQueuedSynchronizer类)是一个用来构建锁和同步器的框架 ...
- linux上查看系统内核版本命令(转载)
uname -a uname -r 查看发行版本信息: 在RedHat系统里,存在一个/etc/redhat-release文件,里面保存了发行版的版本信息 $cat /etc/redhat-rele ...
- EasyDarwin开源流媒体云平台设计与实现(分布式+负载均衡)
前言 早在2013年我就设计了一套架构非常简单的分布式流媒体服务器平台<基于Darwin实现的分布式流媒体直播服务器系统>,当时的考虑如今看来有诸多的细节点没有考虑到:1.CMS是单点部署 ...
- BNUOJ 34978 汉诺塔 (概率dp)
题目分析:对于 i 个盘 , 须要移动多少步,取决于最大的盘子在哪个杆上.在C杆上,则最大的盘不须要移动,由于初始状态一定是满足盘由下到上盘子依次变小的,仅仅须要移动i - 1个盘.假设在A杆上,则首 ...
- Struts2页面遍历
<s:iterator />可以遍历 数据栈里面的任何数组,集合等等 在使用这个标签的时候有三个属性值得我们关注 1. value属性:可选的属性,value属性是指一个被迭代的 ...
- 牛客练习赛14 D 比较月亮大小 【水】
链接:https://www.nowcoder.com/acm/contest/82/D 来源:牛客网 比较月亮大小 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其 ...