mac azure git_在Azure Data Studio中使用Git组件

mac azure git

This article gives an insight into the terms in the Git repository of Azure Data Studio. In the previous articles, we learned the following things:

本文深入介绍了Azure Data Studio的Git存储库中的术语。 在前面的文章中,我们了解了以下内容:

As you know, Git provides a version control system to track changes in your scripts. It is a shared repository in which team members can view, modify, and commit their changes. It is useful to know the components of Git repositories.

如您所知,Git提供了一个版本控制系统来跟踪脚本中的更改。 它是一个共享的存储库,团队成员可以在其中查看,修改和提交其更改。 了解Git存储库的组件很有用。

Git存储库组件和工作流程 (Git repositories components and workflow)

It has three main components – Working directory, staging area, and local repository. In the below screenshot, it shows all changes move from the Working directory -> Staging area-> Local repository.

它具有三个主要组件– 工作目录,暂存区本地存储库 。 在下面的屏幕快照中,它显示了所有从工作目录->暂存区域->本地存储库更改

Git repositories components

Let’s explore these areas in detail.

让我们详细探讨这些领域。

工作目录或树 (The Working directory or tree)

It is the area where our scripts exist. In Git, we can also call it an untracked area. It means that if you make any changes in your script, Git marks them in the Working tree but do not explicitly save it. You may lose your changes at this point because Git is not tracking your changes. We need to instruct Git to track and save these changes.

这是我们的脚本存在的区域。 在Git中,我们也可以将其称为未跟踪区域。 这意味着,如果您在脚本中进行了任何更改,Git都会在工作树中将其标记出来,但不会显式保存。 此时您可能会丢失更改,因为Git尚未跟踪您的更改。 我们需要指示Git跟踪并保存这些更改。

In the Azure Data Studio, open the integrated terminal for PowerShell commands. In this terminal, run the command Git Status.

在Azure Data Studio中,打开PowerShell命令的集成终端。 在此终端中,运行命令Git Status。

In the output, you get a message nothing to commit, working tree clean.

在输出中,您没有得到任何消息可提交,工作树干净了。

The Working directory or tree

It shows that Git does not have any tracked file that is being modified. It also tells you about the Git branch. By default, Git uses the master branch.

它显示Git没有任何正在修改的跟踪文件。 它还告诉您有关Git分支的信息。 默认情况下,Git使用master分支。

Now, add a new script in the repository folder we initiated earlier. Rerun the git status command. It is a new file that does not exist before the last commit. It is an untracked file, so in the output of git status, it gives you information for the untracked files as well. Git does not automatically include in the commit snapshots.

现在,在我们先前启动的存储库文件夹中添加一个新脚本。 重新运行git status命令。 这是一个新文件,在上一次提交之前不存在。 这是一个未跟踪的文件,因此在git status的输出中,它也为您提供了未跟踪的文件的信息。 Git不会自动包含在提交快照中。

Add a new script

暂存区 (Staging area)

Git starts tracking the files in the staging area. As per the above screenshot, it instructs you to run the Git add command to move the file from the working tree to the staging area. Git does not track any additional changes to these files after you added into the staging area. It requires an explicit notice to Git.

Git开始跟踪暂存区域中的文件。 按照上面的屏幕截图,它指示您运行Git add命令将文件从工作树移动到暂存区。 添加到暂存区域后,Git不会跟踪对这些文件的任何其他更改。 它需要明确通知Git。

Let’s add the file into the staging area using the below command.

让我们使用以下命令将文件添加到暂存区域。

git add “filename”

git添加“文件名”

You need to specify the file name in double-quotes, or else it won’t add the files. Once you add the file, notice that Git shows the file under the staged changes.

您需要在双引号中指定文件名,否则它不会添加文件。 添加文件后,请注意,Git在分阶段的更改下显示了该文件。

Staging area

Hover the mouse over icon A, and you get index added message in the pop-up.

将鼠标悬停在图标A上,您会在弹出窗口中看到添加索引的消息。

Pop up message

Rerun the git status command. It shows the changes that need to be committed. Git now tracks the file in the staged area.

重新运行git status命令。 它显示了需要提交的更改。 Git现在在暂存区域中跟踪文件。

git status

Let’s modify this file that is in the staging area but not yet committed. I added the highlighted line and made some errors in this script knowingly. It immediately shows the number of errors in this file.

