git优秀开源软件_使用Git贡献开源软件

本文介绍了开源软件的重要性及贡献开源项目的好处,包括回馈社区、增强投资组合、提升技能和提升知名度。通过实例详细讲解了如何使用Git设置环境、参与开源贡献的典型工作流程,如选择项目、编写代码、单元测试、发送拉取请求等,鼓励读者加入开源世界,为开源社区贡献力量。
摘要由CSDN通过智能技术生成

git优秀开源软件

In the past decade or so, open source software has come a long way. Initially, when it came to developing enterprise level applications, engineers and developers would simply opt for proprietary software for a multitude of reasons.

在过去的十年左右的时间里,开源软件已经走了很长一段路。 最初,在开发企业级应用程序时,工程师和开发人员出于多种原因只会选择专有软件。

Such a frame of mind has shifted drastically and as things stand at present, there are a number of highly successful enterprise and commercial products built using open source software. A few cases in point would be Twitter(Rails), Github(Rails), Snappy(Laravel), Paypal(NodeJS) and countless others.

这样的思想框架已经发生了巨大变化,按照目前的情况来看,有许多使用开源软件构建的非常成功的企业和商业产品。 例如Twitter(Rails)Github(Rails)Snappy(Laravel)Paypal( NodeJS)等等。

The beauty of open source software lies in the fact that there are millions of software developers, investing their spare time to improve a single software project without even charging a cent, though there are a lot of intangible benefits to take home from it, which we will look at later in a bit of detail.

开源软件的美丽之处在于,有数以百万计的软件开发人员投入他们的业余时间来改善单个软件项目,甚至不收取任何费用,尽管可以从中获得很多无形的收益,我们稍后会详细介绍。

During the course of this tutorial, you will learn.

在本教程的过程中,您将学习。

  1. What is open source software.

    什么是开源软件。
  2. The benefits of contributing to an open source project.

    贡献给开源项目的好处。
  3. Setting up your environment before making your first contribution.

    在做出您的第一个贡献之前,先设置环境。
  4. A typical workflow to follow while making a contribution.

    做出贡献时要遵循的典型工作流程。

This tutorial assumes you have a basic knowledge of Git. It is more focused on how Git fits into the whole process.

本教程假定您具有Git的基本知识。 它更加关注Git如何适合整个过程。

了解开源软件 ( Understanding Open Source Software )

Let us first understand what is open source software and how it really works.

首先让我们了解什么是开源软件及其真正的工作原理。

I will quote an excerpt from the official open source website.

我将引用官方开源网站的摘录。

Generally, Open Source software is software that can be freely accessed, used, changed, and shared (in modified or unmodified form) by anyone. Open source software is made by many people, and distributed under licenses that comply with the The Open Source Definition.

通常,开源软件是任何人都可以自由访问,使用,更改和共享(以修改或未修改的形式)的软件。 开源软件是由许多人制作的,并根据符合“开源定义”的许可进行分发。

A better way to understand this would be to look at how the opposite of this works.

更好地理解这一点的方法是看一下与此相反的工作方式。

For the sake of argument, suppose I made a really cool blogging platform like Ghost. Since I intend to earn from it, I came up with an on-site hosting plan that my users can subscribe to host their blogs. I also throw in a few neat features like custom domains, and automatic backups.

为了争辩,假设我做了一个非常酷的博客平台,例如Ghost 。 由于我打算从中赚钱,所以我提出了一个现场托管计划,我的用户可以订阅该托管计划来托管他们的博客。 我还介绍了一些简洁的功能,例如自定义域和自动备份。

Though I can build on this and provide as many features as I like, at the heart of it, I really do not intend to make my blogging platform's source code public. If I did that, anyone could set it up on their servers for free, and modify it anyway they like.

尽管我可以在此基础上构建并提供尽可能多的功能,但从本质上讲,我并不打算公开博客平台的源代码。 如果这样做的话,任何人都可以免费在服务器上进行设置,并根据自己的喜好进行修改。

Also, since the blogging platform is my product and I have copyrighted it to myself, I have also entitled myself to a right to legal prosecution in case say, someone maliciously obtained the source code of my blogging tool.

另外,由于博客平台是我的产品,并且我已将其版权归我所有,因此,如果有人恶意获取了我博客工具的源代码,我也有权获得法律起诉权。

Sounds too complicated? I am really just getting started but I will stop it there.

