每天推薦一個 GitHub 優質開源項目和一篇精選英文科技或編程文章原文,歡迎關注開源日報。交流QQ群:202790710;微博:https://weibo.com/openingsource;電報群 https://t.me/OpeningSourceOrg
今日推薦開源項目:《視頻播放器 video.js》傳送門:GitHub鏈接
推薦理由:如果你想在你的瀏覽器上放一個視頻播放器,興許這個 video.js 就剛好合你的胃口。在開始之前你需要安裝一下 Node.js ,然後就像平時寫 HTML 一樣使用元素就可以了;它們的 Readme 上也提供了示例以供照葫蘆畫瓢,如果想做些示例以外的調整可以參考文檔。它們還提供了各種各樣的插件,包括允許視頻循環和添加播放列表之類的功能,當你需要的時候不妨查閱一下。順帶一提,這個播放器的使用量非常之大……根據排行榜上的說明大約有1/3的網站正在使用它,你可以看看這個了解詳細信息。
排行榜:https://trends.builtwith.com/media/VideoJS
今日推薦英文原文:《All You need to know about Git P2.》作者:David Hany
原文鏈接:https://medium.com/@Galoomba/all-you-need-to-know-about-git-p2-af13cd482ff2
推薦理由:這一篇也是講關於 Git 的知識的,如果你還沒有看過 P1,可以從這裡回去看看(傳送門),依然以食譜為例子介紹 Git 中的常用命令
All You need to know about Git P2.
Git Commits.
Last article we created our first commit saving the basic Burger Recipe that we loved, Check out part 1 if you missed it →https://bit.ly/2CQdPgl. Yet we didn』t help the chef to discover some new flavours without losing his old one as we promised .
It』s time to play a little with the Ingredients
For starters we will increase the quantity of eggs from 1 to 3 and add 2 cheese slices to the recipe.
We open our text editor, Editing the Recipe, Testing it out, 「yummy」.
Good. It』s ready to be committed so we open the terminal using the git add
command to add our changes to the Staging area and then git commit
to commit our changes.
Performing our second commit, We want to check if everything is alright
Using the git log
command we could view our commits history so let』s give it a shot to check if every thing is alright.
There are 2 commits, Each of them have a unique ID and a commit message that should, in short, describe the commit purpose
But by double checking the recipe we discover that we made a mistake. We misspelled cheese and that could cause misunderstanding.
It』s possible to create a new commit fixing that misspell, But we want to keep our commit history more organized to be easier to maintain. Using the command git commit --amend --no-edit
can help achieve this. The --no-edit
part stands for what we don』t want to edit out off the commit message, We can renew the commit message using -m 'new message'
instead of --no-edit
.
Checking the commit history again, We discover that we have succeeded.
But did that really work?!, Luckily there is the command git show
that shows the recent edits that happened to our file.
You can also view the difference between any two commits by using the command git diff <first commit ID> <second commit ID>
. As we have mentioned in last article we can use the first 4 digits referring to the commit ID.
The new recipe is ready but after discussion with the kitchen staff he decide to increase the white rolls from 4 to 5. So he decided to make a new commit increasing the quantity of white rolls.
But that poses an important question, When should we commit ?!
It』s good practice to make check points, And commit often as you reach one of those check points, others think that you should commit every time you have something working. whatever you choose you should always remember to commit, better safe than sorry.
Let』s check the commit history to see if everything is okay.
It』s all good and ready to be on stage. While the chef is cooking his new recipe we have to look over our commit history and think why we see the commit on top and not the one on the bottom!
The HEAD
The HEAD is typically a pointer that points to the current commit, you can change the HEAD position through many ways to check different commits.
Check out a commit
You can use the command git checkout <commit ID>
to check a commit by its ID .
For now don』t mind the note we will discuss that statement later. But as you can see it changed from master to 74e34. If you opened the BurgerRecipe by now you will be surprised that it changed to 4 white rolls instead of 5 as we committed last time.
If we run git status
to check our flow
HEAD detached, what does that mean ?!
When you run the command git checkout [commit ID]
your Git files are rolled back to the state they were in when that commit was made. HEAD will now point to the commit you specified.
Now we should check the git log
to check if there are any changes.
It looks like our 3rd commit got deleted!!
Well, it didn』t. Each commit carries a link to the previous one, with checking out the 『74e34』 commit we no longer have record to the 『b2a7de』 commit.
To return the HEAD to its position again we will check out the master. That will return the lost commit to commit history and we will discuss how it worked in the next article.
The Chef recipe is finally ready but after testing it we become aware that 4 white rolls were enough. So we wanted to reset to the second commit and forget all about the 3rd one.
We could do that by using the command git reset <option> <commit>
, I will go with --hard
as option as I don』t want anything related to the 3rd commit any more, You can check the different options in the documentation to find the one that fits your needs.
And by any chance if you are working on a file and you have messed up something and want to return back to the last commit you made you can use git reset --hard HEAD
.
So far we』ve become so familiar with how commits work and how to move forward and backward and reset to the last commit you want , Next article we will get familiar with Branches what they mean and how to use them.
→Today』s Commands
git commit --amend --no-edit
updates the last commit
git show
Show various types of objects
git diff
Show changes between commits, commit and working tree, etc
git checkout
Switch branches or restore working tree files
git reset
Reset current HEAD to the specified state
每天推薦一個 GitHub 優質開源項目和一篇精選英文科技或編程文章原文,歡迎關注開源日報。交流QQ群:202790710;微博:https://weibo.com/openingsource;電報群 https://t.me/OpeningSourceOrg
今日份git命令,get,叮!