大家好,我是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 log
與 git 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!