听起来太复杂了吗? 我真的才刚刚开始,但是我会在那儿停下来。

Open source software works the opposite way. Under that context, I would just make the source code of my blogging platform publicly available to be used by anyone and be modified in any way.

开源软件的工作方式与此相反。 在这种情况下,我只会公开发布我的博客平台的源代码,以供任何人使用和以任何方式进行修改。

As simple as this sounds, there is still the licensing part involved.

听起来很简单,但是仍然涉及许可部分。

There are a number of licenses that you can apply to your open source projects. The most widely used is the MIT license and you can read about it if you are interested in the details.

您可以将许多许可证应用于开源项目。 使用最广泛的是MIT许可证 ,如果您对详细信息感兴趣,可以阅读它。

贡献开源软件的好处 ( Benefits of Contributing to Open Source Software )

If you are one of those who will need a little convincing before you start contributing to open source software, let us dive into the advantages right away.

如果您是在开始为开源软件做出贡献之前需要一点说服力的人之一,那么让我们立即深入了解其优势。

回馈社区的意识 (Sense of Giving Back to the Community)

Software development is a collaborative process. I can hardly imagine the software industry to be where it is today if every software developer/team worked in isolation.

软件开发是一个协作过程。 如果每个软件开发人员/团队都孤立地工作,我很难想象软件行业会像今天这样。

You use a good number of code pieces(in the form of plugins. modules, functions) written by other developers, not to mention the countless Stackoverflow threads that are just sitting there to help you out if you ever get stuck.

您使用了许多其他开发人员编写的代码段(以插件,模块,函数的形式),更不用说无数个Stackoverflow线程了,它们只是在那儿帮助您解决问题。

A software developer does consume a lot of code written by other fellow developers during his professional lifecycle and it feels really good to contribute and give back to the community that helps you in so many ways.

软件开发人员在其职业生命周期中确实消耗了许多其他开发人员编写的代码,并且做出贡献并回馈社区可以在许多方面为您提供帮助,这真的很不错。

加强您的投资组合 (Strengthening your Portfolio)

Open source projects can add a great deal of substance to your Curriculum Vitae. Imagine if David Heinemeier Hansson walked into an interview and started his introduction by saying he is the creator of the Rails framework. What kind of impact would that have on the complexion of the interview?

开源项目可以为您的简历增添许多实质。 想象一下,如果David Heinemeier Hansson接受采访并通过说他是Rails框架的创建者开始介绍他。 这会对面试的肤色产生什么样的影响?

Surely this is an exaggerated example but you get the point.

当然,这是一个夸张的例子,但您明白了。

作为开发者成长 (Growing as a Developer)

It is impossible to make an open source contribution before reading and fully understanding the available code. Diving into code written by other developers can help you expand your technical horizon and open you up to nobel programming constructs and techniques. In general, it can also help you see the bigger picture and how to go about good software design.

在阅读并完全理解可用代码之前,不可能做出开源贡献。 深入研究其他开发人员编写的代码,可以帮助您扩展技术视野并向Nobel编程结构和技术开放。 通常,它还可以帮助您看到更大的图景以及如何进行良好的软件设计。

让自己知道 (Making Yourself Known)

I think I can dub contributing to open source software as a free technical marketing campaign. Amidst all those reported issues and pull requests, one thing stands out and that is you, the person who is making all the effort.

我认为我可以作为免费的技术营销活动来为开源软件做贡献。 在所有这些已报告的问题和请求请求中,有一件事脱颖而出,那就是您,这是您正在竭尽全力的人。

Need I say more?

需要我多说?

设置环境 ( Setting up your Environment )

Before you setup the tools of the trade, I must say Git has vastly simplified the process of contributing to open source software. Yes, the open source community functioned perfectly before Git but the workflow just did not come so naturally as compared to the post-git era.

在您设置交易工具之前,我必须说, Git大大简化了为开源软件做贡献的过程。 是的,开源社区在Git之前运行良好,但与git后时代相比,工作流程并不是那么自然。

The role of Github cannot be under estimated either. It took something as beaufitul as Git and further simplified the whole process.

Github的作用也不容小estimated。 它像Git一样具有美感,并进一步简化了整个过程。

安装Git (Installing Git)

Open up your terminal and execute the following command to install Git.

打开终端并执行以下命令来安装Git。

# on OSX
$ brew install git

