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 - ...
随机推荐
- 去掉删除discuz x3.2 的-Powered by Discuz!
如图discuz论坛 网站标题栏的尾巴powered by discuz!是不是很想删除呢,特别是为什么会剩下短线呢?下面就叫你如何准确删除或者修改. 工具/原料 8UFTP(使用自己熟悉的网站文件上 ...
- Oracle 去掉重复字符串
create or replace function remove_same_string(oldStr varchar2, sign varchar2) return varchar2 is /** ...
- 故障排查实战案例——某电器ERP系统日志暴增
前言 本篇文章写在新春佳节前夕,也是给IT运维朋友一个警醒,在春节长假前请妥善体检自己的系统安心过个年. 千里之堤毁于蚁穴,一条看似简单的语句就能拖垮整个系统,您的SQL Server很久没体检了吧? ...
- Java内存回收优化及配置
原文链接:http://eol.cqu.edu.cn/eol/jpk/course/preview/jpkmaterials_folder_txtrtfview.jsp?resId=23156& ...
- Windows 10 IoT Serials 4 - 如何在树莓派上使用Cortana语音助手
从Windows 10 IoT Core 14986版本开始,微软已经加入Cortana语音助手功能.之前,我们只能使用本地语音识别,需要编写应用程序,下载到设备中才能实现.从现在开始,微软已经从系统 ...
- CSS实现的几款不错的菜单栏
前言 自从做了智慧城市这个项目之后,我一个做后端的开发者,瞬间转为前端开发,不过我还是很喜欢前端的.前端那些事,其实蛮有意思的,HTML实现的是静态的,使用ajax之后就可以和数据库交互了,加上js和 ...
- WPF开发进阶 - Fody/PropertyChanged(二)
前一篇 简单的介绍了Fody/PropertyChanged的使用方法, 这一篇,我们详细介绍它的一些比较重要的特性和规则 1. Attributes 通过在类或属性上标记这些特性,可以在编译代码时, ...
- 简单谈谈JavaScript中的this
是夜,想着考量下小黄毛近期的JavaScript进阶如何了,鉴于近期一直在接触Vue 2.0,索性就围绕this编写了个代码片段, 给其一个测量,毕竟写js的程序员都知道,JavaScript的函数调 ...
- C语言 extern学习2 分析
上一篇文章中,通过头文件声明,而调用有一个特别大的漏洞: 为什么编译器可以链接过来呢,因为默认是extern修饰的,这种类似全局作用域的功能使其可以被调用 继续加强学习: 这一次有两对C文件: fir ...
- Windows程序员必须知道的字符编码和字符集
字符编码 (Character encoding) 在存储和传递文本过程中,为了使得所有电脑都能够正确的识别出文本内容,需要有一个统一的规则. 2. 字符集 (Character Set) ) 一般 ...