Git基础教程(二)
配置命令:git config --global *
版本库初始化:git init
向版本库添加文件:git add *
提交文件:git commit *
查看状态:git status
查看修改详情:git diff *
查看日志:git log (*)
恢复版本:git reset *
撤销:git checkout -- *
删除:git rm * 配置github:ssh-keygen -t rsa -C "******@163.com"
添加远程库:git remote add *
调试:ssh -T -v git@github.com
查询远程库:git remote -v
删除远程库文件:
git rm -f gitReadme.md
git commit -m "delete file Gitreadme.md" --先删除本地库
git push origin master
删除远程库:git remote remove origin
克隆远程库:git clone *
(续)4,分支管理
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git branch
* master
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git branch dev zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git checkout dev
Switched to branch 'dev'
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git checkout -b working
Switched to a new branch 'working'
git branch
命令会列出所有分支,当前分支前面会标一个*
号。zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (working)
$ git add readme.md zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (working)
$ git commit -m 'add readme.md'
[working 59dc0fe] add readme.md
1 file changed,16 insertions(+)
create mode 100644 readme.md
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (working)
$ cat readme.md
----------
# 数据结构学习笔记 #
>**本笔记来自学习《数据结构与算法.严蔚敏(48集)》视频,[数据结构(C语言版)].严蔚敏_吴伟民.扫描版.pdf。** ----------
# 第01章 绪论 #
## 学习要点 ##
1.熟悉各名词、术语的含义,掌握基本概念;
2.理解算法五个要素的确切含义;
3.掌握计算语句频度和估算算法时间复杂度的方法。
## 代码块 ##
-矩阵乘法
-选择排序
-冒泡排序 zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ cat readme.md
cat: readme.md:No such file or directory
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git merge working
Updating b460b3f..59dc0fe
Fast-forward
readme.md |16++++++++++++++++
1 file changed,16 insertions(+)
create mode 100644 readme.md
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git branch -d dev
Deleted branch dev (was b460b3f).
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git branch -d working
error:The branch 'working' is not fully merged.
If you are sure you want to delete it, run 'git branch -D working'.
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git add readme.md zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git commit -m "add a reame.md file."
[master b6fc772] add a reame.md file.
1 file changed,17 insertions(+)
create mode 100644 readme.md zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git pull --rebase origin master
remote:Counting objects:2,done.
remote:Compressing objects:100%(2/2),done.
remote:Total2(delta 1), reused 0(delta 0), pack-reused 0
Unpacking objects:100%(2/2),done.
From github.com:zhangbc/dataStructure
* branch master -> FETCH_HEAD
6fb284c..8366817 master -> origin/master
First, rewinding head to replay your work on top of it...
Applying: add a reame.md file.
Applying:数据结构学习笔记 by zhangbc
Applying: add a reame.md file. zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git push origin master
Counting objects:6,done.
Delta compression using up to 4 threads.
Compressing objects:100%(6/6),done.
Writing objects:100%(6/6),604 bytes |0 bytes/s,done.
Total6(delta 4), reused 0(delta 0)
remote:Resolving deltas:100%(4/4), completed with 2local objects.
To github.com:zhangbc/dataStructure.git
8366817..da420b4 master -> master
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ cat gitReadme.md
# gitReadme #
----------
Creating a new branch is quick and simple.(Dev) zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git add gitReadme.md zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git commit -m "Add gitReadme.md"
[dev 366500d]Add gitReadme.md
1 file changed,4 insertions(+)
create mode 100644 gitReadme.md
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git checkout master
Switched to branch 'master'
M readme.md
Your branch is ahead of 'origin/master' by 3 commits.
(use "git push" to publish your local commits) zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ cat gitReadme.md
# gitReadme #
----------
Change a main branch of master is quick and simple.(Master) zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git add gitReadme.md zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git commit -m "Add gitReadme.md"
[master b466603]Add gitReadme.md
1 file changed,4 insertions(+)
create mode 100644 gitReadme.md
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git merge dev
Auto-merging gitReadme.md
CONFLICT (add/add):Merge conflict in gitReadme.md
Automatic merge failed; fix conflicts and then commit the result.
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master|MERGING)
$ cat gitReadme.md
# gitReadme # ----------
<<<<<<< HEAD
Change a main branch of master is quick and simple.(Master)
======= Creating a new branch is quick and simple.(Dev)
>>>>>>> dev
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master|MERGING)
$ vi gitReadme.md
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master|MERGING)
$ cat gitReadme.md
# gitReadme #
---------- Change a main branch of master is quick and simple.(Master)
----------
Creating a new branch is quick and simple.(Dev) zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master|MERGING)
$ git add gitReadme.md zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master|MERGING)
$ git commit -m "Add gitReadme.md confict fixed."
[master 8e59a4d]Add gitReadme.md confict fixed. zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$
查看日志:
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git log --graph --pretty=oneline --abbrev-commit
Fast forward
模式,但这种模式下,删除分支后,会丢掉分支信息。如果要强制禁用Fast forward
模式,Git就会在merge时生成一个新的commit,这样,从分支历史上就可以看出分支信息。 zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git checkout -b dev
Switched to a new branch 'dev' zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ cat gitReadme.md
# gitReadme #
----------
Creating a new branch with --no-ff is quick and simple.(Dev) zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git add gitReadme.md zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git commit -m 'Add merge with --no-ff.'
[dev 49afeab]Add merge with --no-ff.
1 file changed,1 insertion(+),4 deletions(-)
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 6 commits.
(use "git push" to publish your local commits) zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git merge --no-ff -m "Merge with no-ff." dev
Merge made by the 'recursive' strategy.
gitReadme.md |5+----
1 file changed,1 insertion(+),4 deletions(-)
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git log --graph --pretty=oneline --abbrev-commit
首先,master分支应该是非常稳定的,也就是仅用来发布新版本,平时不能在上面干活;干活都在dev分支上,也就是说,dev分支是不稳定的,到某个时候,比如1.0版本发布时,再把dev分支合并到master上,在master分支发布1.0版本;每个人都在dev分支上干活,每个人都有自己的分支,时不时地往dev分支上合并即可。
stash
功能,可以把当前工作现场“储藏”起来,等以后恢复现场后继续工作。zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git branch
* dev
master zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git status
On branch dev
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) modified: readme.md no changes added to commit (use "git add" and/or "git commit -a") zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git stash
Saved working directory and index state WIP on dev:49afeabAdd merge with --no-ff.
HEAD is now at 49afeabAdd merge with --no-ff. zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 10 commits.
(use "git push" to publish your local commits) zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git checkout -b issue-101
Switched to a new branch 'issue-101' zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (issue-101)
$ git add readme.md zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (issue-101)
$ git commit -m "fix bug 101"
On branch issue-101
nothing to commit, working tree clean zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (issue-101)
$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 10 commits.
(use "git push" to publish your local commits) zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git merge --no-ff -m "merge bug fix 101" issue-101
Already up-to-date. zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git branch -d issue-101
Deleted branch issue-101(was c182956). zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git checkout dev
Switched to branch 'dev' zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git status
On branch dev
nothing to commit, working tree clean zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git stash list
stash@{0}: WIP on dev:49afeabAdd merge with --no-ff. zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git stash pop
On branch dev
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) modified: readme.md no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0}(ab63aa01e37e908d49ab921656884b29b17aeac1) zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git stash list zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
2)feature分支
git branch -D <name>
强行删除。zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git remote
origin zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git remote -v
origin git@github.com:zhangbc/dataStructure.git (fetch)
origin git@github.com:zhangbc/dataStructure.git (push)
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git push origin dev
Counting objects:20,done.
Delta compression using up to 4 threads.
Compressing objects:100%(20/20),done.
Writing objects:100%(20/20),1.81KiB|0 bytes/s,done.
Total20(delta 12), reused 0(delta 0)
remote:Resolving deltas:100%(12/12), completed with 2local objects.
To github.com:zhangbc/dataStructure.git
*[new branch] dev -> dev
(2)dev分支是开发分支,团队所有成员都需要在上面工作,所以也需要与远程同步;(3)bug分支只用于在本地修复bug;(4)feature分支是否推到远程,取决于合作开发。
抓取分支:
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (dev)
$ git clone git@github.com:zhangbc/PythonWorking.git
Cloning into 'PythonWorking'...
remote:Counting objects:90,done.
remote:Compressing objects:100%(2/2),done.
remote:Total90(delta 0), reused 0(delta 0), pack-reused 88
Receiving objects:100%(90/90),18.55KiB|6.00KiB/s,done.
Resolving deltas:100%(47/47),done.
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git tag V1.0
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git tag
V1.0
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git log --pretty=oneline --abbrev-commit
c182956 merge bug fix 101
2fd9cb4 fix bug 101
ffb5db6 Merge with no-ff.
49afeabAdd merge with --no-ff.
8e59a4dAdd gitReadme.md confict fixed.
b466603 Add gitReadme.md
366500dAdd gitReadme.md
63b712aMerge branch 'dev'
4d28e6d an example
6da4fcd an example
da420b4 add a reame.md file.
cfce135 数据结构学习笔记 by zhangbc
5433fd9 add a reame.md file.
8366817Delete README.md
6fb284c数据结构学习笔记 by zhangbc
ac69d7d 数据结构学习笔记 by zhangbc
bde6080 add readme.md
39013c9Create README.md
b460b3f 数据结构学习笔记 by zhangbc zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git tag v0.1 da420b4
查看标签详情:
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git show V1.0
commit c182956d8cf80b393b18027cc6bb010481aeae40
Merge: ffb5db6 2fd9cb4
Author: zhangbc <zhangbochengcheng189@163.com>
Date:MonMar616:47:202017+0800 merge bug fix 101
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git tag -a V0.2-m "Version 0.1 released"5433fd9
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git tag -s -a V0.3-m "Version 0.3 released"
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git tag -d show
Deleted tag 'show'(was c182956)
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git push origin V0.2
Counting objects:1,done.
Writing objects:100%(1/1),168 bytes |0 bytes/s,done.
Total1(delta 0), reused 0(delta 0)
To github.com:zhangbc/dataStructure.git
*[new tag] V0.2-> V0.2 zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git push origin --tag
Total0(delta 0), reused 0(delta 0)
To github.com:zhangbc/dataStructure.git
*[new tag] V1.0-> V1.0
*[new tag] v0.1-> v0.1
删除远程库标签:
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git tag -d V0.2
Deleted tag 'V0.2'(was 30a96b6) zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git push origin :refs/tags/V0.2
To github.com:zhangbc/dataStructure.git
-[deleted]V0.2
Administrator@WIN-9S4D59CISAA MINGW64 ~(master)
$ git config --global color.ui true
Administrator@WIN-9S4D59CISAA MINGW64 /e/DataStructure/dataStructure (master)
$ git config --global alias.st status Administrator@WIN-9S4D59CISAA MINGW64 /e/DataStructure/dataStructure (master)
$ git st
On branch master
nothing to commit, working tree clean
Administrator@WIN-9S4D59CISAA MINGW64 /e/DataStructure/dataStructure (master)
$ git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" Administrator@WIN-9S4D59CISAA MINGW64 /e/DataStructure/dataStructure (master)
$ git lg
*53aad04-(HEAD -> master, origin/master) C++ ignore file.(21 minutes ago)<zhangbc>
* c28d67e -本笔记系统说明文件 by zhangbc (35 minutes ago)<zhangbc>
* b797aab - delete file readmeBug.md (38 minutes ago)<zhangbc>
*20828c2- delete file Gitreadme.md (44 minutes ago)<zhangbc>
配置Git的时候,加上--global是针对当前用户起作用的,如果不加,那只针对当前仓库起作用。
Administrator@WIN-9S4D59CISAA MINGW64 /e/DataStructure/dataStructure (master)
$ cat .git/config
[core]
repositoryformatversion =0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = git@github.com:zhangbc/dataStructure.git
fetch =+refs/heads/*:refs/remotes/origin/*
Administrator@WIN-9S4D59CISAA MINGW64 ~(master)
$ cat .gitconfig
[user]
name = *****
email = **********@163.com
[color]
ui = true
[alias]
st = status
g = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'--abbrev-commit
最后,Git基础入门知识,到此已基本完成,欢迎各位拍砖!
Git基础教程(二)的更多相关文章
- 第五篇 -- git基础教程
git(权威指南)基础教程第一章 git -- gitbash -- cygwin git service:gitolite 两个的目录不同 gitbash ~ windows/home/admini ...
- Git 学习之Git 基础(二)
Git 基础 读完本章你就能上手使用 Git 了.本章将介绍几个最基本的,也是最常用的 Git 命令,以后绝大多数时间里用到的也就是这几个命令.读完本章,你就能初始化一个新的代码仓库,做一些适当配置: ...
- Git系列教程二 基础介绍
一.存储方式 如果让我们设计一个版本控制系统,最简单的方式就是每做一次更改就生成一个新的文件. 这样的方式太占用空间,所以传统的版本控制系统都是保存一个文件的某个版本的全部内容以及其他版本相对于这个版 ...
- Git基础教程(一)
本教程为学习笔记,github作为最受欢迎的资源库,不可不学!详细教程参见:廖雪峰的官方网站Git教程系列.准备花两篇幅搞定实战总结,闲言碎语少说,脚踏实地求真! 1,Git入门 Git是 ...
- GItHub Git 基础教程 常用命令 命令
最近复习了一下Git的使用,简单总结了一些.以供以后查阅和大家参考. 一,安装 首先是Linux下: 打开shell ,输入 sudo apt-get install git-core 之后回车输入密 ...
- Git简明教程二、开始进行版本管理
上一篇介绍了Git中的一些基本概念.本篇来实际看一看如何通过几个常用命令来快速上手Git,完成版本管理的日常操作(核心操作). 0. 准备工作 安装Git后,请先在你的电脑上新建或选择一个目录作为测试 ...
- git 基础教程
git 提交 全部文件 git add . git add xx命令可以将xx文件添加到暂存区,如果有很多改动可以通过 git add -A .来一次添加所有改变的文件.注意 -A 选项后面还有一个 ...
- Git 基础教程 之 添加、提交
一, 编写一个名为readme.txt文件,放入pythonwork目录下 ① 手动新建 ② 使用命令: a. touch readme.txt b. vim readme.txt PS: ...
- Git 基础教程 之 创建版本库
一,选择一个合适的地方,创建空目录,下面两种方法都可 ① 手动新建 ② 使用命令: mkdir pythonwork 二,初始化,使目录变成Git可管理的仓库 执行: git i ...
随机推荐
- ViewFlipper的功能与用法
ViewFlipper组件继承了ViewAnimator,它可调用addView(View v)添加多个组件,一旦向ViewFlipper中添加了多个组件之后,ViewFlipper可使用动画控制多个 ...
- HTML 颜色
HTML 颜色 HTML 颜色由红色.绿色.蓝色混合而成. 颜色值 HTML 颜色由一个十六进制符号来定义,这个符号由红色.绿色和蓝色的值组成(RGB). 种颜色的最小值是0(十六进制:#00).最大 ...
- Bootstrap入门(二十四)data属性
Bootstrap入门(二十四)data属性 你可以仅仅通过 data 属性 API 就能使用所有的 Bootstrap 插件,无需写一行 JavaScript 代码.这是 Bootstrap 中的一 ...
- zookeeper 介绍
ZooKeeper 是一个分布式的,开放源码的分布式应用程序协调服务,它包含一个简单的原语集,分布式应用程序可以基于它实现同步服务,配置维护和命名服务等. Zookeeper是hadoop的一个子项目 ...
- Node v0.12.5 稳定版发布
Node v0.12.5 稳定版发布了,该版本改进记录主要包括: openssl: upgrade to 1.0.1o (Addressing multiple CVEs) npm: upgrade ...
- ArcGIS制图技巧系列(3)—让地图更有立体感
ArcGIS制图技巧系列(3)-让地图更有立体感 by 李远祥 在前面的章节中,我们已经介绍过各种的地图效果,如发光效果,山体阴影效果,植被填充效果等,所有的这些效果不外乎是各种技术的叠加和技巧的使用 ...
- 地图学与GIS制图的基础理论(一)
说到地图制作,很多人第一时间就会跟地图学进行挂钩.是的,地图学的很多理论和知道思想都非常适合基于GIS制图.可以说,利用GIS进行电子地图制作,其实也属于地图学的一小部分. 地图学是研究地图的理论.地 ...
- 众人拾柴火焰高之Tomcat集群
一人拾柴火不旺,众人拾柴火焰高.Tomcat服务器也是一样,一台服务器再强大能承受的访问也是有限的.要提供高并发.高可用的服务,就必须横向扩展,多台Tomcat组成一个集群,根据实际的访问量动态增减服 ...
- AR_Demon(使用vuforia平台提供的钥匙跟后台,实现相机拍图片读取模型以及视频的功能)
1.https://developer.vuforia.com注册账号. 2.分别添加License Manager(连接钥匙),Target Manager(图片后台下载). 3.下载vuforia ...
- Google Guice学习
学习动力:公司项目使用 官方文档:https://github.com/google/guice/wiki/Motivation 学习阶段:入门 主要部份: 简介 Bindings方式 Scopes设 ...