# on ubuntu
$ sudo apt-get install git

The brew command users Homebrew which is a package manager for OSX.

brew命令用户Homebrew是OSX的软件包管理器。

If you are on Windows, you can download an executable installer.

如果您使用的是Windows,则可以下载可执行安装程序

For information about installing Git on different distributions of Linux, you can look at the official documentation.

有关在不同Linux发行版上安装Git的信息,请参阅官方文档

配置Git (Configuring Git)

Once you have installed Git, you need to configure a few variables.

一旦安装了Git,就需要配置一些变量。

Git stores configuration in a numer of places and prioritizes it's use. If you are interested in the details, you can have a look at the official documentation.

Git将配置存储在许多地方,并优先使用它。 如果您对这些细节感兴趣,可以查看官方文档

Execute the following commands in your terminal, replacing the place holders <> with the appropriate information.

在终端中执行以下命令,将占位符<>替换为适当的信息。

$git config --global user.name "<your-username>"
# example: git config --global user.name "Noman ur Rehman"

$ git config --global user.email "<your-email>"
# example: git config --global user.email "me@example.com"

$ git config --global push.default "simple"
# sets the simple push strategy which pushes
# from local branch(of the same name) to
# the remote branch(of the same name)

$ git config --global core.editor "<path-to-your-editor>"
# example: git config --global core.editor "/Volumes/Media/Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl"

If you are more into graphical user interface tools, you can look at the Github desktop client.

如果您更喜欢图形用户界面工具,则可以查看Github桌面客户端

There are a lot of other Git configuration variables you can set but these should be enough for a start. Since Git is the only tool you need, let us now move to the contribution workflow.

您可以设置许多其他的Git配置变量,但这些对于开始来说应该足够了。 由于Git是您唯一需要的工具,因此让我们现在转到贡献工作流程。

开源贡献工作流 ( Open Source Contribution Workflow )

选择一个项目 (Selecting a Project)

There are two parts to selecting a project, the which and what. Which project do you wish to contribute to and what do you wish to contribute to it.

选择一个项目有两个部分, whichwhat 。 您希望为哪个项目做出贡献,以及您希望为什么做出贡献。

The answer to the which part can be an open source project you have used a lot over the years or simply using Github to search for your desired project. You should also take into account the code complexity when choosing a project.

一部分的答案可能是您多年来使用了很多的开源项目,或者只是使用Github搜索所需的项目。 选择项目时,还应考虑代码的复杂性。

Based on your experience, you might find it hard to get your head around a certain project. Do not take it as a setback but rather as a stepping stone. In such a case, go for something that is right down your alley and will make the ride a lot smoother.

根据您的经验,您可能会发现很难开展某个项目。 不要把它当作挫折,而要当作垫脚石。 在这种情况下,请沿着巷子里的东西走,这会使乘车更顺畅。

The answer to what can be a feature you think would be nice if added to the project you selected. You can also look into the reported issues for a project and work on resolving them. Some projects also have certain TODO comments. You can also see if you can work on these TODO items.

这个问题的答案有什么可你想,如果添加到您选择的项目将是很好的一个特征。 您还可以查看项目报告的问题并着手解决它们。 一些项目也有某些待办事项注释。 您还可以查看是否可以处理这些TODO项目。

阅读贡献指南 (Reading the Contribution Guide)

At times, the owner of the project writes a contribution guide in the wiki section or as part of the readme for the project.

有时,项目的所有者会在Wiki部分或项目自述文件的一部分中编写贡献指南。

Be sure to read it first. It is nice to follow the process outlined by them as it serves to ease up the process for both parties.

请务必先阅读。 遵循他们概述的过程很高兴,因为这有助于简化双方的过程。

进行本地复制 (Making a Local Copy)

Forking is the process of making your personal clone of the project and downloading it to your local machine.

分叉是创建您的项目的个人克隆并将其下载到本地计算机的过程。

Here is how to fork a project.

这是如何创建项目的方法。

On the project's Github page, you will notice a Fork button at the top-right corner. Simply click this button and a copy will be created under your username.

在项目的Github页面上,您会在右上角看到一个Fork按钮。 只需单击此按钮,便会在您的用户名下创建一个副本。

The next step is to copy the git url of the project which can be found under the commits/branches/releases/contributors header.

下一步是复制项目的git网址,该网址可以在commits / branches / releases / contributors标头下找到。

