ezuk
ezuk

Reputation: 3196

Git diff untracked file against a tracked file in another branch/path

I have the following scenario:

  1. Current branch is feature/dashboard.

  2. I have an untracked file, tmp/dashboard_bulk.js (came from my browser)

  3. I'd like to compare it with a tracked file app/assets/javascripts/audience/dashboard_bulk.js that's on branch master (again, not my current branch).

So source file is untracked, and destination file is on a different path in a different branch.

Is there a way to do this?

Upvotes: 4

Views: 507

Answers (1)

tbekolay
tbekolay

Reputation: 18547

git diff doesn't seem to mind if you give it a path that is untracked.

The syntax for pointing to a file on a different branch is branch:path/to/file.

Putting these two together, the command to do the diff is

git diff \
master:app/assets/javascripts/audience/dashboard_bulk.js \
tmp/dashboard_bulk.js

Upvotes: 3

Related Questions