I would like to know how to see as a file with the command git diff master origin/master in the terminal on Visual Studio Code.
I did a git fetch from my remote repository, and now I want to see the diff, but with the command just show me in the terminal.
Example of what I want:
In Visual Studio Code, on the left side, there is a Git icon that looks like this:
By clicking on this icon, then double-clicking one of the files listed under Changes you can see the Git difference in two sides.
If you want to see the diff changes from different branches, there is some extra work. For example you want to see all the changes from last N commits in your Feature branch.
Set up Visual Studio Code to be your default difftool by adding this in your ~/.gitconfig file.
[diff]
tool = vscode
[difftool "vscode"]
cmd = code --wait --diff $LOCAL $REMOTE
Go to your Git project. Type in:
git difftool {{branch you want to check with}}, for example git difftool master
You will be prompted for each file, if you want to open it in Visual Studio Code or not.
You can achieve this in Visual Studio Code by
Opening up settings (On window/linux File > Preferences > Setting.
On macOS Code > Preferences > Settings)
Search for diff
The specific setting is Diff Editor:Render Side by Side. Mark the checkbox.
After hours of searching, installing and uninstalling extensions, it seems this is already implemented in VSC.
Just click on the top right icon - "Open changes"
And go back to seeing only the file, not the changes, by clicking on the... top right icon - "Open file"
If you want to compare between two arbitrary references - for example comparing between branch and branch, or a commit and another commit - and still view all files in one shot easily just like we see the index changes.
Install the GitLens extension
Go to the Source control in the left pane.
If you don't have the icon then you can look under menu View -> SCM (Show source control) or use the defined shortcut.
Expand the last section Search & Compare
Click on button Compare References...
Pick the references, and then you will see the list of changed files and clicking one file will show its changes side to side.
I have answered a similar question here.
But basically you can use the following command:
git difftool -x "code --wait --diff"
Open file ~/.gitconfig in Visual Studio Code:
code ~/.gitconfig
Copy the following lines in ~/.gitconfig:
[diff]
tool = default-difftool
[difftool "default-difftool"]
cmd = code --wait --diff $LOCAL $REMOTE
Save the changes. Open a terminal in Visual Studio Code by running Ctrl + Shift + `. Run the following command in the terminal:
git difftool master origin/master
Here's a simple way to view your changes since last commit (on current branch):
Click Git icon on left side of VS Code
If you've made changes to the file(s) since last commit, you'll see the file(s) listed under "CHANGES"
Right click the file name (under "CHANGES") and click "Open Changes"
This will open the two versions of the file side by side with the changes highlighted
toggle inline view now is available (on the 3 dots)
You can diff any two files by first right clicking on a file in the EXPLORER or OPEN EDITORS list and selecting Select for Compare and then right-click on the second file to compare with and select Compare with <file_name_you_chose>.
Alternatively from the keyboard hit Ctrl + Shift + P and select menu File → Compare Active File With... and you will be presented with a list of recent files. Example:
Vscode itself is able to show differences between any two files:
code --diff file1.txt file2.txt
i believe this is independent from git diff feature.
For a quick single file diff view in VSCode without further integrated navigation and edit experience you can configure and use the git difftool as explained by other answers - or more safe (and global) like this:
git config --global difftool.vscode.cmd "code --wait --diff $LOCAL $REMOTE"
git config --global diff.tool vscode # optionally as default
For a fully integrated experience for such kind of custom diff in VSCode do like this:
# possibly commit or stash a dirty work tree before switching
git switch origin/master --detach # new master in worktree
git reset master # old master as detached HEAD (diff base)
Now you can see and use this "custom diff" as usual in VSCode - as a diff of worktree vs. HEAD : Use the git SCM icon, double/right-click on file changes, toggle inline diff view, etc. .
Now you can even work directly on that worktree right in the diff view. To make a commit of such changes do like:
git reset origin/master # base for added changes only
# review the bare added delta again (in VSCode)
git add/commit ...
git branch/tag my_master_fixup # name it
Then merge the new master as usual, switch back to feature branch, possibly cherry-pick the my_master_fixup, rebase or whatever ..
To make this answer work, we must follow a few steps, which, despite having been already repeated in previous answers, I'll rewrite them for sake of completeness.
Open the file ~/.gitconfig, and add the following lines:
[diff]
tool = default-difftool
[difftool "default-difftool"]
cmd = code --wait --diff $LOCAL $REMOTE
In some of the answers, the next suggested step is doing git difftool <local_branch> origin/<remote_branch>.
However, there's also another possibility:
git fetch origin <remote_branch>
git difftool FETCH_HEAD
Also, to prevent those annoying prompts from showing up, we can always do:
git config --global difftool.prompt false
From v1.48 release notes:
As you navigate the Source Control view, pressing Space on a change
will now open it as a preview editor and keep the focus in the Source
Control view, for easier keyboard navigation.
So you could downarrow through your scm file changes and hit Space to open a diff view.. Focus remains in the SCM view so you could keep doing this.
Here another way to compare against the previous versions.
On the Explorer panel.
choose a file to compare, then open context menu (right click), then choose Select for Compare.
again, open context menu, then select Open Timeline. Wait for loading previous changes.
On the Timeline tab, you can select a previous version and open the context menu and click Compare with Selected.
Then you will see diff files side by side.
I can view changes made to an individual file in git (history) from the terminal.
How do I view all changes (history) to individual files in eclipse?
From the Egit manual:
right-click Team > Show in History
That will display the graph of commits for that file.
That is the equivalent of git log
When ever I commit a file in my project the commit changes window doesn't appear but instead focus is shifted to the git staging window. How do I get the commit changes window to appear again?
Go to Preferences > Team > Git > Committing and uncheck "User Staging View to commit". Hola you will see your old favorite Commit Changes Window.
As nitind, this is mostly answered in this post:
https://waynebeaton.wordpress.com/2016/05/16/git-staging-view/
Is there a plugin or some setting in EGit to show the current git branch in the toolbar of eclipse so that it's visible on which branch you're working?
Like Sasikanth says there is no toolbar in EGit that shows the current branch.
Since there usually are multiple repositories within your IDE, a toolbar that shows the current branch of a single repository would probably often choose the wrong repository to display.
But if you have an idea how such a toolbar could work you may want to open an enhancement request.
In the meanwhile you can either use the Repositories View to see the current branch of each repsoitory or look at the Pakckage Explorer or Project Explorer. The projects are decorated with the repository they belong to and the current branch that is checked out.
Here the project belongs to the gitexample repository on branch master.
When I switch branch with non-committed changes I'm given a prompt to stash my changes:
When I switch back to the branch with the stashed changes I can't see any of the non-committed changes.
Using EGit how can I retrieve the stashed changes?
EGit 3.5 and later
In EGit 3.5 and later, there is a menu called Stashes in the Team context menu. It provides an action to stash changes and also lists any existing stashes. The same menu is also available as a toolbar icon and in the Git Repositories view:
Selecting an existing stash from the menu opens it in a viewer. The changes can be inspected and there are actions for applying the stash or deleting it:
EGit 3.4 and ealier
Open the Git Repositories view (Ctrl+3 and typing, Cmd+3 on Mac OS X)
Expand the node of the corresponding repository
Expand the Stashed Commits node
Open the context menu of the stash and select Apply Stashed Changes
In Eclipse (Luna) + eGIT, you can restore stash as