Intellij Idea 简明教程

Intellij Idea - Version Control

IntelliJ 支持各种版本控制系统,如 Git、Subversion、Mercurial、CVS、GitHub 和 TFS。您可以直接从 IDE 执行与版本控制相关的操作。

IntelliJ supports various version control systems like Git, Subversion, Mercurial, CVS, GitHub and TFS. You can perform version control related action from the IDE itself.

在本章中,我们将讨论 Git 和 Subversion(以下简称 SVN)。我们假设读者熟悉 Git 和 SVN 工具及其术语。

In this chapter, we will discuss Git and Subversion (hereafter referred to as SVN). We assume that the reader is familiar with Git and SVN tool and its terminology.

Git

在本节中,我们将了解如何使用 Git。

In this section, we will learn how to work with Git.

Clone

要克隆现有的 Git 仓库 −

To clone an existing Git repository −

  1. Navigate to File→New→Project from Version Control→Git.

  2. Enter the repository URL, Parent directory and Directory name.

  3. Click on the clone button to continue.

clone repository
  1. Upon successful running of the above steps, the repository will get cloned.

Track changes

Git 将跟踪你在仓库中所做的更改。让我们修改仓库中的任何文件,并将其与仓库进行比较。

Git will track the changes that you make in repository. Let us modify any file from the repository and compare it with the repository.

  1. Navigate to VCS → Git → Compare with Latest Repository Version.

  2. The above step will open the diff window.

  3. You can see there is a new line on the right side with green background colour.

  4. Git shows it in green as we have added new contents. If we remove any contents then it’ll be shown in red colour

track changes

Revert local changes

按照以下步骤放弃本地更改 −

Follow these steps to discard the local changes −

  1. Navigate to the VCS → Git → Revert option.

  2. It will ask for confirmation and remove your changes.

revert changes

Add file to repository

要将文件添加到仓库,请导航至 VCS → Git → Add option 。此操作类似于 git add 操作。

To add file to repository navigate to VCS → Git → Add option. This action is similar to the git add action.

Commit changes

提交操作将创建本地提交。它类似于 git commit 操作。要执行提交 −

The Commit operation will create local commit. It is similar to the git commit action. To perform commit −

  1. Navigate to the VCS → Git → Commit File option.

  2. Select files to be committed.

  3. Enter commit message and click on Commit button.

commit changes

Push changes to the remote repository

推送操作会将本地更改发送至远程存储库。要推送更改 −

The Push action will send local changes to the remote repository. To push changes −

  1. Navigate to the VCS → Git → Push option.

  2. A window will appear. Here, you can see the comitts to be pushed.

  3. Verify commit and click on the Push button to publish your changes.

push changes

View history or logs

要显示历史记录,请导航至 VCS → Git → Show history option 。此操作类似于 git log 命令。它将按如下所示显示历史记录 −

To show history, navigate to the VCS → Git → Show history option. This action is similar to the git log command. It will show history as follows −

view history or logs

Get updates

按照以下步骤从存储库中获取更新 −

Follow these steps to fetch updates from the repository −

  1. Navigate to the VCS → Git → Pull option.

  2. Select the option according to your requirements.

  3. Click on the Pull button.

get updates

Add existing project to Git

要在 Git 下添加现有项目 −

To add existing project under Git −

  1. Navigate to VCS → Import into Version Control → Create Git repository.

  2. Select project by browsing directory.

  3. Click on the OK button.

existing project

Subversion

在本节中,我们将了解 Subversion 在 IntelliJ 中的工作原理。让我们考虑几个重要的操作来理解这一点。

In this section, we will understand how Subversion works in IntelliJ. Let us consider a few important actions to understand this.

Checkout

签出 SVN 存储库 −

To checkout SVN repository −

  1. Navigate to File → New → Project from Version Control → Subversion.

  2. Enter repository URL.

  3. Click on the OK button.

checkout

Track changes

SVN 将跟踪您在存储库中所做的更改。让我们修改存储库中的任何文件,并将其与存储库进行比较 −

SVN will track changes you made in the repository. Let us modify any file from repository and compare it with repository −

  1. Navigate to VCS→Subversion→Compare with Latest Repository Version

  2. You can see there is new line on right side with green background colour.

  3. SVN shows it in with green background to indicated the addition of new content. If we remove any content then it will be shown in red colour.

latest repository

Revert local changes

按照以下步骤还原您所做的本地更改 −

Follow these steps to revert the local changes you have made −

  1. Navigate to the VCS → Subversion → Revert option.

  2. It will ask for confirmation and remove your changes.

remove your changes

Commit changes to remote repository

按照以下步骤提交远程仓库中的更改 −

Follow these steps to commit changes in the remote repository −

  1. Navigate to VCS → Subversion → Commit Files option.

  2. A new window will appear. Here, you can see the files to be committed to remote respository.

  3. Verify the files and click on the Commit button to publish your changes.

commit button

View history or logs

若要显示历史记录,请导航至 VCS → Subverion → Show history 选项。此选项类似于 svn log 命令。它将按以下方式显示历史记录 −

To show history, navigate to the VCS → Subverion → Show history option. This option is similar to the svn log command. It will show history as follows −

history navigate

Update operation

要获取最新更改,请导航至 VCS → Subversion → Update File/Update Folder 选项。

To fetch latest changes navigate to VCS → Subversion → Update File/Update Folder option.

update operation

Add existing project to Subversion

按照以下步骤在 SVN 下添加现有项目 −

Follow these steps to add existing project under SVN −

  1. Navigate to VCS → Import into Version Control → Import into Subverion.

  2. Enter the repository URL and click on the Import button −

add existing project