Once you have done that, execute the following command in the terminal.

完成此操作后,在终端中执行以下命令。

$git clone "<the-copied-git-url>" "<directory-name>"
# example: git clone "https://github.com/nomanurrehman/stripe-ruby-mock" "stripe-ruby-mock"

You now have the code copied and ready to be edited in the directory you specified.

现在,您已经复制了代码,并准备在指定目录中对其进行编辑。

All projects have a base master branch that contains the fully tested, bug free, stable code.

所有项目都有一个基本的master分支,其中包含经过全面测试,无错误的稳定代码。

You can check the branch you are currently working on by executing the following commands.

您可以通过执行以下命令来检查当前正在处理的分支。

# move to the root of your project
$ cd <directory-name>
# example: cd stripe-ruby-mock

# show branch
$ git branch

Notice that the master branched is marked with a * which means you are currently on it.

请注意,主分支标有* ,表示您当前在该分支上。

At this point, you can execute the unit tests to make sure everything is working as expected. If any of the tests fail later, they can help you identify the problem areas.

此时,您可以执行单元测试以确保一切正常。 如果以后任何测试失败,则可以帮助您确定问题区域。

编写代码 (Writing Code)

It is obvious that before you write any line of code, you must understand the project's overall design and coding constructs. It seems silly to write it down as a separate step.

显然,在编写任何代码之前,您必须了解项目的总体设计和编码结构。 单独记录下来似乎很愚蠢。

Sadly, this part is something no tutorial or magic potion can teach. It all depends on the level of expertise and experience you have overall.

可悲的是,这部分内容是任何教程或魔药都无法教的。 这完全取决于您的整体专业水平和经验。

As a rule of thumb though, majority of the projects have a single entry point. A code file at the root that calls in all the different parts to do it's work. You can slowly build your way up from there, understanding how each part and how all the parts in cohesion work.

根据经验,大多数项目只有一个入口点。 根目录中的代码文件调用所有不同的部分来完成工作。 您可以从那里慢慢建立自己的方式,了解凝聚力的每个部分以及所有部分如何工作。

Also be sure to make your commits to the development branch, merging later into the master branch when done. It is a neat practice to follow.

另外,请确保对development分支进行提交,完成后将其合并到master分支中。 遵循这种整洁的做法。

Building on from the last command you executed to check the branch, you can run these commands to switch to the development branch.

在您执行的最后一个检查分支的命令的基础上,您可以运行这些命令以切换到development分支。

# switch to development branch
$ git checkout development

You can also create a development branch if the project does not have one.

如果项目没有分支,您也可以创建一个开发分支。

# create development branch
$ git checkout -b development

Also make sure that your commits are atomic that is each commit should introduce a small change as that helps to chop and change things later if required.

还要确保您的提交是原子的,每个提交都应该引入一个小的更改,因为这有助于在以后需要时进行更改。

For example, instead of committing a whole class, make the first commit as an empty class. In the second commit, add the contructor for the class. Similarly, in a series of steps, add the class methods.

例如,不要提交整个类,而是将第一个提交作为空类。 在第二个提交中,为该类添加构造器。 同样,在一系列步骤中,添加类方法。

写作单元测试 (Writing Unit Tests)

Once you are done with writing code, writing unit tests is equally important.

一旦完成编写代码,编写单元测试同样重要。

Beware, this part can be easily over-looked and you may be a little lazy in your test coverage but be as comprehensive as you can be. Make sure to test the new code in every way possible.

当心,这部分很容易被忽略,您的测试范围可能有些懒惰,但是要尽可能全面。 确保以各种可能的方式测试新代码。

Writing unit tests is helpful because other contributors can make sure(before writing their own code) everything is working correctly by simply executing the test suite.

编写单元测试很有用,因为其他贡献者可以通过简单地执行测试套件来确保(在编写自己的代码之前)一切正常。

Based on your project's base language, the unit test framework may vary. Ruby projects mostly use RSpec whereas PHP has the PHPUnit package.

根据项目的基本语言,单元测试框架可能会有所不同。 Ruby项目主要使用RSpec,而PHP具有PHPUnit软件包。

发送拉取请求 (Sending a Pull Request)

Assuming you have written the code and the unit tests and committed all of them neatly to your development branch, you can merge the development branch into the master branch.