让我们修改暂存区域中但尚未提交的文件。 我添加了突出显示的行,并故意在此脚本中犯了一些错误。 它立即显示此文件中的错误数。

Number of errors

Modify the script to remove any syntax errors. You do not see the number of errors now in the below screenshot.

修改脚本以删除任何语法错误。 在下面的屏幕快照中,您现在看不到错误数量。

Modify the script

Save your changes and check the output of git status. You see two entries for the same file.

保存更改并检查git status的输出。 您会看到同一文件的两个条目。

Save script changes

所做更改: (Changes to be committed:)

It is the file version we moved from the working tree to the staged area.

这是我们从工作树移动到暂存区的文件版本。

Changes to be committed
更改未上演以提交 (Changes not staged for commit )

We modified the file in the staged area. Git does not track the changes in the staged area until we explicitly ask Git to do so.

我们在暂存区中修改了文件。 在我们明确要求Git这样做之前,Git不会跟踪工作区中的更改。

Changes not staged for commit

We can run again the Git add command to move the changes as well from the working tree to the staged area.

我们可以再次运行Git add命令,将更改也从工作树移动到暂存区域。

Git add command

Now, in the git status command output, you get the only row for the changes to be committed. It is the tracked version of the script.

现在,在git status命令输出中,您仅获得要提交的更改的行。 它是脚本的跟踪版本。

git status command

查看未上演的更改 (View the changes that are not staged )

Suppose we want to view the changes that are not staged yet. We performed the changes in the working tree area.

假设我们要查看尚未上演的更改。 我们在工作树区域中进行了更改。

For this purpose, we can use command git diff without any arguments. Git diff command compares the working directory and staging area files. In the below screenshot, we removed a line from the script in the working area. The staged copy of this file has this line added. Therefore, we get the difference in these scripts as the changes not staged.

为此,我们可以使用不带任何参数的git diff命令。 Git diff命令比较工作目录和暂存区文件。 在下面的屏幕截图中,我们在工作区的脚本中删除了一行。 此文件的暂存副本已添加此行。 因此,由于未进行更改,因此我们在这些脚本中得到了不同。

View the changes that are not staged in Azure Data Studio

Similarly, we can use argument –staged in the git diff command to view staged changes that will go in the next commit.

同样,我们可以在git diff命令中使用–staged参数来查看将在下一次提交中进行的分段更改。

git diff command

本地存储库 (The Local Repository)

The local repository contains the version of the file after you performed a commit operation. It is the final version that is saved in the Git. You can move the items from the staging area to the local repository using the git commit command. In the Azure Data Studio, you can also use Command Palette -> Git commit for this purpose.

执行提交操作后,本地存储库包含文件的版本。 它是保存在Git中的最终版本。 您可以使用git commit命令将项目从登台区域移动到本地存储库。 在Azure Data Studio中,您也可以为此使用Command Palette-> Git commit

This command gathers all changes in the staging area tracked) and puts them in the local repository. A commit command is similar to a Checkpoint command in SQL Server. Once it moved the changes to the local repository, you do not see any item in the staging area.

此命令将在跟踪的暂存区域中收集所有更改,并将它们放入本地存储库中。 提交命令类似于SQL Server中的Checkpoint命令。 将更改移到本地存储库后,您在暂存区域中看不到任何项目。

Execute the git command in the terminal, and it opens the following window. You need to enter the commit message in this window.

在终端中执行git命令,它将打开以下窗口。 您需要在此窗口中输入提交消息。

The Local Repository

To insert the commit message, press I and enter. It changes the prompt to Insert, as shown below.

要插入提交消息,请按I并输入。 它将提示更改为插入,如下所示。

Commit message

Use arrow keys to take the cursor to a specific position and enter your commit message.

使用箭头键将光标移至特定位置,然后输入提交消息。

Save changes

To save this file, press ESC followed by wq. WQ stands for write and quit.

要保存此文件,请按ESC,然后按wq 。 WQ代表写和退出。

Insert commit record

After the commit, check the output of the git status command. It says that your branch is ahead of ‘Rajendra/master’ by 1 commit.

提交后,检查git status命令的输出。 它说您的分支比“ Rajendra / master”要早1次提交。

Difference in Git and GitHub commit

