Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to find the difference between two arbitrary text files using Git?

Tags:

git

windows

These files are not necessarily version controlled.

I'm using Git and Git GUI on Windows XP.

like image 627
cammil Avatar asked Jan 30 '12 09:01

cammil


People also ask

Can you use git to compare 2 files?

You can compare files between two Git commits by specifying the name of the ref that refers to the commits you want to compare. A ref may be a commit ID or HEAD, which refers to the current branch. Let's compare two commits in our Git repository. The above command will perform a diff operation across our two commits.

How do I compare codes in git?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch.

How do you tell the difference in files in git bash?

The diff can be done with git diff (followed by the filename or nothing if you want to see the diff of all modified files). But if you already did something like git add * , you have to undo with git restore --staged .

How does git diff work?

Comparing changes with git diffDiffing 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.


1 Answers

You'll need to use the --no-index option unless one or both of the files are outside of a Git repository:

git diff --no-index path/to/file.txt path/to/other/file.txt

You can also use git difftool with the same arguments to invoke your GUI tool.

like image 164
32bits Avatar answered Oct 20 '22 00:10

32bits