iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 11
0
自我挑戰組

Experience of a backend novice系列 第 11

Git log 裡面的東西是什麼? 歡迎git log --online!

  • 分享至 

  • xImage
  •  

Day eleven
Git log 裡面的東西是什麼? 歡迎git log --online!
What’s inside git log? Let’s welcome git log --oneline

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

今天想跟大家分享,git log 裡面的一些細節。
Today I am going to share with you some detail in git log

首先,我們先來看看下面的圖片:
Firstly, take a look on the image below:

我們可以看到,每一個commit後面都有一段非常長的隨機字串,那這是什麼呢?
We could see that there is a long-random-looking string on every commit, and what the heck is that?

這是一串git 根據commit的內容,由SHA1生成的隨機驗證字串,也許你會問,什麼是SHA1?
This is a checksum produced by Git with SHA1 according to the committed content, by the way, what’s SHA1?

SHA1全名為security hash algorithm, 中文意思大概就是“安全加密演算法”。
SHA is the abbreviation of “security hash algorithm”

諸如此類的演算法有好幾種,SHA系列的演算法是不可逆的,簡單來說,如果你拿到一串加密過的字串,就像上面那些驗證字串,你是沒有辦法透過將它逆轉回加密前的樣子。
There are several algorithm like this, and, moreover, SHA is not reversible, which means that if you got a hashed string like the one above, you wouldn’t be able to decode and reverse it back to the one before hashed.

有興趣的朋友可以google一下,這邊我們就不針對SHA多做討論!
If you are interested in that, you could google it. I think google serves as a better teacher than me, lol.

接下來介紹一個非常實用的指令,git log --oneline!
Now I am going to share a very very useful code! Git log --oneline

輸入git log --online
Type git log --oneline

可以對照下圖,這是git loggit log --oneline的差別。
You could see the difference between git log and git log --oneline

由上圖大家可以看到,git --oneline 拿掉了作者,日期相關資訊,並且只保留驗證字串的七碼!
As image shown above, you could see that git takes author, date information off, also only keep 7 characters from the original long-random-looking checksum.

那我們之前提到的git checkout也可以使用這七碼來作切換嗎?
So could we use git checkout that we previously mentioned to switch between different commits?

輸入git checkout out cc92d2f (請輸入你電腦上的驗證字串,你的跟我的不一樣)
The answer is yes! Type git checkout cc92d2f (please note that yours will be different from mine, so just type the one shown on your computer)

如上圖,我們已經成功的切換到前一個commit
As photo shown above, we’ve successfully switched to the previous commit

輸入 git checkout master
Type git checkout master

輸入 git log --oneline
Type git log --oneline

這樣就又切回來了!
Now we are back.

看完今天的文章,是不是對於git 有更深一層的理解了呢?
After reading through article today, do you have better understanding on Git?

我們明天見!
See you guys!


上一篇
覺得每次都要git add 以及 git commit 太麻煩了嗎? 請服用 git commit -am
下一篇
如何設置Git的個人資訊?
系列文
Experience of a backend novice30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言