bitbucket创建代码

tech2022-09-21  77

bitbucket创建代码

This article was sponsored by Bitbucket. Thank you for supporting the sponsors who make SitePoint possible.

本文由Bitbucket赞助。 感谢您支持使SitePoint成为可能的赞助商。

目的 (Objective)

Learn how to use pull requests for code review with Git by adding an inspirational quote to a teammate’s repository.

通过在队友的存储库中添加鼓舞人心的报价,了解如何使用请求请求进行Git代码审查。

任务简介 (Mission Brief)

You’ve started getting the grasp of Git with a repository you own. But what if your team is off traveling the universe, and you want to be able to collaborate on the same repo? Complete this tutorial to learn the ropes of code review.

您已经开始拥有自己的存储库来掌握Git。 但是,如果您的团队准备离开宇宙旅行,并且希望能够在同一个仓库上进行协作,该怎么办? 完成本教程,学习代码复习的精髓。

Topics covered:

涵盖的主题:

Forking a teammate’s repository, creating a pull request, and contributing to a teammate’s repository.

分叉队友的存储库,创建拉取请求,并为队友的存储库做出贡献。 TimeAudiencePrerequisites15 minutesYou have some experience using Bitbucket Cloud. If not, try out one of our beginner tutorials.You have installed Git  You have a Bitbucket account 时间 听众 先决条件 15分钟 您有使用Bitbucket Cloud的经验。 如果没有,请尝试我们的初学者教程之一 。 您已经安装了Git 您有一个Bitbucket帐户

关于分叉 (About Forking)

When you work with another user’s public Bitbucket repository, typically you have read access to the code but not write access. This is where the concept of forking comes in. Here’s how it works:

当您使用另一个用户的公共Bitbucket存储库时,通常您具有对代码的读取访问权限,但没有写访问权限。 这就是派生概念出现的地方。它的工作方式如下:

Fork the repository to copy it to your own account.

分叉存储库以将其复制到您自己的帐户。 Clone the forked repository from Bitbucket to your local system.

将分叉的存储库从Bitbucket克隆到本地系统。 Make changes to the local repository.

对本地存储库进行更改。 Push the changes to your forked repository on Bitbucket.

将更改推送到Bitbucket上的分叉存储库中。 Create a pull request from the original repository you forked to add the changes you made.

从派生的原始存储库创建一个拉取请求,以添加所做的更改。 Wait for the repository owner to accept or reject your changes.

等待存储库所有者接受或拒绝您的更改。

If a repository owner accepts the pull request, Bitbucket merges your code changes into the original repository. It is recommended that you work with forks and pull requests, even if the repository owner gives you write access to a public repository. While a pull is part of the Git and Mercurial workflow, pull requests and forks are concepts used only by repository hosting services — like Bitbucket.

如果存储库所有者接受拉取请求,Bitbucket会将您的代码更改合并到原始存储库中。 即使存储库所有者为您提供了对公共存储库的写访问权限,也建议您使用fork和pull请求。 拉取是Git和Mercurial工作流程的一部分,拉取请求和派生是仅由存储库托管服务(例如Bitbucket)使用的概念。

分叉队友的资料库 (Fork a Teammate’s Repository)

Since everyone on your team is not in the Bitbucket space station all at the same time, one of your team members decided it would be a neat idea to gather some inspiring quotes that anyone can refer to, whether they are making plans for the new space station on Saturn’s rings or adventuring out to a new solar system! Your teammate started up a repository with the thought that anyone can contribute and inspire. You decide that you have a quote you want to add.

由于您团队中的每个人都不在同一时间在Bitbucket空间站中,因此您的团队中的一个成员认为,收集一些启发性的报价以供所有人参考,无论他们是否正在制定新的太空计划,都是一个好主意站在土星环上或冒险探索新的太阳系! 您的队友以任何人都可以贡献和启发的思想为基础建立了一个存储库。 您决定自己有一个要添加的报价。

In this example you’ll fork a public repository belonging to a user called tutorials.

在本示例中,您将创建一个属于tutorials的用户的公共存储库。

