第二次作业:分布式版本控制系统Git的安装与使用
本次作业要求来自:
https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2103
一.下载安装配置用户名和邮箱。
1.安装git bash
2.配置用户名和邮箱
在git bash输入下列加粗命令
Administrator@PC-20161105AYNF MINGW32 ~
$ git config --global user.name "lzic"
Administrator@PC-20161105AYNF MINGW32 ~
$ git config --global user.email "715741378@qq.com"
3.查看账户名和邮箱地址
在git bash输入下列加粗命令
Administrator@PC-20161105AYNF MINGW32 ~
$ git config user.name
lzic
Administrator@PC-20161105AYNF MINGW32 ~
$ git config user.email
715741378@qq.com
二. 创建工作目录并通过git init命令把这个目录变成Git可以管理的仓库。
1.创建工作目录
2.进入工作目录
在git bash输入下列加粗命令
Administrator@PC-20161105AYNF MINGW32 /e
$ cd /e
Administrator@PC-20161105AYNF MINGW32 /e
$ cd git
Administrator@PC-20161105AYNF MINGW32 /e/git
$ cd project1
3.把目录变成工作仓库
在git bash输入下列加粗命令
Administrator@PC-20161105AYNF MINGW32 /e/git/project1
$ git init
Initialized empty Git repository in E:/git/project1/.git/
三. 在工作目录下准备文本文件,建议下载Notepad++代替记事本。
1.在工作目录创建文件
四. 组合用git add、git commit、git status 把文件提交到仓库。
1.在文件中添加内容并保存
2.查看状态。
在git bash输入下列加粗命令
Administrator@PC-20161105AYNF MINGW32 /e/git/project1 (master)
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
3.把文件添加到仓库
在git bash输入下列加粗命令
Administrator@PC-20161105AYNF MINGW32 /e/git/project1 (master)
$ git add test.txt
Administrator@PC-20161105AYNF MINGW32 /e/git/project1 (master)
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: test.txt
4.把文件提交到仓库
在git bash输入下列加粗命令
Administrator@PC-20161105AYNF MINGW32 /e/git/project1 (master)
$ git commit -m " hello lzic" 下滑线命令是对版本的描述,自己命名
[master (root-commit) a1f4304] hello lzic
1 file changed, 1 insertion(+)
create mode 100644 test.txt
Administrator@PC-20161105AYNF MINGW32 /e/git/project1 (master)
$ git status
On branch master
nothing to commit, working tree clean
五. 练习提交三个或以上的版本。
1.修改文件内容并保存,重复四步骤
六. 组合使用git diff、git log、git reset命令进行版本管理与回退,观察文件变化。
1.修改文件内容并保存
2.查看工作文件和仓库文件的不同
在git bash输入下列加粗命令
Administrator@PC-20161105AYNF MINGW32 /e/git/project1 (master)
$ git diff
diff --git a/test.txt b/test.txt
index fdfd97d..97ea40d 100644
--- a/test.txt
+++ b/test.txt
@@ -1,3 +1,4 @@
hello lzic
this is my first modify
-this is my second modify
\ No newline at end of file
+this is my second modify
+this is my third modify
\ No newline at end of file
3.查看版本
在git bash输入下列加粗命令
Administrator@PC-20161105AYNF MINGW32 /e/git/project1 (master)
$ git log --pretty=oneline
2413e875310ff2da0d73a24f91577045b1f0c72c second modify
1232797d243675f3b2f8d010f8d3dd1b684651f0 first modify
a1f43041d7975f4061b2a450b090e815afaf2614 hello lzic
4.版本回退
在git bash输入下列加粗命令
Administrator@PC-20161105AYNF MINGW32 /e/git/project1 (master)
$ git reset --hard 1232 下划线是版本号的前几位数
HEAD is now at 1232797 first modify
Administrator@PC-20161105AYNF MINGW32 /e/git/project1 (master)
$ cat test.txt
hello lzic
this is my first modify 内容已变为回退的版本
七. 将Git仓库托管到GitHub网站上。
1.创建SSH KEY
在git bash输入下列加粗命令
Administrator@PC-20161105AYNF MINGW32 /e/git/project1 (master)
$ ssh-keygen -t rsa -C "715741378@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Created directory '/c/Users/Administrator/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:CPKJD/WsWTPi/Ff6iByOijA0SSQz6AU9Ds1uEfOaKfs 715741378@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|=o=o. |
|++ Bo |
|..* =. |
|...O+= . |
| =+++ B S |
|. += = o . |
|o. * . o |
|.o. = oo. |
|. .E. =.... |
+----[SHA256]-----+
生成了这些文件。
2.注册并登陆GitHub
3.添加SSH KEY
4.创建仓库
5.本地仓库与远程仓库建立连接
在git bash输入下列加粗命令
Administrator@PC-20161105AYNF MINGW32 /e/git/project1 (master)
$ git remote add origin git@github.com:lzic/git-project1.git 下划线是工作目录GitHub名/仓库名,地址栏也可看到。
八. 把本地仓库的内容推送到GitHub仓库。
1.本地仓库的所有内容推送到到远程仓库
在git bash输入下列加粗命令
Administrator@PC-20161105AYNF MINGW32 /e/git/project1 (master)
$ git push -u origin master
Warning: Permanently added the RSA host key for IP address '192.30.253.112' to the list of known hosts.
Counting objects: 3, done.
Writing objects: 100% (3/3), 214 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote: https://github.com/lzic/git-project1/pull/new/master
remote:
To github.com:lzic/git-project1.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.