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),具有以下的特点: 分布式版本控制: 多个开发人员协调工作: 有效监听谁做的修改: 本地及远程 ...
随机推荐
- Maven的国内镜像(解决jar下载过慢)
Maven简介 maven作为一个项目管理工具确实非常好用,结果在使用时候,你会发现下载jar速度不如自己在网上下载.之前oschina的中央仓库可用,现在oschina的maven服务器关了,只能拿 ...
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
- bzoj千题计划216:bzoj1499: [NOI2005]瑰丽华尔兹
http://www.lydsy.com/JudgeOnline/problem.php?id=1499 预处理从每个位置向每个方向最多能走几步 dp[k][i][j] 第k个时间段后,钢琴到位置(i ...
- 一个由SEO优化展开的meta标签大讲解
您的个人网站即使做得再精彩,在“浩瀚如海”的网络空间中,也如一叶扁舟不易为人发现,如何推广个人网站,人们首先想到的方法无外乎以下几种: ● 在搜索引擎中登录自己的个人网站 ● 在知名网站加入你个人网站 ...
- HTML5 JavaScript实现图片文字识别与提取
8月底的时候,@阿里巴巴 推出了一款名为“拯救斯诺克”的闯关游戏,作为前端校园招聘的热身,做的相当不错,让我非常喜欢.后来又传出了一条消息,阿里推出了A-star(阿里星)计划,入职阿里的技术培训生, ...
- composer "Failed to decode zlib stream"
dockerFile 中安装composer.... RUN curl -s -f -L -o /tmp/installer.php https://raw.githubusercontent.com ...
- Jenkins mac pkg安装 后默认配置文件/启动路径
自启动文件路径 /Library/LaunchDaemons/org.jenkins-ci.plist jenkins.war 执行文件路径 /Applications/Jenkins/jenkins ...
- 第10月第6天 lua 闭包
1. static int mytest(lua_State *L) { //获取上值 )); printf("%d\n", upv); upv += ; lua_pushinte ...
- kali更新失败
今天更新kali时失败,出现如下问题: root@kali:~# apt-get update Get: http://mirrors.aliyun.com/kali kali-rolling InR ...
- Dream------Hbase--0.94版本和0.98/1.X版本api变动
Dream------Hbase--0.94版本和0.98/1.X版本api变动 网上好多说getQualifier.getValue.getRow被..Array代替了,其实并不是的. 1. Int ...