第二次作業:分布式版本控制系統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"
$ git config --global user.email "[email protected]"
3.檢視賬戶名和郵箱位址
$ git config user.name
lzic
$ git config user.email
二. 建立工作目錄并通過git init指令把這個目錄變成Git可以管理的倉庫。
1.建立工作目錄
2.進入工作目錄
Administrator@PC-20161105AYNF MINGW32 /e
$ cd /e
$ cd git
Administrator@PC-20161105AYNF MINGW32 /e/git
$ cd project1
3.把目錄變成工作倉庫
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.檢視狀态。
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 add test.txt
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: test.txt
4.把檔案送出到倉庫
$ git commit -m " hello lzic" 下滑線指令是對版本的描述,自己命名
[master (root-commit) a1f4304] hello lzic
1 file changed, 1 insertion(+)
create mode 100644 test.txt
nothing to commit, working tree clean
五. 練習送出三個或以上的版本。
1.修改檔案内容并儲存,重複四步驟
六. 組合使用git diff、git log、git reset指令進行版本管理與回退,觀察檔案變化。
1.修改檔案内容并儲存
2.檢視工作檔案和倉庫檔案的不同
$ 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
3.檢視版本
$ git log --pretty=oneline
2413e875310ff2da0d73a24f91577045b1f0c72c second modify
1232797d243675f3b2f8d010f8d3dd1b684651f0 first modify
a1f43041d7975f4061b2a450b090e815afaf2614 hello lzic
4.版本回退
$ git reset --hard 1232 下劃線是版本号的前幾位數
HEAD is now at 1232797 first modify
$ cat test.txt
hello lzic
this is my first modify 内容已變為回退的版本
七. 将Git倉庫托管到GitHub網站上。
1.建立SSH KEY
$ ssh-keygen -t rsa -C "[email protected]"
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 [email protected]
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 remote add origin [email protected]:lzic/git-project1.git 下劃線是工作目錄GitHub名/倉庫名,位址欄也可看到。
八. 把本地倉庫的内容推送到GitHub倉庫。
1.本地倉庫的所有内容推送到到遠端倉庫
$ 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
To github.com:lzic/git-project1.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.