IntelliJ IDEAversion控制

LearningIntelliJ IDEA version控制functions, includingGit集成, submitting and pushcode, branchmanagement, merge and conflict解决etc.advancedfunctions

1. version控制Basics

version控制 is a记录file in 容变化 system, 它可以helping你追踪file modifyhistory, restore以 before version, 以及 and team members协作Development.

1.1 version控制systemclass型

  • 本地version控制system: such asRCS, 只 in 本地保存file modifyhistory
  • 集in式version控制system: such asSVN, has 一个in央server保存所 has file modifyhistory
  • distributedversion控制system: such asGit, 每个Development者都 has 完整 versionlibraryreplica

1.2 GitIntroduction

Git is 目 before 最流行 distributedversion控制system, 它具 has 以 under 特点:

  • distributedarchitecture, 无需in央server
  • high 效 branchmanagement
  • 强 big merge and conflict解决capacity
  • 完整 history记录
  • support离线工作

1.3 IntelliJ IDEA version控制集成

IntelliJ IDEA in 置了 for Git, SVN, Mercurialetc.version控制system support. 你可以through以 under 方式启用version控制集成:

  1. 点击VCS > Enable Version Control Integration
  2. 选择version控制systemclass型, such as"Git"
  3. 点击"OK"

2. Git集成

IntelliJ IDEAproviding了强 big Git集成functions, 可以helping你 high 效地managementGit仓library.

2.1 cloneGit仓library

要cloneGit仓library, 请按照以 under 步骤operation:

  1. 点击File > New > Project from Version Control > Git
  2. 输入仓libraryURL
  3. 选择本地store位置
  4. 点击"Clone"

2.2 Gittool窗口

Gittool窗口位于IntelliJ IDEA 底部, package含以 under 主要tag:

  • Log: 显示submittinghistory
  • Console: 显示Gitcommands输出
  • Local Changes: 显示本地modify file
  • Branches: 显示所 has branch
  • Remote Branches: 显示远程branch

2.3 Gitstatus栏

Gitstatus栏位于IntelliJ IDEA right under 角, 显示当 before branch and 未submitting modify数量.

3. basicGitoperation

IntelliJ IDEAproviding了直观 界面来执行basic Gitoperation.

3.1 submittingmodify

要submittingmodify, 请按照以 under 步骤operation:

  1. 点击VCS > Commit, or using fast 捷键Ctrl + K
  2. in submitting for 话框in, 选择要submitting file
  3. 输入submittinginformation
  4. 点击"Commit" or "Commit and Push"

3.2 pushmodify

要pushmodify to 远程仓library, 请按照以 under 步骤operation:

  1. 点击VCS > Git > Push, or using fast 捷键Ctrl + Shift + K
  2. 确认要push branch and submitting
  3. 点击"Push"

3.3 pullmodify

要 from 远程仓librarypullmodify, 请按照以 under 步骤operation:

  1. 点击VCS > Git > Pull, or using fast 捷键Ctrl + T
  2. 选择要pull 远程 and branch
  3. 点击"Pull"

3.4 查看modifyhistory

要查看file modifyhistory, 请按照以 under 步骤operation:

  1. in projecttool窗口in, right 键点击file
  2. 选择"Git" > "Show History"
  3. in history窗口in查看file modifyhistory

4. branchmanagement

branch is Git corefunctions之一, 它允许你 in 不影响主branch circumstances under Development new functions or 修复bug.

4.1 查看branch

要查看所 has branch, 请按照以 under 步骤operation:

  1. 点击VCS > Git > Branches
  2. or using fast 捷键Ctrl + Shift + '
  3. in branch窗口in查看所 has 本地 and 远程branch

4.2 creationbranch

要creation new branch, 请按照以 under 步骤operation:

  1. 点击VCS > Git > Branches
  2. 点击"New Branch"按钮
  3. 输入branch名称
  4. 选择基于哪个branchcreation
  5. 点击"Create"

4.3 切换branch

要切换 to otherbranch, 请按照以 under 步骤operation:

  1. 点击VCS > Git > Branches
  2. right 键点击要切换 branch
  3. 选择"Checkout"

4.4 mergebranch

要mergebranch, 请按照以 under 步骤operation:

  1. 切换 to 要merge to branch
  2. 点击VCS > Git > Merge Changes
  3. 选择要merge branch
  4. 点击"Merge"

5. merge and conflict解决

当两个branchmodify了同一file 同一部分时, merge时就会发生conflict. IntelliJ IDEAproviding了强 big conflict解决tool.

5.1 查看conflict

发生conflict时, IntelliJ IDEA会 in 编辑器in显示conflict file, 并标记conflict 部分.

5.2 解决conflict

要解决conflict, 请按照以 under 步骤operation:

  1. in conflictfilein, 查看conflict 部分
  2. using编辑器顶部 conflict解决tool栏, 选择要保留 version:
    • Accept Left: 保留当 before branch version
    • Accept Right: 保留要mergebranch version
    • Accept Both: 保留两个version
    • Compare: 比较两个version
  3. 手动编辑file, 解决所 has conflict
  4. 点击VCS > Git > Add, 将解决conflict after file添加 to stage区
  5. submittingmerge结果

6. advancedGitfunctions

IntelliJ IDEA还providing了许 many advancedGitfunctions, helping你更 high 效地managementGit仓library.

6.1 resetsubmitting

要resetsubmitting, 请按照以 under 步骤operation:

  1. 点击VCS > Git > Reset Head
  2. 选择resetclass型:
    • Soft: 保留modify, 不modify工作Table of Contents
    • Mixed: 保留modify, modify工作Table of Contents
    • Hard: discard所 has modify, restore to 指定submitting
  3. 选择要reset to submitting
  4. 点击"Reset"

6.2 rebase

rebase is a将一个branch modifyapplication to 另一个branch method. 要执行rebase, 请按照以 under 步骤operation:

  1. 切换 to 要rebase branch
  2. 点击VCS > Git > Rebase
  3. 选择要基于哪个branchrebase
  4. 点击"Rebase"

6.3 交互式重写history

要交互式重写history, 请按照以 under 步骤operation:

  1. 点击VCS > Git > Show History
  2. right 键点击要重写 submitting
  3. 选择"Reword", "Edit", "Squash", "Fixup" or "Drop"
  4. 按照提示completion重写

6.4 Git stash

Git stash可以暂时保存未submitting modify, 以便你可以切换 to otherbranch. 要usingGit stash, 请按照以 under 步骤operation:

  1. 点击VCS > Git > Stash Changes
  2. 输入stash名称 (可选)
  3. 点击"Create Stash"
  4. 要restorestash, 请点击VCS > Git > Unstash Changes, 选择要restore stash, 点击"Apply Stash"

实践练习

请按照以 under 步骤completion练习:

  1. in GitHub or GitLab on creation一个 new Git仓library
  2. usingIntelliJ IDEAclone该仓library
  3. creation一个 new Javaclass, 并submitting to 仓library
  4. creation一个 new branch, in 该branch on modifyJavaclass
  5. 切换回主branch, modify同一个Javaclass 同一部分
  6. 尝试merge new branch to 主branch, 解决conflict
  7. push所 has modify to 远程仓library
  8. usingGit stash保存未submitting modify, 然 after restore