Questions tagged [diff]

The act of identifying differences between two or more files in order to support various software development activities (bug tracking, patch creation, ...)

During the development of an application it is often necessary to determine the differences between two or more files -- this activity is commonly referred as diff (see for example this entry in The Jargon File).

These are some of the scenarios for diff activities:

  • in version control systems, diff is used to understand what has changed between two revisions or changeset, in order to track down bugs or assess which tests to run;
  • diff is an important part of merge operations, where the developers compares two or more version of the same files and decides how to fix conflicting changes;
  • the output of a diff activity can be "exported" in a patch file, a compact representation that permits to reapply the changes in a later moment to a different copy of the code. Patch are often used in contributing to open source software.

This tag is used for questions related to diff activities, diff tools and their use in the context of software development.

See also "Wikipedia File_comparison".

Related tags:

4623 questions
409
votes
14 answers

How to diff one file to an arbitrary version in Git?

How can I diff a file, say pom.xml, from the master branch to an arbitrary older version in Git?
Chris K
  • 11,996
  • 7
  • 37
  • 65
396
votes
9 answers

Diff files present in two different directories

I have two directories with the same list of files. I need to compare all the files present in both the directories using the diff command. Is there a simple command line option to do it, or do I have to write a shell script to get the file listing…
Sudar
  • 18,954
  • 30
  • 85
  • 131
384
votes
11 answers

Fast way of finding lines in one file that are not in another?

I have two large files (sets of filenames). Roughly 30.000 lines in each file. I am trying to find a fast way of finding lines in file1 that are not present in file2. For example, if this is file1: line1 line2 line3 And this is…
Niels2000
  • 4,027
  • 3
  • 16
  • 15
370
votes
12 answers

Can I use git diff on untracked files?

Is it possible to ask git diff to include untracked files in its diff output, or is my best bet to use git add on the newly created files and the existing files I have edited, then use: git diff --cached ?
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
368
votes
21 answers

Compare two MySQL databases

I'm currently developing an application using a MySQL database. The database-structure is still in flux and changes while development progresses (I change my local copy, leaving the one on the test-server alone). Is there a way to compare the two…
Vincent Ramdhanie
  • 102,349
  • 23
  • 137
  • 192
356
votes
13 answers

What is the Windows equivalent of the diff command?

I know that there is a post similar to this : here. I tried using the comp command like it mentioned, but if I have two files, one with data like "abcd" and the other with data "abcde", it just says the files are of different sizes. I wanted to know…
wittythotha
  • 3,956
  • 4
  • 19
  • 18
355
votes
4 answers

Download Github pull request as unified diff

How can I download the changes contained in a Github pull request as a unified diff?
Thilo
  • 257,207
  • 101
  • 511
  • 656
349
votes
9 answers

Fastest way to tell if two files have the same contents in Unix/Linux?

I have a shell script in which I need to check whether two files contain the same data or not. I do this a for a lot of files, and in my script the diff command seems to be the performance bottleneck. Here's the line: diff -q $dst $new >…
JDS
  • 16,388
  • 47
  • 161
  • 224
337
votes
6 answers

How to read the output from git diff?

The man page for git-diff is rather long, and explains many cases which don't seem to be necessary for a beginner. For example: git diff origin/master
poseid
  • 6,986
  • 10
  • 48
  • 78
321
votes
4 answers

How can I expand/collapse a diff sections in Vimdiff?

I've started using vimdiff today, and wanted to do some of the things that I've taken for granted on Windows based diff editors (like expand/collapse a diff section, have full file expansion/only diffs with three context lines above or below, etc.).…
TCSGrad
  • 11,898
  • 14
  • 49
  • 70
314
votes
7 answers

diff to output only the file names

I'm looking to run a Linux command that will recursively compare two directories and output only the file names of what is different. This includes anything that is present in one directory and not the other or vice versa, and text differences.
barfoon
  • 27,481
  • 26
  • 92
  • 138
302
votes
5 answers

How to apply `git diff` patch without Git installed?

How can my client apply patch created by git diff without git installed? I have tried to use patch command but it always asks file name to patch.
Andrey Kuznetsov
  • 11,640
  • 9
  • 47
  • 70
295
votes
14 answers

Find the files existing in one directory but not in the other

I'm trying to find the files existing in one directory but not in the other, I tried to use this command: diff -q dir1 dir2 The problem with the above command that it finds both the files in dir1 but not in dir2 as well as the files in dir2 but not…
Error404
  • 6,959
  • 16
  • 45
  • 58
292
votes
5 answers

Git diff between current branch and master but not including unmerged master commits

I want a diff of all changes in a branch that is not merged to master yet. I tried: git diff master git diff branch..master git diff branch...master However, in each of these cases the diff contains content in master that has not been merged into…
pillarOfLight
  • 8,592
  • 15
  • 60
  • 90
275
votes
6 answers

Create patch or diff file from git repository and apply it to another different git repository

I work on WordPress based project and I want to patch my project at each new release version of WP. For this, I want generate a patch between two commits or tags. For example, in my repo /www/WP I do this: $ git patch-format com1..com2 --stdout >…
zatamine
  • 3,458
  • 3
  • 25
  • 33