Depending on which DVCS tool you are using, use the search field in the top right corner of Bitbucket to find one of the following repositories:

根据所使用的DVCS工具,使用Bitbucket右上角的搜索字段来查找以下存储库之一:

For Git, search for the tutorials/tutorials.git.bitbucket.org repository.

对于Git,请搜索tutorials / tutorials.git.bitbucket.org存储库。

For Mercurial, search for the tutorials/tutorials.bitbucket.org repository.

对于Mercurial,请搜索tutorials / tutorials.bitbucket.org存储库。

From the repository you open, click Fork on the left side of the screen. The system displays the fork page.

在打开的存储库中,单击屏幕左侧的Fork 。 系统显示分叉页面。

Change the Name for example, to myteamquotes.

例如,将名称更改为myteamquotes 。

In the Description field, enter Inspiring quotes for my team.

在说明字段中, Inspiring quotes for my team输入Inspiring quotes for my team 。

Uncheck Inherit repository user/group permissions.

取消选中“ 继承存储库用户/组权限” 。

Press Fork repository.

按Fork存储库 。

复制您的Fork并更改到存储库 (Copy Your Fork & Make a Change to the Repository)

Have you figured out what piece of advice you want to share with your teammates yet? Let’s get a copy of the forked repository to your local system so that you can add it.

您是否想过要与队友分享哪些建议? 让我们将分叉存储库的副本复制到本地系统,以便您可以添加它。

我正在使用Git! (I’m using Git!)

步骤1.将fork克隆到本地系统 (Step 1. Clone your fork to your local system)

From the Overview page of the forked repository in Bitbucket, click Clone on the left side. The system displays a pop-up clone dialog. By default, the clone dialog sets the protocol to HTTPS unless you have already set up SSH for Git.

从Bitbucket中分支的存储库的“ 概述”页面中,单击左侧的“ 克隆 ”。 系统显示一个弹出克隆对话框。 默认情况下,除非您已经为Git设置了SSH,否则克隆对话框会将协议设置为HTTPS 。

From the pop-up clone dialog, copy the highlighted clone command.

在弹出的克隆对话框中,复制突出显示的克隆命令。

From your terminal window, change the directory to your repositories directory.

在终端窗口中,将目录更改为repositories目录。

$ cd ~/repos

Paste the command you copied from Bitbucket onto the command line and press Return.

将您从Bitbucket复制的命令粘贴到命令行,然后按Return键。

Enter your Bitbucket password when the terminal asks for it. This is the password you entered when you created your Bitbucket account. If you created an account by linking to Google or Facebook, use your password for that account. At this point, your terminal window should look similar to this:

在终端要求时输入您的Bitbucket密码。 这是您创建Bitbucket帐户时输入的密码。 如果您通过链接到Google或Facebook创建了一个帐户,请使用该帐户的密码。 此时,您的终端窗口应类似于以下内容:

$ cd ~/repos $ git clone https://emmap1@bitbucket.org/emmap1/myteamquotes.git Cloning into 'myteamquotes'... Password remote: Counting objects: 15, done. remote: Compressing objects: 100% (15/15), done. remote: Total 15 (delta 4), reused 0 (delta 0) Unpacking objects: 100% (15/15), done. Checking connectivity... done.

You now have the forked repository on your local system.

现在,您在本地系统上有了分叉的存储库。

步骤2.对存储库源进行更改 (Step 2. Make a change to the repository source)

This repository contains a website that has an editme.html file. This file lists inspirational quotes for your space teammates. Now, it is your turn to record an inspirational quote… or just a favorite quote. Do the following to contribute to this repository:

该存储库包含一个具有editme.html文件的网站。 该文件列出了您的太空队友的励志名言。 现在,轮到您记录鼓舞人心的报价……或只是一个喜欢的报价。 请执行以下操作以对此存储库做出贡献:

Use Google or some other search engine to locate your favorite quote.

使用Google或其他搜索引擎找到您喜欢的报价。 Navigate to the directory folder containing your repository files (something like ~/repos/myteamquotes).

导航到包含您的存储库文件的目录文件夹(类似于〜/ repos / myteamquotes)。 Open the editme.html file with a text editor.

