開源日報 每天推薦一個 GitHub 優質開源項目和一篇精選英文科技或編程文章原文,堅持閱讀《開源日報》,保持每日學習的好習慣。
今日推薦開源項目:《瀏覽器 browser-2020》
今日推薦英文原文:《5 Git Practices for Effective Work》
開源日報第724期:《瀏覽器 browser-2020》
今日推薦開源項目:《瀏覽器 browser-2020》傳送門:GitHub鏈接
推薦理由:現在是2020年,瀏覽器依然可以做很多令人驚奇的事情。該存儲庫包含當今瀏覽器中實現的較不知名功能的詳盡列表。
今日推薦英文原文:《5 Git Practices for Effective Work》作者:W3dcos
原文鏈接:https://medium.com/better-programming/5-git-practices-for-effective-work-b612e5430bc7
推薦理由:關於Git使用的幾條建議

5 Git Practices for Effective Work

Commit early, commit often

724-1
(Photo by Aziz Acharki on Unsplash)
One of Git』s key advantages is flexibility. Git makes it possible to handle small and large projects, and enables a smoother workflow for team members. Tracking changes, maintaining the source code backup, enabling the collaboration of the team, and deploying the source code on the server with a single command are considered to be the power of Git performance.

Yet, there is lots of stuff you don』t even guess that』s essential for productive work. To increase your work efficiency and achieve better results, we suggest the following points to consider while working.

1. Make Clean Commits

Many of you, while fixing a specific bug, may spot another one and try to solve all the things in just a single git commit. Of course, this is not a good habit and can be problematic for you and your team members. Always keep in mind that fixing two different bugs should produce two separate commits. Keep the commits clean and contribute one commit for a single purpose. It will help others check your changes efficiently and make code reviews.

Also, don』t forget to write good commit messages (we have contributed a whole article on this topic). For that purpose, Git provides tools like the staging area (index) and the ability to stage only some parts of your file.

2. Commit Early and Often

Git is responsible for your data when you commit. Do not wait until you get a perfect commit. Split the feature implementation into small chunks and commit often. If you need a little bit more time to complete your work, just keep it updated with the latest changes so as not to get stuck in conflicts. If you commit early and often, you don』t lose work or revert changes, and you can trace your work while using the git reflog command. However, don』t commit a half-done code. If you want to commit just because you need a clean working copy, just use the git stash command instead!

3. Don』t Change Published History

Altering an already published history is a bad practice. Why? Let』s explain. Once a commit has been merged into an upstream branch and is visible to other programmers, it』s not recommended to change the history, to avoid conflicts. If you later find out that you litter your commit up, you can create new commits that fix the problem, for example by git revert. However, there are times when altering a published history is perhaps a normal thing, if managed well.

4. Use Aliases

Git alias is a shortcut that creates short commands mapping the longer ones. It demands a few keystrokes to run a command simplifying the programmer』s work. For example, we run:

git commit -m 「commit message」

Instead, we can type:

git c -m 「commit message」

Cutting a few letters every time will definitely save lots of time! Check out our article 7 Git Tricks to Save You Time.

5. Use Git Rebase in an Interactive Mode

There are lots of scenarios when your feature branch is ready to be integrated into the master, but a mess of commits doesn』t let you merge it.

You may have a bunch of commits in your branch, but once you want to merge it into the master, you should squash those commits into a clean commit. Git rebase interactive comes to help you with that:

git rebase — interactive <base>

Thanks to this magic mode, you can clean the history by filtering and modifying the existing sequence of commits.

To sum up, we undoubtedly can say that Git is a flexible tool that provides almost everything to make your workflow easier. It』s something like a magic world that we』re trying to dive deeper into and explore for you.


下載開源日報APP:https://openingsource.org/2579/
加入我們:https://openingsource.org/about/join/
關注我們:https://openingsource.org/about/love/