开源日报 每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,坚持阅读《开源日报》,保持每日学习的好习惯。
今日推荐开源项目:《浏览器 browser-2020》
今日推荐英文原文:《5 Git Practices for Effective Work》

今日推荐开源项目:《浏览器 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/