使用文本编辑器打开editme.html文件。

Go ahead and add a quote of your choosing. You can add an image link to your quote if you like, just place it above the <blockquote> tag.

继续添加您选择的报价。 您可以根据需要将图像链接添加到报价中,只需将其放在<blockquote>标记上方即可。

Here is a sample of what an addition will look like:

这是添加物外观的示例:

<!-- Please don't edit above or below this line. To add a quote, copy the div below and paste it at the bottom of the file. Then populate it with your quote and attribution. <div class="quote"> <blockquote>Your quote goes here</blockquote> <cite>Attribution</cite> </div> You can add an optional image tag. The image must be linked from an external site and not be in the repository. <img src="http://your_image_link.jpg"> <!--Please don't edit above this line.> <div class="quote"> <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b9/Steve_Jobs_Headshot_2010-CROP.jpg/245px-Steve_Jobs_Headshot_2010-CROP.jpg"> <blockquote>Put a dent in the universe.</blockquote> <cite>Steve Jobs</cite> </div>

If you are not sure what to do, you can copy the example tags at the top of the file, paste them just below the last quote on the page, and modify them with your quote, as shown in the preceding example.

如果不确定该怎么做,则可以将示例标签复制到文件顶部,将其粘贴在页面上最后一个引号的下面,然后用引号对其进行修改,如前面的示例所示。

Save and close the file.

保存并关闭文件。

From your terminal window, change the directory to myteamquotes.

在终端窗口中,将目录更改为myteamquotes 。

$ cd ~/repos/myteamquotes

Display the status of the repository with git status.

使用git status显示存储库的git status 。

$ git status On branch master Your branch is up-to-date with 'origin/master'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: editme.html no changes added to commit (use "git add" and/or "git commit -a")

If you added an image file, you will see that file as well.

如果添加了图像文件,则也会看到该文件。

Add your changes locally with git add:

使用git add在本地添加更改:

$ git add editme.html

Commit your changes locally with git commit:

使用git commit在本地提交更改:

$ git commit -m "Making a change" [master 83bc100] Making a change 1 file changed, 10 insertions(+), 5 deletions(-)

Enter git push to push the changes to your Bitbucket fork, and enter your password to finish pushing changes.

输入git push将更改推送到您的Bitbucket分支,然后输入密码以完成推送更改。

$ git push origin master Counting objects: 3, done. Delta compression using up to 8 threads. Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 340 bytes | 0 bytes/s, done. Total 3 (delta 2), reused 0 (delta 0) To https://emmap1@bitbucket.org/emmap1/myteamquotes.git 7479b42..83bc100 master -> master Branch master set up to track remote branch master from origin.

Log into your Bitbucket repository and notice you can see your push in the activity stream.

登录到您的Bitbucket存储库,注意您可以在活动流中看到您的推送。

我正在使用SourceTree! (I’m using SourceTree!)

步骤1.将fork克隆到本地系统 (Step 1. Clone your fork to your local system)

From the Overview page of the forked repository in Bitbucket, click the Clone in SourceTree icon.

从Bitbucket中分支的存储库的Overview页面中,单击Clone in SourceTree图标。

Click the Clone in SourceTree button from the popup that appears.

在出现的弹出窗口中单击“ 在SourceTree中克隆”按钮。

From the Clone New window, update the Destination Path to <local directory>/repos/myteamquotes/. This destination path refers to the repos directory you just previously created for repositories.

在“ 复制新窗口”中,将“ 目标路径”更新为<local directory>/repos/myteamquotes/ 。 此目标路径引用您之前为存储库创建的存储库目录。

Click the Clone button.

单击克隆按钮。

步骤2.对存储库源进行更改 (Step 2. Make a change to the repository source)

This repository contains a website that has an editme.html file. This file lists inspirational quotes for your space teammates. Now, it is your turn to record an inspirational quote… or just a favorite quote. Do the following to contribute to this repository:

该存储库包含一个具有editme.html文件的网站。 该文件列出了您的太空队友的励志名言。 现在,轮到您记录鼓舞人心的报价……或只是一个喜欢的报价。 请执行以下操作以对此存储库做出贡献:

