Git基础教程(一)
本教程为学习笔记,github作为最受欢迎的资源库,不可不学!详细教程参见:廖雪峰的官方网站Git教程系列。准备花两篇幅搞定实战总结,闲言碎语少说,脚踏实地求真!
1,Git入门


Administrator@WIN-9S4D59CISAA MINGW64 ~(master)
$ git config --global user.name "zhangbc" Administrator@WIN-9S4D59CISAA MINGW64 ~(master)
$ git config --global user.email "zhangbochengcheng189@163.com"
Administrator@WIN-9S4D59CISAA MINGW64 ~(master)
$ cd F: Administrator@WIN-9S4D59CISAA MINGW64 /f
$ mkdir learngit Administrator@WIN-9S4D59CISAA MINGW64 /f
$ cd learngit/ Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit
$ pwd
/f/learngit
Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit
$ git init
Initialized empty Git repository in F:/learngit/.git/ Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$

Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git add readme.md Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git commit -m "wrote a readme file."
[master (root-commit) a25e8e4] wrote a readme file.
1 file changed,42 insertions(+)
create mode 100644 readme.md
Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git status
On branch master
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")
Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git diff readme.md
diff --git a/readme.md b/readme.md
index 33a3876..46dd97d100644
--- a/readme.md
+++ b/readme.md
@@-40,3+40,6@@
git提交到github:
ssh-keygen -C ‘zhangbocheng189@163.com’-t rsa
回到GitHub个人首页,点击AccountSettings-> SSH PublicKeys->Add another public key。title 可以随便取名字,Key里面添加的内容为 id_rsa.pub 文件内所有的代码。然后点击Apply即可。
+
+Git is a distributed version control system.
+Git is free software.
\ No newline at end of file

Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git log
commit 6fa7dc43a0aa553ae0a3cf9b9a6c9b2757a8e556
Author: zhangbc <zhangbochengcheng189@163.com>
Date: Sun Mar 5 23:21:18 2017 +0800
wrote a readme file.
commit a25e8e46a364a39e52a36cec1bb94bf58921fae4
Author: zhangbc <zhangbochengcheng189@163.com>
Date: Sun Mar 5 23:07:56 2017 +0800
wrote a readme file.
Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git log --pretty=oneline
6fa7dc43a0aa553ae0a3cf9b9a6c9b2757a8e556 wrote a readme file.
a25e8e46a364a39e52a36cec1bb94bf58921fae4 wrote a readme file.
HEAD
表示当前版本,也就是最新的提交3628164...882e1e0
(注意我的提交ID和你的肯定不一样),上一个版本就是HEAD^
,上上一个版本就是HEAD^^
,当然往上100个版本写100个^
比较容易数不过来,所以写成HEAD~100
。Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git reset --hard HEAD^
HEAD is now at a25e8e4 wrote a readme file.
Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git reset --hard 6fa7dc43a0aa553ae0a3cf9b9a6c9b2757a8e556
HEAD is now at 6fa7dc4 wrote a readme file.
Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git reflog
6fa7dc4 HEAD@{0}: reset: moving to 6fa7dc43a0aa553ae0a3cf9b9a6c9b2757a8e556
a25e8e4 HEAD@{1}: reset: moving to HEAD^
6fa7dc4 HEAD@{2}: commit: wrote a readme file.
a25e8e4 HEAD@{3}: commit (initial): wrote a readme file.

master
,以及指向master
的一个指针叫HEAD
。
add
到暂存区,那就不会加入到commit
中。Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git checkout -- readme.md

