Skip to content
Fix Code Error

How do I diff the same file between two different commits on the same branch?

March 13, 2021 by Code Error
Posted By: Anonymous

In Git, how could I compare the same file between two different commits (not contiguous) on the same branch (master for example)?

I’m searching for a compare feature like the one in Visual SourceSafe (VSS) or Team Foundation Server (TFS).
Is it possible in Git?

Solution

From the git-diff manpage:

git diff [--options] <commit> <commit> [--] [<path>...]

For instance, to see the difference for a file “main.c” between now and two commits back, here are three equivalent commands:

$ git diff HEAD^^ HEAD main.c
$ git diff HEAD^^..HEAD -- main.c
$ git diff HEAD~2 HEAD -- main.c
Answered By: Anonymous

Related Articles

  • Custom event for Foundation 5 top bar dropdown items
  • Why call git branch --unset-upstream to fixup?
  • Why do I have to "git push --set-upstream origin "?
  • Why does git perform fast-forward merges by default?
  • How to create the branch from specific commit in…
  • Git workflow and rebase vs merge questions
  • How do I add foundation with grunt to a ember.js app…
  • Difference between git checkout --track…
  • Checkout another branch when there are uncommitted…
  • Git Using Remote Branch
  • In plain English, what does "git reset" do?
  • Why do git fetch origin and git fetch : behave differently?
  • How do I make a Git commit in the past?
  • How can I reconcile detached HEAD with master/origin?
  • Why does Git say my master branch is "already up to…
  • How to prevent scrolling the whole page?
  • How to register Foundation 5 as AMD module with Require.js
  • Error TF30063: You are not authorized to access ...…
  • Git merge master into feature branch
  • What is a tracking branch?
  • Retrieve specific commit from a remote Git repository
  • Avoid creating new session on each axios request laravel
  • Git push rejected after feature branch rebase
  • Various ways to remove local Git changes
  • git pull while not in a git directory
  • Git merge with force overwrite
  • Your configuration specifies to merge with the from…
  • Why did my Git repo enter a detached HEAD state?
  • git clone: Authentication failed for
  • Move the most recent commit(s) to a new branch with Git
  • Rebasing remote branches in Git
  • Git submodule head 'reference is not a tree' error
  • What's the difference between HEAD^ and HEAD~ in Git?
  • Git: Create a branch from unstaged/uncommitted…
  • How to cherry pick a range of commits and merge into…
  • How to recover stashed uncommitted changes
  • What exactly does the "u" do? "git push -u origin…
  • Start redis-server with config file
  • Memcached vs. Redis?
  • How do I delete a Git branch locally and remotely?
  • How do I clone a single branch in Git?
  • moving committed (but not pushed) changes to a new…
  • Git, How to reset origin/master to a commit?
  • Finding a branch point with Git?
  • What's the difference between "git reset" and "git…
  • How do I revert a Git repository to a previous commit?
  • How can I move HEAD back to a previous location?…
  • Change a Git remote HEAD to point to something…
  • git bring some "older" changes to a new branch after…
  • git lfs push to github failure on Ubuntu 18.04
  • How to pull in changes from skeleton sub-repository…
  • How to modify existing, unpushed commit messages?
  • How to find the nearest parent of a Git branch?
  • Detect if Visual C++ Redistributable for Visual…
  • What are the undocumented features and limitations…
  • Squash the first two commits in Git?
  • Interdependent properties in Vue.js
  • Aurelia is emitting different css code in Foundation…
  • Rename master branch for both local and remote Git…
  • Install Foundation 5 in ember-cli
  • How to get the changes on a branch in Git
  • Delete all local git branches
  • Git "error: The branch 'x' is not fully merged"
  • How do you get git to always pull from a specific branch?
  • VueJS Master Checkbox Toggle with array values
  • TFS - testing a common module by running builds of…
  • How do I 'overwrite', rather than 'merge', a branch…
  • Git vs Team Foundation Server
  • How to ignore files/directories in TFS for avoiding…
  • Getting NullPointerException after setting value of…
  • Apache server keeps crashing, "caught SIGTERM,…
  • How does origin/HEAD get set?
  • What is "git remote add ..." and "git push origin master"?
  • How to keep a git branch in sync with master
  • Why is processing a sorted array faster than…
  • Python - While Loops Not Appearing in Console When…
  • How can I merge two commits into one if I already…
  • Git submodule update
  • Webpack: How do I include a node module's css?
  • Merge, update, and pull Git branches without using checkouts
  • master branch and 'origin/master' have diverged, how…
  • How do you stop tracking a remote branch in Git?
  • How to merge my branch to master if some other…
  • How to update a rating sequentially?
  • What are the differences between git remote prune,…
  • Git push won't do anything (everything up-to-date)
  • Visual Studio Error: (407: Proxy Authentication Required)
  • How to revert multiple git commits?
  • Git merge branch differences
  • How to list branches that contain a given commit?
  • Vue.js + Foundation + Webpack configuration
  • Check if pull needed in Git
  • How to Detect if I'm Compiling Code with a…
  • Three.js: Cannot display mesh created with texture array
  • How can I find the location of origin/master in git,…
  • git pull from master into the development branch
  • Is it safe to shallow clone with --depth 1, create…
  • Checking out Git tag leads to "detached HEAD state"
  • How to use Visual Studio Code as Default Editor for Git
  • How to use Git Revert

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Full-screen iframe with a height of 100%

Next Post:

How do you access the matched groups in a JavaScript regular expression?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error