How do I compare two different branches in Visual Studio Code?
Is it possible?
How do I compare two different branches in Visual Studio Code?
Is it possible?
git merge
? –
Rochellrochella copy commit hash to clipboard
feature and paste it in. –
Acriflavine F1
> gitlens: compare
is helpful if you don't like the sidebar –
Fryer Contributors
and Search & Compare
panels may be hidden. You can enable them by clicking the ellipsis menu at top of Source Control sidebar –
Lightsome git fetch --all
to fetch all remote branches? –
Antre origin/my-branch
) but won't merge the remote ref into your local copy of the branch (so comparing to my-branch
won't have the changes). Neither is particularly right or wrong, it depends exactly what you want to see. –
Dinothere Update: As of November, 2020, Gitlens appears within VSCode's builtin Source Control Panel
I would recommend to use: Git Lens.
This is possible (and much simpler) without GitLens, using only the Git Graph plugin.
With your Git Graph
open, click on the first commit you want to compare, and then Ctrl/Cmd + Click on your second commit. Both lines will be highlighted. The commit details will now display all differences between A and commit B, allowing you to compare any two commits across branches or
from the same branch.
If you just want to view the changes to a particular file between the working copy and a particular commit using GitLens, the currently accepted answer can make it difficult to find the file you're interested in if many files have changed between the versions.
Instead, if the file is open, right click on the file's tab (or, if it's not currently open, go to the file explorer in the side bar and right click on the file), then go to Commit Changes > Open Changes with Revision... (or Open Changes with Branch or Tag...).
Use the Git History Diff plugin for easy side-by-side branch diffing:
https://marketplace.visualstudio.com/items?itemName=huizhou.githd
Visit the link above and scroll down to the animated GIF image titled Diff Branch. You'll see you can easily pick any branch and do side-by-side comparison with the branch you are on! It is like getting a preview of what you will see in the GitHub Pull Request. For other Git stuff I prefer Visual Studio Code's built-in functionality or Git Lens as others have mentioned.
However, the above plugin is outstanding for doing branch diffing (i.e., for those doing a rebase Git flow and need to preview before a force push up to a GitHub PR).
UPDATE
Now it's available:
https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory
Until now it isn't supported, but you can follow the thread for it: GitHub
It's now possible by using the githistory extension.
Here's a small trick though: You can compare the latest commits from each branch and that would be the same as comparing two branches side by side or creating a PR.
Here's how to do that using githistory extension:
I typically want to compare the current checked out state with some other branch, often master
. As I like using keyboard shortcuts, the easiest way I found (compiled from the various answers already present):
master
Behind
/Ahead
to see the list of commits.
If instead you want to compare two specific branches (and not the checked out one), select 'Compare References...' in step 3. After that you can select the 2 branches/tags/commits/...
Looks like there's an update for git lens.
That's it :)
In the 11.0.0
version released in November 2020, GitLens views are now by default all placed under the source control
tab in VSCode, including the Search & Compare
view which has the compare branches functionality:
It can be changed back to the side bar layout in GitLens settings:
You can use Git tree extension
© 2022 - 2024 — McMap. All rights reserved.