iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 8
0

Day eight
如何使用Git-如何初始化git
How to use initialise git?

Hello everyone! It’s Ray.
嗨大家好,我是Ray!

As mentioned in my the article I posted last time, Git is kind of an integral tool to coders.
Today I’m going to share the basics of Git.
如上一篇提到,Git對於一個coder來說可以說是不可或缺的,今天我就來分享一下Git的基本操作

At the first, let’s create an example folder, it could be my-git-repository.
首先呢,讓我們先來創一個範例資料夾,名稱就叫做my-git-repository吧!

Le’t go to command line
到Command Line

cd the idea patch you like for this folder
cd 你想要這個資料夾在哪的路徑/

let’s type
輸入

mkdir my-git-repository

Now type
然後

cd code/my-git-repository

to get into the folder in command line. Code is the name of my own folder, which is different from yours. Please type your own.
進到資料夾內,code是我自己的母資料夾,各位請輸入你們自己的路徑

Now we are in the folder as follows:
進到資料夾的位置,如下圖:

Let’s make a file here
讓我們在裡面建立一個檔案

touch example1.html

And then we add the content below in the file:
然後在該檔案裡面添加以下內容:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>First example</title>
</head>
<body>
<p>This is the first example</p>
</body>
</html>

Now type
輸入

git init

And then let’s type and take a look
然後輸入

git status

As image shown above, now we could start to use git’s feature.
Currently the example1 is still untracked. Remember that before we make any commit, sounds like that we have to follow those celebrities before receiving what’s new of them.
如上圖所示,我們已經可以開始使用git的相關功能,目前example1的檔案還處於untracked狀態,在建立任何存擋點之前,我們必須要先將檔案加入追蹤,就好像我們在FB上追蹤那些名人一樣!

Let’s add the file and start to track it
輸入

git add example1.html

As image below:
,如下圖:

Okay. After tracking, now we are going to make our first commit.
Enter
再來輸入

git commit

as image below:
看起來如下:

Supposedly, the new window would pop up as image below:
應該會出現以下的畫面

Now we enter the message for this commit for further better recognising.
接著我們隨便輸入first example當作這個存擋點的訊息記錄

Finally enter
接著我們按

:wq

, it means save and exit this window
儲存並離開視窗

Now let’s type
輸入

git status

, and it should look like image above.
看起來如上圖:

Enter
輸入

git log

, and you could see a series of number which represents the identify number of this commit.
然後你應該可以看到一串代表著此次commit,獨一無二的號碼。

Please note that the number varies out of the content of commit, so each commit is unique. If your commit number is different from mine, rest-assured that that’s pretty normal.
你應該會看到以下的commit,commit 的號碼每個人都不同,所以如果你的號碼跟我的不同是正常的,不用覺得奇怪!

Now we’ve completed our very first commit, and we will be able to go back to this commit whenever we need in the future.
這樣一來就算是完成了一次的存擋啦!之後我們可以隨時回到這個狀況只要我們想要的話!

Okay. Let’s call it a day! I will bring more to you in the following days
今天的分享就先到這啦,之後若有機會會再做進一步的介紹!


上一篇
為什麼我們要使用Git?
下一篇
使出git checkout!
系列文
Experience of a backend novice30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言