Use Google or some other search engine to locate your favorite quote.

使用Google或其他搜索引擎找到您喜欢的报价。

From SourceTree, click the Show in Finder button.

在SourceTree中,单击“ Show in Finder按钮。

Open the editme.html file with a text editor.

使用文本编辑器打开editme.html文件。

Go ahead and add a quote of your choosing. You can add an image link to your quote if you like, just place it above the <blockquote> tag.

继续添加您选择的报价。 您可以根据需要将图像链接添加到报价中,只需将其放在<blockquote>标记上方即可。

Here is a sample of what an addition will look like:

这是添加物外观的示例:

<!-- Please don't edit above or below this line. To add a quote, copy the div below and paste it at the bottom of the file. Then populate it with your quote and attribution. <div class="quote"> <blockquote>Your quote goes here</blockquote> <cite>Attribution</cite> </div> You can add an optional image tag. The image must be linked from an external site and not be in the repository. <img src="http://your_image_link.jpg"> <!--Please don't edit above this line.> <div class="quote"> <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b9/Steve_Jobs_Headshot_2010-CROP.jpg/245px-Steve_Jobs_Headshot_2010-CROP.jpg"> <blockquote>Put a dent in the universe.</blockquote> <cite>Steve Jobs</cite> </div>

If you are not sure what to do, you can copy the example tags at the top of the file, paste them just below the last quote on the page, and modify them with your quote, as shown in the preceding example.

如果不确定该怎么做,则可以将示例标签复制到文件顶部,将其粘贴在页面上最后一个引号的下面,然后用引号对其进行修改,如前面的示例所示。

Save and close the file.

保存并关闭文件。

Open SourceTree and notice that your repository has Uncommitted changes.

打开SourceTree并注意您的存储库具有未提交的更改 。

Click the Commit button at the top to commit the file.

单击顶部的“提交”按钮以提交文件。

Enter the following commit message in the space provided: “Adding new quote.”

在提供的空间中输入以下提交消息:“添加新报价”。

Click the Commit button under the message box. When you switch back to the view, you see that the file has been committed but not pushed to the Bitbucket repository.

单击消息框下的提交按钮。 当您切换回视图时,您会看到文件已提交但尚未推送到Bitbucket存储库。

From SourceTree, click the Push button to push your committed changes.

在SourceTree中,单击“ 推送”按钮以推送已提交的更改。

From the dialog box that appears, click OK to push the commit to the repository.

在出现的对话框中,单击“ 确定”将提交推送到存储库。

Log into your Bitbucket repository and notice you can see your push in the activity stream.

登录到您的Bitbucket存储库,注意您可以在活动流中看到您的推送。

创建请求请求 (Create a Pull Request)

To aww and inspire your teammate’s with words of wisdom, you can request your change to get added to the original repository. To do that, you create a pull request.

要用智慧的话语来激发和激发队友的热情,您可以请求进行更改以将其添加到原始存储库中。 为此,您创建一个拉取请求。

步骤1.将叉子与原始叉子进行比较 (Step 1. Compare your fork to the original)

While you were working on adding your quote, another teammate might have made updates to the original repository. At this point, you can check that and decide if you need to adjust your fork accordingly. Do the following to compare your changes with the repository:

在您添加报价时,另一位队友可能已对原始存储库进行了更新。 此时,您可以检查并确定是否需要相应地调整前叉。 执行以下操作以将您的更改与存储库进行比较:

Log into Bitbucket and navigate to your myteamquotes repository. Forked repositories have a special widget that lets you compare your fork work to the original.

登录到Bitbucket并导航到myteamquotes存储库。 分支存储库具有一个特殊的小部件,可让您将您的叉子工作与原始工作进行比较。

Click the Compare link on the left side of the page. The Compare section has a specialized view that is available only in forked repositories.

点击页面左侧的比较链接。 比较部分具有专门的视图,该视图仅在分支的存储库中可用。

Press the Compare button to compare your forked repository to the original repository.

按下“ 比较”按钮以将您的分叉存储库与原始存储库进行比较。