假设您已经编写了代码和单元测试,并将它们整齐地提交给您的development分支,则可以将development分支合并到master分支中。

# switches to master branch
$ git checkout master

# merges development into master
$ git merge development

To send a pull request, you can use Github or the command line.

要发送拉取请求,可以使用Github或命令行。

For the Github part, here is how to do it.

对于Github部分,这是操作方法。

On the project's Github page, and click the New pull request button.

在项目的Github页面上,然后单击“ 新建”拉取请求按钮。

The next page should give you an option to compare branches. Click the compare across forks. link on this page.

下一页应该给您一个比较分支的选项。 单击跨叉比较。 此页面上的链接。

You should now have the option to select the base fork and branch alongwith the head fork and branch.

现在,您应该可以选择基叉和分支以及头叉和分支。

The base fork is the repository you forked from whereas the head fork is your forked repository. Also make sure to compare the same branches from both the repositories.

基叉是您从中派生的存储库,而头叉是您从中派生的存储库。 还请确保比较两个存储库中的相同分支。

Once you have selected the base and head fork, simply click the Create pull request button.

选择了基叉和头叉后,只需单击“ 创建拉动请求”按钮。

The owner of the project will be notified of the pull request and you can wait on them for the merge or feedback comments.

项目所有者将收到拉取请求的通知,您可以等待它们进行合并或反馈注释。

合并拉取请求反馈 (Incorporating Pull Request Feedback)

At times, the owner might have feedback on the contribution you made. Maybe you missed a certain scenario in the unit tests or a function could have been written a better way.

有时,所有者可能会对您所做的贡献有反馈。 也许您错过了单元测试中的某个场景,或者可以编写一个更好的方法来编写函数。

You can read the comments on your pull request and repeat steps 4 and 5 until your contribution is accepted.

您可以阅读关于您的请求请求的注释,并重复步骤4和5,直到您的贡献被接受为止。

It could also be that while you were busy writing your code, someone else's contribution was accepted and the master branch(of the main repository) moved ahead.

也可能是在您忙于编写代码时,其他人的贡献被接受了,并且(主存储库的) master分支前进了。

In such a scenario, you will need to add the git url(as another remote) of the project(you forked from) to your local git repository and merge the respective master branches. You can find the git url of the source project just like you found the git url of the forked project in step 3.

在这种情况下,您需要将项目(从其分支)的git url(作为另一个远程对象)添加到本地git存储库,并合并各自的master分支。 您可以找到源项目的git url,就像在步骤3中找到分支的项目的git url一样。

Execute the following command to add the remote of the forked repository.

执行以下命令以添加分支存储库的远程目录。

# adds remote of forked repository
$ git remote add "<remote-name>" "<git-url>"
# example: git remote add "rebelidealist" "https://github.com/rebelidealist/stripe-ruby-mock.git" 

# pulls master from added remote
$ git pull <remote-name> master
# example: git pull rebelidealist master

Your local master branch is now updated.

您本地的master分支现已更新。

拉取请求接受和合并 (Pull Request Acceptance and Merging)

There is not much you can do for this part other than be happy and feel useful.

除了高兴和感到有用之外,您没有什么可以做的。

When your pull request is accepted, it will be marked as Merged.

当您的请求请求被接受时,它将被标记为Merged

Perhaps tweet about it and let your followers know about your contributions?

也许发推文并让您的关注者知道您的贡献?

最后的想法 ( Final Thoughts )

Open source software is all about the sense of community. It is a great feeling to know your contribution will be impacting hundreds of projects, just like contributions from fellow developers have impacted your personal and professional projects.

开源软件是关于社区意识的。 很高兴知道您的贡献将影响数百个项目,就像其他开发人员的贡献已影响您的个人和专业项目一样。

If you have an idea, provided it's somethis useful, and such an open source project is not out there, start your own. If given the right exposure, you will be surprised to see how many people are willing to contribute.

如果您有一个想法,只要有一个有用的想法,而且还没有这样的开源项目,请启动您自己的想法。 如果给予适当的曝光,您会惊讶地发现有多少人愿意捐款。

I hope you found this tutorial interesting and knowledgeable. Until my next piece, happy coding!

我希望您发现本教程有趣且知识丰富。 直到我的下一篇文章,祝您编程愉快!

翻译自: https://scotch.io/tutorials/contributing-to-open-source-software-with-git

git优秀开源软件

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值