vscode
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVS 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 CLI available in PATH.
code必须安装VS Code,且 CLI工具已添加到系统PATH中。
codeOpening 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
undefinedCompare 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
undefinedgit show :path/to/file > /tmp/staged && code -d /tmp/staged path/to/file
undefinedGotchas
注意事项
- File must exist and have changes between the compared revisions
- Use to verify file has history before diffing
git log --oneline -5 -- path/to/file
- 文件必须存在,且对比的版本之间存在变更
- 在进行对比前,可使用验证文件是否有历史记录
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变更