akibo
akibo

Reputation: 715

See the latest changes of a git pull?

When I ran git pull, I saw this on the terminal:

Fast-forward
 src/components/Button/index.tsx |    2 +-

How can I see what the changes are, without having to go to the browser? Is it possible to know what has been changed in the editor (I'm using vscode)?

Upvotes: 3

Views: 8435

Answers (3)

LeGEC
LeGEC

Reputation: 52036

You can view how your head commit was updated using the reflog :

$ git reflog
46f6744 (HEAD -> master, origin/master) HEAD@{0}: pull (finish): returning to refs/heads/master
46f6744 (HEAD -> master, origin/master) HEAD@{1}: pull (start): checkout 46f6744b780c1df8b0212fd297679719443874a3
e5eee0e HEAD@{2}: commit: some message
ac32fe4 HEAD@{3}: commit: some other message
...

As you can see : given the above reflog, the effect of git pull was to move HEAD from commit e5eee0e to 46f6744.

You can then view the diff between these two commits :

git diff e5eee0e 46f6744
# if you are interested in this specific file :
git diff e5eee0e 46f6744 -- src/components/Button/index.tsx

The HEAD@{xx} mentioned in the reflog is also a valid way to specify a commit :

git diff HEAD@{2} HEAD

These commands can be run from any terminal.


Note that HEAD@{2} may not the correct reference to look at in your case :
I have pull (start): ... and pull (finish): ... entries in my example because I configured pull.rebase = true on my machine ; if the pull hadn't been a fast forward, the reflog would have registed a sequence of commits being replayed, and the "previous" state could have been HEAD@{5} or HEAD@{11} or ...

Inspect your reflog to understand which was the active commit before your git pull action.

Another place of interest can be the reflog for the remote branch :
it will show you how your local view of origin/master was updated when you ran git pull

$ git reflog origin/master
46f6744 (HEAD -> master, origin/master) refs/remotes/origin/master@{0}: pull: fast-forward
e5eee0e refs/remotes/origin/master@{1}: pull: fast-forward

Upvotes: 1

LightCC
LightCC

Reputation: 11699

In Visual Studio Code, there are some extensions which will show you the specific files that changed in a tree view, and allow you to open them in a "diff view" where it shows you the original file on the left, and the updated file on the right, with green/red highlighting of the things that changed.

A few top extensions with this capability:

  • GitLens
    • opens a tree view in the side bar with commit and file information
    • adds inline "code lens" comments about recent changes to specific lines
  • Git Graph
    • Opens a separate window that shows a visual map of the repo with all the commits in all the branches

One of my standbys is outside of the editor/IDE though. If you have Windows, Git Extensions is a great option. It is an open-source, full GUI for Git that provides 99% of the available functionality of git in an easy point and click interface and visual layout of branches, commits, and files.

Upvotes: 0

Reece
Reece

Reputation: 549

You can find the difference by using the command:

git diff HEAD^1

More information about the above git command is available in this answer, or the man-page for git diff is another option.

Is it possible to know what has been changed in the editor (I'm using vscode)?

To complete the answer, there is an extension available in VSCode that is called GitLens that provides insightful information about latest commits and changes on a line-by-line basis. There are more details on the above link to the extension.

Upvotes: 2

Related Questions