1)是readme.md自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;2)是readme.md已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。
Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ rm test.md Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) deleted: test.md no changes added to commit (use "git add" and/or "git commit -a") Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git checkout -- test.md Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git status
On branch master
nothing to commit, working tree clean
Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ rm test.md
Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) deleted: test.md no changes added to commit (use "git add" and/or "git commit -a") Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git rm test.md
rm 'test.md' Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git commit -m "remove test.md"
[master 1f8e8c7] remove test.md
1 file changed,45 deletions(-)
delete mode 100644 test.md Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git status
On branch master
nothing to commit, working tree clean
Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ ssh-keygen -t rsa -C "zhangbocheng189@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): zhangbc
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in zhangbc.
Your public key has been saved in zhangbc.pub.
The key fingerprint is:
SHA256:ULusTjP9zWYbldd/snUjJIgG1Jwqqzu1QtT7m2I7zXQ zhangbocheng189@163.com
The key's randomart image is:
+---[RSA 2048]----+
| .o o |
| . = . |
| . .o . |
| . o ..o... ..|
|. + oS. . .o o|
| . + ..E o. ..|
|. o * * . ....=|
| + = *.o . oo..++|
| .=.+oo .o+.. |
+----[SHA256]-----+


Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git remote add origin git@github.com:zhangbc/learngit.git
Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git push -u origin master
Permission denied (publickey).
fatal:Could not read from remote repository. Please make sure you have the correct access rights
and the repository exists.
Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ ssh -T -v git@github.com
OpenSSH_7.3p1,OpenSSL1.0.2k26Jan2017
debug1:Reading configuration data /etc/ssh/ssh_config
debug1:Connecting to github.com [192.30.253.113] port 22.
debug1:Connection established.
debug1: identity file /c/Users/Administrator/.ssh/id_rsa type 1
debug1: key_load_public:No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_rsa-cert type -1
debug1: key_load_public:No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_dsa type -1
debug1: key_load_public:No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_dsa-cert type -1
debug1: key_load_public:No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ecdsa type -1
debug1: key_load_public:No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ecdsa-cert type -1
debug1: key_load_public:No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ed25519 type -1
debug1: key_load_public:No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ed25519-cert type -1
debug1:Enabling compatibility mode for protocol 2.0
debug1:Local version string SSH-2.0-OpenSSH_7.3
debug1:Remote protocol version 2.0, remote software version libssh-0.7.0
debug1: no match: libssh-0.7.0
debug1:Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC:<implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC:<implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1:Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1:Host'github.com' is known and matches the RSA host key.
debug1:Found key in/c/Users/Administrator/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1:Authentications that can continue: publickey
debug1:Next authentication method: publickey
debug1:Offering RSA public key:/c/Users/Administrator/.ssh/id_rsa
debug1:Authentications that can continue: publickey
debug1:Trying private key:/c/Users/Administrator/.ssh/id_dsa
debug1:Trying private key:/c/Users/Administrator/.ssh/id_ecdsa
debug1:Trying private key:/c/Users/Administrator/.ssh/id_ed25519
debug1:No more authentication methods to try.
Permission denied (publickey).
Administrator@WIN-9S4D59CISAA MINGW64 ~(master)
$ find -name *pub
./.android/adbkey.pub
./.ssh/id_rsa.pub
./AppData/Roaming/VanDyke/Config/KnownHosts/160.16.205.132[160.16.205.132]22.pub

