C Diff Explained

0 views
Skip to first unread message

Joslyn Moreci

unread,
Aug 3, 2024, 5:52:09 PM8/3/24
to lelampglimul

3d2 and 5a5 denote line numbers affected and which actions were performed. d stands for deletion, a stands for adding (and c stands for changing). the number on the left of the character is the line number in file1.txt, the number on the right is the line number in file2.txt. So 3d2 tells you that the 3rd line in file1.txt was deleted and has the line number 2 in file2.txt (or better to say that after deletion the line counter went back to line number 2). 5a5 tells you that the we started from line number 5 in file1.txt (which was actually empty after we deleted a line in previous action), added the line and this added line is the number 5 in file2.txt.

There are three types of change commands. Each consists of a linenumber or comma-separated range of lines in the first file, a singlecharacter indicating the kind of change to make, and a line number orcomma-separated range of lines in the second file. All line numbersare the original line numbers in each file. The types of changecommands are:

This command list can be run within ed when editing file1.txt in order to get the same content as file2.txt. Note that there might be more command chains that generate the same output.

Finally,If you deeply look at the output of diff file1.txt file2.txt you'll notice that is kind of a combination between commands and content that can be applied on file1.txt to generate file2.txt and vice versa.

When you need to compare two files containing similar text in Linux, using the diff command can make your task much easier. The command compares two files to suggest changes that would make the files identical. Great for finding that extra curly brace that broke your newly updated code.

It may be helpful to know that when the analysis is done, file2 [in the syntax] is treated as the reference document that you are trying to match with. So, you may say that diff works in this way:

It is much easier to understand when you see the information in this way. Instead of the alphanumeric output, the new set of symbols helps you to quickly identify the differences between the two files.

As you can see, it uses the same symbols as before, but instead of the change symbol, it suggests changes to be made using easy to read + or - symbols. Here, it recommends that you remove line 2 from 1.txt and replace it with line 2 from 2.txt.

I use git diff almost every working day to verify code changes, review teammate's code, or trace histories and find out what happened. However, I only learnt to read the raw git diff last year, when I tried to extract what function, variable or class are changed here.

If similarity index is larger than 50%, git think you renamed the file, and did some small changes. And the changs of both files would be combined in one diff block. 50% could be configured according to git document here.

?Not sure why git duplicates the information here, it only confuses people. Especially when I found both "new" or "deleted" mode will have same file path in a and b, makes it could not tell whether the file exists in both context.

Most of the information is quite straight forward, but enable to use those information in code, I have to check line by line with help of regex and convert it to JSON format like this. I used the path, operation and line number, and the location info from AST to figure out the function, variable or class changed. Hope this helps :).

DID is a quasi-experimental design that makes use of longitudinal data from treatment and control groups to obtain an appropriate counterfactual to estimate a causal effect. DID is typically used to estimate the effect of a specific intervention or treatment (such as a passage of law, enactment of policy, or large-scale program implementation) by comparing the changes in outcomes over time between a population that is enrolled in a program (the intervention group) and a population that is not (the control group).

DID is used in observational settings where exchangeability cannot be assumed between the treatment and control groups. DID relies on a less strict exchangeability assumption, i.e., in absence of treatment, the unobserved differences between treatment and control groups arethe same overtime. Hence, Difference-in-difference is a useful technique to use when randomization on the individual level is not possible. DID requires data from pre-/post-intervention, such as cohort or panel data (individual level data over time) or repeated cross-sectional data (individual or group level). The approach removes biases in post-intervention period comparisons between the treatment and control group that could be the result from permanent differences between those groups, as well as biases from comparisons over time in the treatment group that could be the result of trends due to other causes of the outcome.



This publication gives a very straightforward review of DID estimation from a health program evaluation perspective. There is also a section on best practices for all of the methods described.


This article, critiquing the DID technique, has received much attention in the field. The article discusses potential (perhaps severe) bias in DID error terms. The article describes three potential solutions for addressing these biases.


This paper offers an in-depth perspective on the DID approach and discusses some of the major issues with DID. It also provides a substantial amount of information on extensions of DID analysis including non-linear applications and propensity score matching with DID. Applicable use of potential outcome notation included in report.


These lecture slides offer practical steps to implement DID approach with a binary outcome. The linear probability model is the easiest to implement but have limitations for prediction. Logistic models require an additional step in coding to make the interaction terms interpretable. Stata code is provided for this step.

Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more. This document will discuss common invocations of git diff and diffing work flow patterns. The git diff command is often used along with git status and git log to analyze the current state of a Git repo.

If we execute git diff at this point, there will be no output. This is expected behavior as there are no changes in the repo to diff. Once the repo is created and we've added the diff_test.txt file, we can change the contents of the file to start experimenting with diff output.

The remaining diff output is a list of diff 'chunks'. A diff only displays the sections of the file that have changes. In our current example, we only have one chunk as we are working with a simple scenario. Chunks have their own granular output semantics.

The first line is the chunk header. Each chunk is prepended by a header enclosed within @@ symbols. The content of the header is a summary of changes made to the file. In our simplified example, we have -1 +1 meaning line one had changes. In a more realistic diff, you would see a header like:

The remaining content of the diff chunk displays the recent changes. Each changed line is prepended with a + or - symbol indicating which version of the diff input the changes come from. As we previously discussed, - indicates changes from the a/diff_test.txt and + indicates changes from b/diff_test.txt.

Once configured, git diff will first run the binary file through the configured converter script and diff the converter output. The same technique can be applied to get useful diffs from all sorts of binary files, for example: zips, jars and other archives: using unzip -l (or similar) in place of pdf2html will show you paths that have been added or removed between commits images: exiv2 can be used to show metadata changes such as image dimensions documents: conversion tools exist for transforming .odf, .doc and other document formats to plain text. In a pinch, strings will often work for binary files where no formal converter exists.

The git diff command can be passed an explicit file path option. When a file path is passed to git diff the diff operation will be scoped to the specified file. The below examples demonstrate this usage.

This example is scoped to ./path/to/file when invoked, it will compare the specific changes in the working directory, against the index, showing the changes that are not staged yet. By default git diff will execute the comparison against HEAD. Omitting HEAD in the example above git diff ./path/to/file has the same effect.

Invoking git diff without a file path will compare changes across the entire repository. The above, file specific examples, can be invoked without the ./path/to/file argument and have the same output results across all files in the local repo.

git diff can be passed Git refs to commits to diff. Some example refs are, HEAD, tags, and branch names. Every commit in Git has a commit ID which you can get when you execute GIT LOG. You can also pass this commit ID to git diff.

This example introduces the dot operator. The two dots in this example indicate the diff input is the tips of both branches. The same effect happens if the dots are omitted and a space is used between the branches. Additionally, there is a three dot operator:

The three dot operator initiates the diff by changing the first input parameter branch1. It changes branch1 into a ref of the shared common ancestor commit between the two diff inputs, the shared ancestor of branch1 and other-feature-branch. The last parameter input parameter remains unchanged as the tip of other-feature-branch.

This page disscused the Git diffing process and the git diff command. We discussed how to read git diff output and the various data included in the output. Examples were provided on how to alter the git diff output with highlighting and colors. We discussed different diffing strategies such as how to diff files in branches and specific commits. In addition to the git diff command, we also used git log and git checkout.

c80f0f1006
Reply all
Reply to author
Forward
0 new messages