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
2560
votes
16 answers

How do I show the changes which have been staged?

I staged a few changes to be committed. How do I see the diffs of all files which are staged for the next commit? Is there a handy one-liner for this? git status only shows names of files which are staged, but I want to see the actual diffs. The…
Frerich Raabe
  • 90,689
  • 19
  • 115
  • 207
2233
votes
26 answers

How can I see the changes in a Git commit?

When I do git diff COMMIT I see the changes between that commit and HEAD (as far as I know), but I would like to see the changes that were made by that single commit. I haven't found any obvious options on diff / log that will give me that output.
laktak
  • 57,064
  • 17
  • 134
  • 164
1881
votes
21 answers

How to grep (search) committed code in the Git history

I have deleted a file or some code in a file sometime in the past. Can I grep in the content (not in the commit messages)? A very poor solution is to grep the log: git log -p | grep However, this doesn't return the commit hash straight…
Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
1429
votes
24 answers

How to compare a local Git branch with its remote branch

How can I see the diff between a local branch and a remote branch?
mrblah
  • 99,669
  • 140
  • 310
  • 420
969
votes
10 answers

Given two directory trees, how can I find out which files differ by content?

If I want find the differences between two directory trees, I usually just execute: diff -r dir1/ dir2/ This outputs exactly what the differences are between corresponding files. I'm interested in just getting a list of corresponding files whose…
Mansoor Siddiqui
  • 20,853
  • 10
  • 48
  • 67
819
votes
26 answers

How do I view 'git diff' output with my preferred diff tool/ viewer?

When I type git diff, I want to view the output with my visual diff tool of choice (SourceGear "diffmerge" on Windows). How do I configure git to do this?
user3891
  • 9,101
  • 4
  • 24
  • 18
807
votes
15 answers

How to see the changes between two commits without commits in-between?

How do you make git diff only show the difference between two commits, excluding the other commits in-between?
user146069
678
votes
13 answers

Make 'git diff' ignore ^M

In a project where some of the files contain ^M as newline separators, diffing these files is apparently impossible, since git diff sees the entire file as just a single line. How does one git diff when comparing the current and previous versions of…
neoneye
  • 50,398
  • 25
  • 166
  • 151
659
votes
2 answers

How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?

I have a .diff file created by a coworker, and would like to apply the changes listed in that diff file to my local branch of the exact same repository. I do not have access to that worker's pc or branch that was used to generate this diff…
Mike_K
  • 9,010
  • 5
  • 20
  • 27
608
votes
17 answers

How to colorize diff on the command line

When I have a diff, how can I colorize it so that it looks good? I want it for the command line, so please no GUI solutions.
daniel kullmann
  • 13,653
  • 8
  • 51
  • 67
544
votes
17 answers

Compare two files in Visual Studio

I saw the new comparison tool in Visual Studio 2012 for comparing two files or two versions of a file. I like it. But when I tried to find it I couldn't it, because I don't use TFS. Is there a way how I can just compare two files with the built-in…
Libor Zapletal
  • 13,752
  • 20
  • 95
  • 182
531
votes
3 answers

How do I exit the results of 'git diff' in Git Bash on windows?

I'm using Git Bash on Windows 7. When I run git diff, I see this: However, I'm unable to get back to a regular prompt. Pressing Ctrl+C seems to work, but as soon as I start typing a command, it's covered up with (END) as in that image.
Travis Northcutt
  • 24,666
  • 9
  • 42
  • 51
492
votes
11 answers

Comparing the contents of two files in Sublime Text

I have two cloned repositories of two very similar open-source projects, which I have been working on in different instances in Sublime Text 2 to arrive at my desired result. Code from both of these projects was used. I have been using Git as…
LanceLafontaine
  • 5,680
  • 4
  • 20
  • 34
476
votes
2 answers

Git diff -w ignore whitespace only at start & end of lines

I love to use git diff -w to ignore whitespace differences. But, I just noticed that it ignores even whitespace differences in the middle of lines. How could I only ignore whitespace differences that come at the start (^) or end ($) of lines?
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
412
votes
15 answers

Exclude file from "git diff"

I am trying to exclude a file (db/irrelevant.php) from a Git diff. I have tried putting a file in the db subdirectory called .gitattributes with the line irrelevant.php -diff and I have also tried creating a file called .git/info/attributes…
Michael
  • 4,597
  • 2
  • 17
  • 16
1
2 3
99 100