002.Git日常基础使用
一 获取git仓库
1.1 初始化仓库
[root@git ~]# cd /mystudy/
[root@git mystudy]# git init
[root@git mystudy]# git remote add origin https://gitee.com/imxhy/mystudy
1.2 克隆现有仓库
[root@git mystudy]# git clone https://gitee.com/xiyouMc/pornhubbot
[root@git mystudy]# git clone https://gitee.com/xiyouMc/pornhubbot mystudy #clone项目,同时本地创建mystudy目录。
二 仓库相关
2.1 检查状态

[root@git mystudy]# echo 'My Project' > README
[root@git mystudy]# git status

2.2 跟踪新文件
[root@git mystudy]# git add README
[root@git mystudy]# git status

2.3 暂存已修改文件
[root@git mystudy]# echo "This is my test file">>README
[root@git mystudy]# git status

[root@git mystudy]# git add README #添加至暂存区

2.4 状态简览
[root@git mystudy]# git status -s

2.5 忽略文件
[root@git mystudy]# cat .gitignore
- 所有空行或者以 # 开头的行都会被 Git 忽略。
- 可以使用标准的 glob 模式匹配,即简化正则表达式。
- 匹配模式可以以(/)开头防止递归。
- 匹配模式可以以(/)结尾指定目录。
- 要忽略指定模式以外的文件或目录,可以在模式前加上惊叹号(!)取反。
- 星号(*):匹配零个或多个任意字符;
- [abc] :匹配任何一个列在方括号中的字符;
- 问号(?):只匹配一个任意字符;
- [0-9]:匹配0至9范围内的任意数字;
- **: 使用两个星号(*) 表示匹配任意中间目录,比如`a/**/z` 可以匹配 a/z, a/b/z 或 `a/b/c/z`等。
2.6 查看已暂存和未暂存修改
[root@git mystudy]# echo "Hello" > README
[root@git mystudy]# echo "Hello" > CONTRIBUTING.md
[root@git mystudy]# git add README
[root@git mystudy]# git status

[root@git mystudy]# git diff #通过git diff查看具体做了哪些修改。

2.7 提交更新
[root@git mystudy]# git status
[root@git mystudy]# git commit

2.8 跳过暂存区
2.9 移除文件
- 正常git删除操作:即从git移除同时从工作目录删除使用git rm。
- rm删除后的git移除:rm文件后,再使用git rm [文件]。
- 放入暂存区之后rm删除文件的git移除:git rm -f [文件]。
- 从git仓库删除但保留在本地目录:git rm --cached [文件]。
2.10 移动文件
[root@git mystudy]# git mv README README.md
$ mv README README.md
$ git rm README
$ git add README.md
三 查看提交历史
[root@git mystudy]# git log
四 撤销操作
4.1 重新提交
[root@git mystudy]# git commit -m 'first commit'
[root@git mystudy]# echo "This is my test 3 file" > README3.md
[root@git mystudy]# git add README3.md
[root@git mystudy]# git commit --amend -m 'second commit'
4.2 取消暂存区文件
[root@git mystudy]# echo "This is my test 4 file" > README4.md
[root@git mystudy]# echo "This is my test 5 file" > README5.md
[root@git mystudy]# git add *
[root@git mystudy]# git status
[root@git mystudy]# git reset HEAD README5.md #从暂存区取消特定文件

4.3 撤销对文件的修改
[root@git mystudy]# echo "version 1.1" > version.md
[root@git mystudy]# git add version.md
[root@git mystudy]# git commit -m 'version commit'
[root@git mystudy]# echo "version 2.2" > version.md
[root@git mystudy]# git status

[root@git mystudy]# cat version.md
version 2.2
[root@git mystudy]# git checkout -- version.md
[root@git mystudy]# git status

五 远程仓库的使用
5.1 查看远程仓库
[root@git mystudy]# git remote -v

5.2 添加远程仓库
[root@git mystudy]# mkdir /mystudy2
[root@git mystudy]# cd /mystudy2
[root@git mystudy2]# git init
[root@git mystudy2]# git remote add mystudy2 https://gitee.com/imxhy/mystudy2
[root@git mystudy2]# git fetch mystudy2 #使用别名拉取仓库存在但本地没有的文件
5.3 从仓库抓取与拉取
5.4 推送至远程仓库
[root@git mystudy2]# git push mystudy2 mystudy2/master

5.5 查看远程仓库
[root@git mystudy2]# git remote show mystudy2

