每天推荐一个 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 .

Tip: of course you have to add the file first

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