If someone has made changes to the original repository since you forked it, you will see that your forked repository is one or more commits behind the original. If that is the case, to update your repository, click Sync now and then Sync on the popup that appears. If you want to see the differences between your current repository and the original repository, click the Diff tab to compare changes. If there are multiple commits, you see their cumulative changes by file in this section. Click the Side-by-side diff button to see changes displayed side-by-side. Or press the View file button to view the full file in Bitbucket.

如果自分叉以来有人对原始存储库进行了更改,您将看到您的分叉存储库是原始存储库中的一个或多个提交。 如果是这样的话,更新您的资料库,点击立即同步 ,然后同步在弹出的出现。 如果你想看到你的当前仓库和原始资料库之间的区别,请点击DIFF标签比较的变化。 如果有多个提交,则可以在本节中按文件查看它们的累积更改。 单击“ 并排差异”按钮以查看并排显示的更改。 或按“ 查看文件”按钮以查看Bitbucket中的完整文件。

Switch back to the Commits tab to see the list of commits pushed from your local repository to the fork in Bitbucket. To see the contents of a specific commit in isolation, click a Commit link and Bitbucket takes you to the Commits page.

切换回“ 提交”选项卡以查看从本地存储库推送到Bitbucket中的派生的提交列表。 要单独查看特定提交的内容,请单击“ 提交”链接,然后Bitbucket会将您带到“ 提交”页面。

步骤2.创建拉取请求 (Step 2. Create a pull request)

Now it’s time to request that your quote get added to the original repository for all to see! From your myteamquotes repository in Bitbucket, do the following:

现在是时候要求将报价添加到原始存储库中了,以供所有人查看! 从Bitbucket的myteamquotes存储库中,执行以下操作:

Press Create Pull Request. The system displays the request form.

按创建请求请求 。 系统显示申请表。

Complete the form. For your purposes today, you only have to add a Title. When you are done it will look something like this:

完成表格。 今天,您只需添加一个Title即可 。 完成后,它将看起来像这样:

Press Create pull request. The system opens your latest request on the Pull Request page of the original repository in the tutorials account. To see the list of all the pull requests against this repo, click the Pull Request tab.

按创建请求请求 。 系统将在教程帐户中原始存储库的“ 提取请求”页面上打开您的最新请求。 要查看针对此存储库的所有拉取请求的列表,请单击“ 拉取请求”选项卡。

After you create a pull request, you can’t delete it. If you delete your fork after you make a request, the receiver can only decline your request because the repository to pull from is gone.

创建拉取请求后,无法将其删除。 如果在发出请求后删除了fork,则接收者只能拒绝您的请求,因为要从中提取资源的存储库已经消失了。

第3步。了解您的请求请求会如何 (Step 3. Learn what happens to your pull request)

You have to wait for the repository owner to accept your pull request. When the original repository owner logs into Bitbucket, that user’s newsfeed shows your pull request and your fork from a few days earlier, as shown in the following image.

您必须等待存储库所有者接受您的拉取请求。 当原始存储库所有者登录到Bitbucket时,该用户的新闻提要显示几天前的拉取请求和派生,如下图所示。

When the repo owner clicks on your pull request, that user can Merge, Edit, or Decline it. In addition to owners, anyone with access to the repository can Approve the request, which means that person reviewed the changes in the pull request.

当回购所有者单击您的提取请求时,该用户可以合并 , 编辑或拒绝 。 除了所有者之外,任何有权访问存储库的人都可以批准该请求,这意味着该人已查看了拉取请求中的更改。

您已为资料库做出了贡献! (You’ve contributed to a repository!)

You’ll get an email when your pull request is accepted or rejected. If you want to try out other things in Bitbucket while you wait, check out how to enable an issue tracker, set up a wiki, or add user permissions.

当您的拉取请求被接受或拒绝时,您会收到一封电子邮件。 如果您想在等待时尝试在Bitbucket中进行其他操作,请查看如何启用问题跟踪器 , 设置Wiki或添加用户权限 。

翻译自: https://www.sitepoint.com/learn-about-code-review-in-bitbucket-cloud/

bitbucket创建代码

最新回复(0)