5.6 远程仓库移除与重命名
[root@git mystudy2]# git remote rename mystudy2 study2
[root@git mystudy2]# git remote
study2
[root@git mystudy2]# git remote rm study2
[root@git mystudy2]# git remote
六 git别名
6.1 设置别名
[root@git mystudy]# git config --global alias.co checkout
[root@git mystudy]# git config --global alias.br branch
[root@git mystudy]# git config --global alias.ci commit
[root@git mystudy]# git config --global alias.st status
002.Git日常基础使用的更多相关文章
- 【GoLang】GO语言系列--002.GO语言基础
002.GO语言基础 1 参考资料 1.1 http://www.cnblogs.com/vimsk/archive/2012/11/03/2736179.html 1.2 https://githu ...
- git学习基础教程
分享一个git学习基础教程 http://pan.baidu.com/s/1o6ugkGE 具体在网盘里面的内容..需要的学习可以直接下.
- Git入门基础详情教程
前言 写了一篇文章<一篇文章了解Github和Git教程>还觉得不错,继续写了<为了Github默默付出,我想了解你>,那么继续写Git 基础知识. Git 官网:https: ...
- Git使用基础篇
Git使用基础篇 前言 Git是一个分布式的版本控制工具,本篇文章从介绍Git开始,重点在于介绍Git的基本命令和使用技巧,让你尝试使用Git的同时,体验到原来一个版 本控制工具可以对开发产生如此之多 ...
- Git使用基础篇(zz)
Git使用基础篇 您的评价: 收藏该经验 Git是一个分布式的版本控制工具,本篇文章从介绍Git开始,重点在于介绍Git的基本命令和使用技巧,让你尝试使用Git的同时,体 ...
- Mac下Git的基础操作
目前最火的版本控制软件是Git了吧,今天简单梳理一下Mac下Git的基础操作~~ 一.什么是Git Git是一个分布式代码管理工具,用于敏捷的处理或大或小的项目,类似的工具还有svn. 基于Git的快 ...
- git 日常使用从入门到真香
目录 git 日常使用从入门到真香 一.Git简介 二.Git常用命令 三.git操作流程 四.报错处理 git 日常使用从入门到真香 一.Git简介 Git是一个开源的分布式版本控制系统,可以有效. ...
- Mac 下 Git 的基础命令行操作
Mac 下 Git 的基础命令行操作 sudo apt-get install git-core //安装Git 用户配置 git config --global user.name "Yo ...
- Git及基础命令的介绍以及如何向本地仓库添加文件
在介绍Git的使用之前,我们得要先来了解一下Git.那么什么是Git? Git是一个版本管理工具(VCS),具有以下的特点: 分布式版本控制: 多个开发人员协调工作: 有效监听谁做的修改: 本地及远程 ...
随机推荐
- AC自动机——多个kmp匹配
(并不能自动AC) 介绍: Aho-Corasick automaton,最经典的处理多个模式串的匹配问题. 是kmp和字典树的结合. 精髓与灵魂: ①利用trie处理多个模式串 ②引入fail指针. ...
- harbor高可用集群配置
目录 说明 双主复制 主从同步 双主复制说明 多harbor实例共享后端存储 方案说明 环境说明 配置说明 安装redis和mysql 导入registry数据库 配置harbor 挂载nfs目录 修 ...
- Hadoop生态圈-Kafka的本地模式部署
Hadoop生态圈-Kafka的本地模式部署 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Kafka简介 1>.什么是JMS 答:在Java中有一个角消息系统的东西,我 ...
- GUI起头
package com.lovo.frame; import java.awt.Color;import java.awt.Container;import java.awt.Font;import ...
- OpenStack中MySQL高可用配置
采用Heartbeat+DRBD+mysql高可用方案,配置两个节点的高可用集群 l 配置各节点互相解析 gb07 gb06 l 配置各节点时间同步 gb07 [root@gb07 ~]# ntp ...
- bzoj千题计划269:bzoj2655: calc (拉格朗日插值)
http://www.lydsy.com/JudgeOnline/problem.php?id=2655 f[i][j] 表示[1,i]里选严格递增的j个数,序列值之和 那么ans=f[A][n] * ...
- 新建 Spring Mvc Web + Maven 的 maven 错误 (二)
新建项目后,可能由于哪边配置不正确,或也可能是编码问题,就有可能在创建初始就可能发生错误: 这是 pom.xml 中提示的错误,有的人说要删除 maven 的本地仓库位置:c:\用户[Users]\A ...
- J2EE的体系结构是指什么?
J2EE 即Java2平台企业版,它提供了基于组件的方式来设计.开发.组装和部署企业应用.J2EE使用多层分布式的应用模型,这个多层通常通过三层或四层来实现: 客户层,运行在客户计算机上的组件. We ...
- 如何使用optipng压缩png图片
OptiPNG – Google推荐的png图片无损压缩工具下载及使用教程 2014年08月24日 实用软件 暂无评论 optipng png图片无损压缩工具介绍: optipng png图片无损压缩 ...
- 百度编辑器ueditor 字符限制
百度编辑器ueditor 字符限制 默认只能输入10000个字符 修改 ueditor.config.js // ,wordCount:true //是否开启字数统计 // ,maximumWords ...