git第一篇---基本命令
摘要:
(1)用git而不是svn。分布式而不是集中式
(2)名词解释
origin是父目录的意思,master是 一个特殊的分支而已。具体参看做最下边:
1.创建仓库
mkdir git
cd git ——创建/home/XXX/git空目录
2.通过git init命令把这个目录变成Git可以管理的仓库:
git init ——初始化Git仓库
3.用命令git add告诉Git,把文件添加到仓库(实际上就是把文件修改添加到暂存区):
git add filename
4.用命令git commit告诉Git,把文件提交到仓库(实际上就是把暂存区的所有内容提交到当前分支):
git commit -m "有意义的附加说明"
5.随时掌握工作区的状态
git status
6.查看文件被修改的内容
git diff
7.查看代码的历史版本号
git log
git log --pretty=oneline ——要求版本信息只能在一行中显示
8.HEAD指向的版本就是当前版本,因此,Git允许我们在版本的历史之间穿梭
git reset --hard commit_id
或git reset --hard HEAD^(HEAD^^等等)
9.查看命令历史,以便确定要回到未来的哪个版本
git reflog
10.弄明白Git的工作区(当前分区)和暂存区
11.理解Git是如何跟踪修改的,每次修改,如果不add到暂存区,那就不会加入到commit中
12.撤销修改
命令git checkout -- filename意思就是,把filename文件在工作区的修改全部撤销,这里有两种情况:
一种是filename自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;
一种是filename已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。
总之,就是让这个文件回到最近一次git commit或git add时的状态。
场景1:当你改乱了工作区某个文件的内容,想直接丢弃工作区的修改时,用命令git checkout -- file。
git checkout其实是用版本库里的版本替换工作区的版本,无论工作区是修改还是删除,都可以“一键还原”。
场景2:当你不但改乱了工作区某个文件的内容,还添加到了暂存区时,想丢弃修改,分两步,第一步用命令git reset HEAD file,就回到了场景1,第二步按场景1操作。
场景3:已经提交了不合适的修改到版本库时,想要撤销本次提交,版本回退,不过前提是没有推送到远程库。
13.删除文件
命令git rm用于删除一个文件。如果一个文件已经被提交到版本库,那么你永远不用担心误删,但是要小心,你只能恢复文件到最新版本,你会丢失最近一次提交后你修改的内容。
14.将本地仓库与github仓库关联起来
往里面添加文件:
1 touch README.md
2 git init
3 git add README.md
4 git commit -m "first commit"
5 git remote add origin git@github.com:sysublackbear/Learmgitfirst.git
6 git push -u origin master
将本地仓库同步github仓库:
1 git remote add origin git@github.com:sysublackbear/Learmgitfirst.git
2 git push -u origin master
然后,从现在起,只要本地作了提交,就可以通过命令:
1 git push origin master
把本地master分支的最新修改推送至GitHub
15.多人协作一个项目的时候,我们每个人可以通过从远程仓库克隆一份来作为己用。
1 git clone git@github,com:sysublackbear/XXXX.git
16.创建分支并且切换到分支
1 git checkout -b dev
2 Switched to a new branch 'dev'
等价于:
1 git branch dev
2 git checkout dev
3 Switched to branch 'dev'
查看分支:
1 git branch
将次分支合并到主分支上面:
1 git merge dev
删除分支:
1 git branch -d dev
2 Deleted branch dev (was fec145a).
17.解决冲突
当Git无法自动合并分支时,就必须首先解决冲突。解决冲突后,再提交,合并完成。
用git log --graph命令可以看到分支合并图。
18.Bug修复
修复bug时,我们会通过创建新的bug分支进行修复,然后合并,最后删除;
当手头工作没有完成时,先把工作现场git stash一下,然后去修复bug,修复后,再git stash pop,回到工作现场
19.开发新功能
开发一个新功能,最好新建一个分支;
如果要丢弃一个没有被合并过的分支,可以通过git branch -D name强行删除。
20.参与开源项目先要克隆一份到本地
1 git clone git@github.com:michaelliao/bootstrap.git
转自:http://www.cnblogs.com/sysu-blackbear/p/3463475.html
关于git的操作命令
1)赋权限
转自:http://blog.163.com/zhulp0372@yeah/blog/static/115894479201241545917697/
Remote Branches
Remote branches are references (pointers) to the state of branches in your remote repositories. They’re local branches that you can’t move; they’re moved automatically
for you whenever you do any network communication. Remote branches act as bookmarks to remind you where the branches on your remote repositories were the last time you connected to them.
They take the form (remote)/(branch)
.
For instance, if you wanted to see what themaster
branch
on your origin
remote
looked like as of the last time you communicated with it, you would check the origin/master
branch.
If you were working on an issue with a partner and they pushed up an iss53
branch,
you might have your own local iss53
branch;
but the branch on the server would point to the commit at origin/iss53
.
This may be a bit confusing, so let’s look at an example. Let’s say you have a Git server on your network at git.ourcompany.com
.
If you clone from this, Git’s clone
command
automatically names it origin
for
you, pulls down all its data, creates a pointer to where its master
branch
is, and names it origin/master
locally.
Git also gives you your own local master
branch
starting at the same place as origin’s master
branch,
so you have something to work from.
“origin” is not special
Just like the branch name “master” does not have any special meaning in Git, neither does “origin”. While “master” is the default name for a starting branch when you run git
which is the only reason it’s widely used, “origin” is the default name for a remote when you run
initgit
. If you run
clonegit
instead, then you will have
clone -o booyahbooyah/master
as
your default remote branch.
git第一篇---基本命令的更多相关文章
- 从零开始使用git第一篇:下载安装配置
从零开始使用git 第一篇:下载安装配置 第一篇:从零开始使用git第一篇:下载安装配置 第二篇:从零开始使用git第二篇:git实践操作 第三篇:从零开始使用git第三篇:git撤销操作.分支操作和 ...
- Git实战指南----跟着haibiscuit学Git(第一篇)
笔名: haibiscuit 博客园: https://www.cnblogs.com/haibiscuit/ Git地址: https://github.com/haibiscuit?tab=re ...
- 版本控制git第一篇
一.git的下载与安装 参考:https://blog.51cto.com/wangfeng7399/2352524 Git 是一个开源的分布式版本控制软件,用以有效.高速的处理从很小到非常大的项目版 ...
- 从零开始使用git第二篇:git的日常操作
从零开始使用git 第二篇:git的日常操作 第一篇:从零开始使用git第一篇:下载安装配置 第二篇:从零开始使用git第二篇:git实践操作 第三篇:从零开始使用git第三篇:git撤销操作.分支操 ...
- 学会Git玩转GitHub(第一篇) 入门详解 - 精简归纳
学会Git玩转GitHub(第一篇) 入门详解 - 精简归纳 JERRY_Z. ~ 2020 / 9 / 25 转载请注明出处!️ 目录 学会Git玩转GitHub(第一篇) 入门详解 - 精简归纳 ...
- [转载] Android Metro风格的Launcher开发系列第一篇
前言:从毕业到现在已经三年多了,回忆一下这三年基本上没有写过博客,总是觉得忙,没时间写,也觉得写博客没什么大用.但是看到很多大牛们都在写博客,分享自己的东西,所以嘛本着向大牛看齐,分享第一,记录第二的 ...
- 简单的抓取淘宝关键字信息、图片的Python爬虫|Python3中级玩家:淘宝天猫商品搜索爬虫自动化工具(第一篇)
Python3中级玩家:淘宝天猫商品搜索爬虫自动化工具(第一篇) 淘宝改字段,Bugfix,查看https://github.com/hunterhug/taobaoscrapy.git 由于Gith ...
- PHP 性能分析第一篇: Xhprof & Xhgui 介绍
[前言]这是国外知名博主 Davey Shafik所撰写的 PHP 应用性能分析系列的第一篇,阅读第二篇可深入了解 xhgui,第三篇则关注于性能调优实践. 什么是性能分析? 性能分析是衡量应用程序在 ...
- Android Metro风格的Launcher开发系列第一篇
前言:从毕业到现在已经三年多了,回忆一下这三年基本上没有写过博客,总是觉得忙,没时间写,也觉得写博客没什么大用.但是看到很多大牛们都在写博客,分享自己的东西,所以嘛本着向大牛看齐,分享第一,记录第二的 ...
随机推荐
- LeetCode OJ 86. Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes gr ...
- Spring Security-用户密码自定义加密
public class SunPasswordEncoder implements PasswordEncoder{ //@实现加密的方法,既将明文转换为密文的方法 public String en ...
- QML Flipable、Flickable和状态与动画 上篇
本文介绍的是QML Flipable.Flickable和状态与动画,我们以前接触过QML组件,和一些QML相关的内容,那么本文介绍的内容就很明了了.先来看内容. AD:51CTO 网+ 第十二期沙龙 ...
- perl-cgi命令行调试
来源: http://www.cnblogs.com/itech/archive/2012/09/23/2698838.html 参考: http://docstore.mik.ua/orelly/l ...
- 1*Json对象声明简单,复合,对象数组
//简单JSON对象 function btn1_click() { var json = { "id": 1001, "name": "张三&quo ...
- hadoop native
http://blog.csdn.net/benben85/article/details/4161134 http://stackoverflow.com/questions/19943766/ha ...
- 笨方法学python--提问
1 实现 用户在终端进行输入 的方法 print "how old are you?", age = raw_input() 该地方,第1名后面加逗号,然后必须换行 2 若要限制用 ...
- 转 Oracle12c/11个 Client安装出现"[INS-30131]"错误“请确保当前用户具有访问临时位置所需的权限”解决办法之完整版
错误分析:安装时exe会自动解压到C:\Users\Administrator\AppData\Local\Temp再进行安装,当文件夹权限不足时就会拒绝安装程序的访问: 第一步: 在win+R输入 ...
- Oracle表和表数据恢复
Oracle数据库表及表数据的恢复 1. 表恢复 对误删的表,只要没有使用 purge 永久删除选项,那么基本上是能从 flashback table 区恢复回来的. 数据表和其中的数据都是可以恢复回 ...
- php 编程效率(1)
用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中搜寻变量,单引号则 不会,注意:只有echo能这么做,它是一种可以把多个字符串当作参数的“函数”(译注:PHP手册中 ...