vscode

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

VS Code CLI Tools

VS Code CLI 工具

Tools for integrating with VS Code, primarily for viewing diffs.
用于与VS Code集成的工具,主要用于查看文件差异。

Requirements

要求

VS Code must be installed with the
code
CLI available in PATH.
必须安装VS Code,且
code
CLI工具已添加到系统PATH中。

Opening a Diff

打开差异对比

Compare two files side by side in VS Code:
bash
code -d <file1> <file2>
在VS Code中并排比较两个文件:
bash
code -d <file1> <file2>

Git Diffs in VS Code

在VS Code中查看Git差异

Simple Approach (no config needed)

简单方法(无需配置)

Extract the old version to a temp file, then diff:
bash
undefined
将旧版本提取到临时文件,然后进行对比:
bash
undefined

Compare with previous commit

与上一次提交版本对比

git show HEAD~1:path/to/file > /tmp/old && code -d /tmp/old path/to/file
git show HEAD~1:path/to/file > /tmp/old && code -d /tmp/old path/to/file

Compare with specific commit

与指定提交版本对比

git show abc123:path/to/file > /tmp/old && code -d /tmp/old path/to/file
git show abc123:path/to/file > /tmp/old && code -d /tmp/old path/to/file

Compare staged version with working tree

对比暂存版本与工作区版本

git show :path/to/file > /tmp/staged && code -d /tmp/staged path/to/file
undefined
git show :path/to/file > /tmp/staged && code -d /tmp/staged path/to/file
undefined

Gotchas

注意事项

  • File must exist and have changes between the compared revisions
  • Use
    git log --oneline -5 -- path/to/file
    to verify file has history before diffing
  • 文件必须存在,且对比的版本之间存在变更
  • 在进行对比前,可使用
    git log --oneline -5 -- path/to/file
    验证文件是否有历史记录

When to Use

使用场景

  • Showing the user what changed in a file
  • Comparing two versions of code
  • Reviewing git changes visually
  • 向用户展示文件中的变更内容
  • 比较同一代码的两个版本
  • 以可视化方式审查Git变更