How to compare working copy, intermediate copy and copied file copy using git

Suppose I have a file in the LICENSE.txt repository. The content is as follows:

Copyright 2014 MyCompany. All Rights Reserved. 

Since my 2015, I changed the year to 2015:

 Copyright 2015 MyCompany. All Rights Reserved. 

And then put the file

 git add LICENSE.txt 

Being slightly distracted, I made another change to LICENSE.txt to reflect that another organization is sharing copyright.

 Copyright 2015 MyCompany and Affiliates. All Rights Reserved. Copyright 2015 Other Company. All Rights Reserved. 

I can see the difference between my working copy and phased copy by running

 git diff 

And I can see the difference between a phased copy and a copied copy by running

 git diff --cached 

How to compare a perfect copy (without changing the year) with a working copy (with additional copyright)?

This is just an example. There are cases that are much more difficult when I had to compare what I put with the changes that I subsequently made to the file. A comparison of the contents of the working copy and the phased copy will determine whether I should replace the supplied copy or not.

I am running git 1.9.5 on Windows Server 2012 R2.

+9
source share
2 answers

How to compare a phased copy (with a change in the year) with a working copy.
[...] I needed to compare what I put with the changes that I subsequently made in the file

It will still be git diff .

(edit OP: how to compare received copy (with year change) with working copy

Then it will be git diff HEAD .)

http://images.abizern.org.s3.amazonaws.com/365git/Feb11/Git%20Diff%202.png

( 365git: getting the difference between a working tree and other commits )

If you are looking for something other than git diff and diff --cached , this leaves you with:

 git diff HEAD 

That is: the difference between the already completed version and the working tree.

+26
source
  • git diff - Compare workspace with index.
  • git diff --staged - Compare the area of ​​the scene with the repository.
  • git diff HEAD - Compare workspace with repository

To illustrate this, I modified the file with the text "Name Staged" and then added it (git add.). After that, I changed the file again, now I replaced the text with "Workspace Name" and then run the following commands:

enter image description here

Now you can clearly see how this works. Pretty cool, right?

+6
source

All Articles