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开发系列第一篇
前言:从毕业到现在已经三年多了,回忆一下这三年基本上没有写过博客,总是觉得忙,没时间写,也觉得写博客没什么大用.但是看到很多大牛们都在写博客,分享自己的东西,所以嘛本着向大牛看齐,分享第一,记录第二的 ...
随机推荐
- 编写程序,从vector<char>初始化string
#include<iostream> #include<string> #include<vector> using namespace std; int main ...
- win10快捷键大全
win10快捷键大全大家可以来了解一下,今天小编带来了win10常用快捷键,很多朋友喜欢使用快捷键来操作电脑,那么Windows10系统有哪些新的快捷键呢• 贴靠窗口:Win +左/右> Win ...
- IntelliJ IDEA 2016.1.3激活【亲测可用】
测试日期:2016.6.24 License server: http://www.iteblog.com/idea/key.php // ========================= 更多技术 ...
- 使用固件库操作STM32F4时的必要配置(转)
源:使用固件库操作STM32F4时的必要配置 使用STM32F4的固件库时,默认的晶振为25Mhz晶振,因此需要做一定的修改.之前因为一直没有注意这个问题,我捣腾了许久,发现工作时钟总是不对,查阅了一 ...
- CREATE SCHEMA
CREATE SCHEMA 创建一个架构,即命名空间,在这个空间中可以进一步定义包含表.视图和权限定义等对象. 语法 CREATE SCHEMA AUTHORIZATION owner [ &l ...
- Java学习笔记之自定义异常
1.自定义异常类: /** * 自定义异常,只要继承继承Exception类或其子类即可 * @author Administrator * */ public class FileException ...
- 无线手柄+步进电机——控制方向
今天测试了一下无线手柄控制电机转向的改变 1: #include <PS2X_lib.h> //for v1.6 2: #include <Stepper.h> 3: 4: ...
- 【转】使用ThinkPHP必须掌握的调试方法
经常看到有人问到findAll的返回数据类型是什么之类的问题,以及出错了不知道什么原因的情况,其实还是没有熟悉ThinkPHP内置的调试手段和方法,抛开IDE本身自带的调试方式不说,如果你正在用或者打 ...
- 天天果园,中粮我买网等生鲜APP竞品分析
奈何对生鲜行业的品类,价格,供应链不熟悉,想先从APP开始来了解生鲜行业和各个生鲜企业,若有不足之处,还望海量,也请帮忙指正. 选取了以下竞品:天天果园,易果生鲜,一米鲜,中粮我买网,爱鲜蜂,每日优鲜 ...
- sqlserver 2008 查看表描述,和表结构
sp_help sys_user sp_columns sys_user --表结构 THEN obj.name ELSE '' END AS 表名, col.colorder AS 序号 , c ...