In the previous article, we integrated the GitHub cloud-based repository without the Git repository in the Azure data studio. Git commit performs the commit in the local repository. It does not sync it with the GitHub repository.

在上一篇文章中,我们在Azure数据工作室中集成了基于GitHub云的存储库,而没有Git存储库。 Git commit在本地存储库中执行提交。 它不会与GitHub存储库同步。

To verify it, open the GitHub repository and check the actual items. In this article, we added a new file, “SERVERPROPERTY Resource DB.sql”, but it is not available in the GitHub as shown below.

要验证它,请打开GitHub存储库并检查实际项目。 在本文中,我们添加了一个新文件“ SERVERPROPERTY Resource DB.sql”,但该文件在GitHub中不可用,如下所示。

Open the GitHub repository

We have already linked Git repository with GitHub, but it is not in sync; that’s why we get the message – your branch is ahead by 1 commit.

我们已经将Git存储库与GitHub链接了,但是它不是同步的。 这就是我们收到消息的原因-您的分支比1次提交领先。

We can either use Azure Data Studio command palette – > Git Sync or use the command git push for it. It compares the Git local repository and GitHub repository and starts synchronization. It does not take sync any changes from the Git working tree or stage area.

我们可以使用Azure Data Studio 命令面板–> Git Sync,也可以使用命令git push 。 它比较Git本地存储库和GitHub存储库并开始同步。 它不会同步来自Git工作树或舞台区域的任何更改。

Git Sync

Refresh the GitHub web browser, and you get the additional file that we used in this article. It also shows the commit message we inserted earlier.

刷新GitHub Web浏览器,您将获得本文中使用的其他文件。 它还显示了我们之前插入的提交消息。

Commit message in GitHub

Click on the file name and view its content.

单击文件名并查看其内容。

View file content

Let’s go back to the Azure Data Studio terminal and run git status. It still shows a change not staged for commit. Previously, we removed a line in the working tree but did not move the change to the staged area. It is still in the working tree, although we performed the git commit activity.

让我们回到Azure Data Studio终端并运行git status。 它仍然显示未上演提交的更改。 以前,我们在工作树中删除了一条线,但没有将更改移到暂存区域。 尽管我们执行了git commit活动,它仍然在工作树中。

ADS terminal

To commit this change, do the following steps

要提交此更改,请执行以下步骤

  • Run a git add “filename” command

    运行git add“文件名”命令
  • Run a git commit command and specify a commit message

    运行git commit命令并指定提交消息
  • Run a git push command to sync changes with the GitHub repository

    运行git push命令以将更改与GitHub存储库同步

Now, you can see the updated commit message in GitHub.

现在,您可以在GitHub中查看更新的提交消息。

Updated record

The script in GitHub is also modified to reflect the last commit.

GitHub中的脚本也被修改以反映最后的提交。

the last commit

Now, in the git status, it shows the message – nothing to commit, working tree clean.

现在,在git状态下,它会显示消息-无需提交,工作树将清除。

nothing to commit

We completed the cycle of moving the changes from Working tree-> staged area-> local repository -> GitHub

我们完成了将更改从工作树->暂存区域->本地存储库-> GitHub移出的周期

Overall data flow

结论 (Conclusion)

In this article, we explored the useful components of Git – Working tree, Staging area, and repository. We learned the lifecycle of items moving through these components and synchronization with GitHub using Git commands. I hope it gives you get a good understanding of git integration in Azure Data Studio. Stay tuned to learn more about Git in my upcoming articles.

在本文中,我们探讨了Git的有用组件- 工作树暂存区存储库 。 我们了解了项目在这些组件中移动以及使用Git命令与GitHub同步的生命周期。 我希望它能使您对Azure Data Studio中的git集成有很好的了解。 请继续关注我的后续文章,以了解有关Git的更多信息。

目录 (Table of contents)

The SQL Server Assessment Extension for Azure Data Studio
Source Control using Git in Azure Data Studio (ADS)
Integrating Azure Data Studio with Git and GitHub
Working with Git components in Azure Data Studio
适用于Azure Data StudioSQL Server评估扩展
在Azure Data Studio(ADS)中使用Git进行源代码控制
将Azure Data Studio与Git和GitHub集成
在Azure Data Studio中使用Git组件

翻译自: https://www.sqlshack.com/working-with-git-components-in-azure-data-studio/

mac azure git

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值