Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

git - How to compare a file in two different commits using the GUI

I refer to https://code.visualstudio.com/Docs/editor/versioncontrol#_viewing-diffs.

Is there a way to easily show a side-by-side diff of a file in two different locations, eg work tree and a specific commit, using the Code GUI?

In Source Control view, if I click on a changed file, it shows a side-by-side diff of the work tree version and (I believe) the latest commit version. Is there a way to easily select another commit?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Coming to vscode (Insiders Build v1.54) is the ability to compare a file from any two commits. It will operate using the context menu items Select for Compare and Compare with Selected opening a diff editor with the Select for Compare version on the left.

Previously, you could only compare any file version to the current version. Now you could compare versions from any two commits.

timeline compare

See https://github.com/microsoft/vscode/issues/116361#issuecomment-783524802


See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_44.md#timeline-view for v1.44 info.

In v1.43 the Timeline view is available in the standard version via the same setting mentioned below.

We've now added paging support (via Load more above), and added a relative timestamp over on the right. Extensions can also contribute menu items to the Timeline view as well as to individual timeline items. In the screenshot above, you can see that the built-in Git extension is contributing a few new commands: Copy Commit ID and Copy Commit Message.

Timeline view


The new (v1.42) Timeline view does what you want. See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_42.md#timeline-view

In this milestone, we've made progress on the new Timeline view, and have an early preview to share. This is a unified view for visualizing time-series events (for example, Git commits, file saves, test runs, etc.) for a resource (file, folder). To enable the Timeline view, you must be using the Insiders edition and then add the following setting:

"timeline.showView": true // has been removed

  • use View/Open View... instead and look for Timeline

Below you can see the Timeline view displaying the Git commit history of a file:

Timeline demo

In this early preview, the Timeline view shows the Git commit history of the active document, which is currently limited to 32 items. Selecting one of those commits will open a diff view of the changes introduced by that commit. Extensions will also be able to contribute their own timeline sources, which will be shown in this unified timeline view. Eventually, you will also be able to select (filter), which sources you'd like to see in the view.

Stay tuned, we have much more in store for this new feature. You can follow along by subscribing to issue #84297 and by watching for issues tagged with the 'timeline' label. And if you have ideas on other types of information you'd like to see in this view, let us know!


My demo: Your current file is always on the left - it doesn't look like you can alter that. So it is always current file<->pick a commit diff. Not compare two different commits to each other.

timeline demo2


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...