Administrator@WIN-9S4D59CISAA MINGW64 /f/learngit (master)
$ git remote -v
origin git@github.com:zhangbc/learngit.git (fetch)
origin git@github.com:zhangbc/learngit.git (push)
Administrator@WIN-9S4D59CISAA MINGW64 /e/DataStructure/dataStructure (master)
$ git rm -f gitReadme.md
rm 'gitReadme.md' Administrator@WIN-9S4D59CISAA MINGW64 /e/DataStructure/dataStructure (master)
$ git commit -m "delete file Gitreadme.md"
[master 20828c2] delete file Gitreadme.md
1 file changed,4 deletions(-)
delete mode 100644 gitReadme.md Administrator@WIN-9S4D59CISAA MINGW64 /e/DataStructure/dataStructure (master)
$ git push origin master
Counting objects:2,done.
Delta compression using up to 4 threads.
Compressing objects:100%(2/2),done.
Writing objects:100%(2/2),236 bytes |0 bytes/s,done.
Total2(delta 1), reused 0(delta 0)
remote:Resolving deltas:100%(1/1), completed with 1local objects.
To github.com:zhangbc/dataStructure.git
c182956..20828c2 master -> master
zhangbc@working MINGW64 /d/BaiduYunDownload/dataStructure (master)
$ git remote remove origin
zhangbc@working MINGW64 /d/BaiduYunDownload
$ git clone git@github.com:zhangbc/cnblogs_Scrapy.git
Cloning into 'cnblogs_Scrapy'...
remote:Counting objects:33,done.
remote:Compressing objects:100%(28/28),done.
remote:Total33(delta 3), reused 33(delta 3), pack-reused 0
Receiving objects:100%(33/33),34.74KiB|0 bytes/s,done.
Resolving deltas:100%(3/3),done.
Git基础教程(一)的更多相关文章
- Git基础教程(二)
继续上篇Git基础教程(一),在开篇之前,先回顾一下上篇中的基本命令. 配置命令:git config --global * 版本库初始化:git init 向版本库添加文件:git add * 提交 ...
- 第五篇 -- git基础教程
git(权威指南)基础教程第一章 git -- gitbash -- cygwin git service:gitolite 两个的目录不同 gitbash ~ windows/home/admini ...
- Git基础教程
Git是一个分布式的版本控制工具,本篇文章从介绍Git开始,重点在于介绍Git的基本命令和使用技巧,让你尝试使用Git的同时,体验到原来一个版 本控制工具可以对开发产生如此之多的影响,文章分为两部分, ...
- GItHub Git 基础教程 常用命令 命令
最近复习了一下Git的使用,简单总结了一些.以供以后查阅和大家参考. 一,安装 首先是Linux下: 打开shell ,输入 sudo apt-get install git-core 之后回车输入密 ...
- git 基础教程
git 提交 全部文件 git add . git add xx命令可以将xx文件添加到暂存区,如果有很多改动可以通过 git add -A .来一次添加所有改变的文件.注意 -A 选项后面还有一个 ...
- Git 基础教程 之 别名
配置别名, 例如: git config --global alias.st status git config ...
- Git 基础教程 之 标签
所谓标签:就是一个让人容易记住的有意义的名字,与某个commit绑在一起. 创建标签:①切回需要打标签的分支上 ② git tag <name> 默认标 ...
- Git 基础教程 之 多人协作
多人协作时,从远程克隆时,默认情况下,只能看到master分支 git checkout -b dev origin/dev 创建远程origin的dev分支到本地 git branch ...
- Git 基础教程 之 远程推送
当你从远程仓库克隆时,实际上Git自动把本地的master分支和远程的master分支对应了起来,并且,远程仓库默认名称是origin. git remote 查看远程库信息 git remote - ...
随机推荐
- AFNetWorking 之 Get/Post 请求的使用
1. Get 与 Post 比较 GET请求:简单业务.明文发送 POST请求:上传文件,重要信息.加密信息,.大数据信息. 2. 序列化 默认是JSon格式. // 请求的序列化 manager.r ...
- CentOS-6.6下Tomcat-7.0安装与配置(Linux)
CentOS-6.6下Tomcat-7.0安装与配置(Linux) 一.认识tomcat Tomcat是一个免费的开源的Serlvet容器,它是Apache基金会的Jakarta项目中的一个核心项目, ...
- MongoDB安装环境搭建
Mongodb的默认端口号27017 _id是全局唯一值,不要去给这个列赋值,默认是唯一的,如果赋值,列入有两列的_id:2,则会报冲突不能插入 [root@HE4 ~]# tar xvf mongo ...
- jQuery addClass removeClass toggleClass hasClass is(.class)用法
jQuery addClass removeClass toggleClass hasClass is(.class)用法 <%@ page language="java" ...
- 用Redis作为Mysql数据库的缓存
看到一篇不错的博文,记录下: http://blog.csdn.net/qtyl1988/article/details/39553339 http://blog.csdn.net/qtyl1988/ ...
- HTML5和CSS3
一.HTML5 HTML5 是 HTML 标准的最新演进版本. 这个术语代表了两个不同的概念:它是一个新的 HTML 语言版本包含了新的元素,属性和行为,同时包含了一系列可以被用来让 Web 站点和应 ...
- 如何用webbrowser获取ajax动态生成的网页的源码?
1.步骤一:修改IE内核的版本(这个方法厉害了) public Form1() { InitializeComponent();int BrowserVer, RegVal; // get the i ...
- MiniProfiler工具介绍
MiniProfiler是一款针对.NET, Ruby, Go and Node.js的性能分析的轻量级程序.可以对一个页面本身,及该页面通过直接引用.Ajax.Iframe形式访问的其它页面进行监控 ...
- Swift 学习有用的学习链接(此贴随学习的深入会一直更新)
Swift 字符串相关学习推荐下面这个链接内容 一: http://www.jianshu.com/p/52e7580166ff (里面详细的介绍了2.0 和 2.0之前 的版本的一些不同的处) 二 ...
- 使用devstack搭建openstack Newton 版本的坑
国外源访问速度慢怎么办? 使用国外源,加之带宽紧张,搭建过程是很累的,这里推荐大家使用一下源: devstack包源.:http://git.trystack.cn pip源: [global] in ...