Skip to main content
flag colorized
Source Link
nezabudka
  • 2.5k
  • 8
  • 15

All through an example:

mkdir cdiff && cd cdiff git init cat text.txt # first comment 1 2 # midle comment 3 4 # last comment git add test.txt git commit -m 'first' 

Now let's change it in the working directory:

cat test.txt 1 2 3 # first comment # last comment 4 bye 

Create a utility:

cat /usr/local/bin/git-cdiff #!/bin/sh diff --color -u <(grep -Ev '^(#|$)' $1) <(git show $2:$1 | grep -Ev '^(#|$)') 
chmod 555 /usr/local/bin/git-cdiff 

Compare the same file from a specific commit with one in working directory:

git cdiff test.txt HEAD 

Or:

git cdiff test.txt <hash commit> 

The files are identical. Change the file in the working directory:

echo byegit >>cdiff test.txt a4ec1 git--- cdiff/dev/fd/63 test 2021-07-09 08:09:48.txt581153921 a4ec1+0300 5d4+++ /dev/fd/62 2021-07-09 08:09:48.581153921 +0300 <@@ -1,4 +1,4 @@ 1 2 +3 4 -bye 

All through an example:

mkdir cdiff && cd cdiff git init cat text.txt # first comment 1 2 # midle comment 3 4 # last comment git add test.txt git commit -m 'first' 

Now let's change it in the working directory:

cat test.txt 1 2 3 # first comment # last comment 4 

Create a utility:

cat /usr/local/bin/git-cdiff #!/bin/sh diff <(grep -Ev '^(#|$)' $1) <(git show $2:$1 | grep -Ev '^(#|$)') 
chmod 555 /usr/local/bin/git-cdiff 

Compare the same file from a specific commit with one in working directory:

git cdiff test.txt HEAD 

Or:

git cdiff test.txt <hash commit> 

The files are identical. Change the file in the working directory:

echo bye >> test.txt git cdiff test.txt a4ec1 5d4 < bye 

All through an example:

mkdir cdiff && cd cdiff git init cat text.txt # first comment 1 2 # midle comment 3 4 # last comment git add test.txt git commit -m 'first' 

Now let's change it in the working directory:

cat test.txt 1 2 # first comment # last comment 4 bye 

Create a utility:

cat /usr/local/bin/git-cdiff #!/bin/sh diff --color -u <(grep -Ev '^(#|$)' $1) <(git show $2:$1 | grep -Ev '^(#|$)') 
chmod 555 /usr/local/bin/git-cdiff 

Compare the same file from a specific commit with one in working directory:

git cdiff test.txt HEAD 

Or:

git cdiff test.txt <hash commit> 
git cdiff test.txt a4ec1 --- /dev/fd/63  2021-07-09 08:09:48.581153921 +0300 +++ /dev/fd/62 2021-07-09 08:09:48.581153921 +0300 @@ -1,4 +1,4 @@ 1 2 +3 4 -bye 
deleted 914 characters in body
Source Link
nezabudka
  • 2.5k
  • 8
  • 15

All through an example:

mkdir cdiff && cd cdiff git init cat text.txt # first comment 1 2 # midle comment 3 4 # last comment git add test.txt git commit -m 'first' 

Now let's change it in the working directory:

cat test.txt 1 2 3 # first comment # last comment 4 

Create a utility:

cat /usr/local/bin/git-cdiff #!/bin/sh diff <(grep -Ev '^(#|$)' $1) <(git show $2:$1 | grep -Ev '^(#|$)') 
chmod 555 /usr/local/bin/git-cdiff 

Compare the same file from a specific commit with one in working directory:

git cdiff test.txt HEAD 

Or:

git cdiff test.txt <hash commit> 

The files are identical. Change the file in the working directory:

echo bye >> test.txt git cdiff test.txt a4ec1 5d4 < bye 

All through an example:

mkdir cdiff && cd cdiff git init cat text.txt # first comment 1 2 # midle comment 3 4 # last comment git add test.txt git commit -m 'first' 

Now let's change it in the working directory:

cat test.txt 1 2 3 # first comment # last comment 4 

Create a utility:

cat /usr/local/bin/git-cdiff #!/bin/sh diff <(grep -Ev '^(#|$)' $1) <(git show $2:$1 | grep -Ev '^(#|$)') 
chmod 555 /usr/local/bin/git-cdiff 
git cdiff test.txt HEAD 

Or:

git cdiff test.txt <hash commit> 

The files are identical. Change the file in the working directory:

echo bye >> test.txt git cdiff test.txt a4ec1 5d4 < bye 

All through an example:

mkdir cdiff && cd cdiff git init cat text.txt # first comment 1 2 # midle comment 3 4 # last comment git add test.txt git commit -m 'first' 

Now let's change it in the working directory:

cat test.txt 1 2 3 # first comment # last comment 4 

Create a utility:

cat /usr/local/bin/git-cdiff #!/bin/sh diff <(grep -Ev '^(#|$)' $1) <(git show $2:$1 | grep -Ev '^(#|$)') 
chmod 555 /usr/local/bin/git-cdiff 

Compare the same file from a specific commit with one in working directory:

git cdiff test.txt HEAD 

Or:

git cdiff test.txt <hash commit> 

The files are identical. Change the file in the working directory:

echo bye >> test.txt git cdiff test.txt a4ec1 5d4 < bye 
deleted 914 characters in body
Source Link
nezabudka
  • 2.5k
  • 8
  • 15

It's actually simple. The main task will be to find the hash of the commit file. All through an example:

mkdir cdiff && cd cdiff git init cat text.txt # first comment 1 2 # midle comment 3 4 # last comment git add test.txt git commit -m 'first' git log commit f1dca01f4742f9a60e8297918531b0b07780ca8c (HEAD -> master) git cat-file -p f1dca tree e4e58635eceffd68a4120b36968ce795d33d3c0b git cat-file -p e4e58635 100644 blob a4ec1c614998f9e60502ae499d99834115d2da54 test.txt git cat-file -p a4ec1 # first comment 1 2 # midle comment 3 4 # last comment 

We got the contents of the first commit file.
NowNow let's change it in the working directory:

cat test.txt 1 2 3 # first comment # last comment 4 

Create a utility:

cat /usr/local/bin/git-cdiff #!/bin/sh diff <(grep -Ev '^(#|$)' $1) <(git cat-file -pshow $2:$1 | grep -Ev '^(#|$)') 
chmod 555 /usr/local/bin/git-cdiff 
git cdiff test.txt a4ec1HEAD 

Or:

git cdiff test.txt <hash commit> 

The files are identical. Change the file in the working directory:

echo bye >> test.txt git cdiff test.txt a4ec1 5d4 < bye 

It remains to come up with a code that will find hash of the file by name in the desired commit.
As an option, change the command cat-file -p to a show and specify it like this:

git cdiff test.txt HEAD:test.txt 

Or:

git cdiff test.txt f1dca:test.txt 

And if this is the same file, then with the second parameter you can specify only the indent from the head and then programmatically combine the second parameter.

It's actually simple. The main task will be to find the hash of the commit file. All through an example:

mkdir cdiff && cd cdiff git init cat text.txt # first comment 1 2 # midle comment 3 4 # last comment git add test.txt git commit -m 'first' git log commit f1dca01f4742f9a60e8297918531b0b07780ca8c (HEAD -> master) git cat-file -p f1dca tree e4e58635eceffd68a4120b36968ce795d33d3c0b git cat-file -p e4e58635 100644 blob a4ec1c614998f9e60502ae499d99834115d2da54 test.txt git cat-file -p a4ec1 # first comment 1 2 # midle comment 3 4 # last comment 

We got the contents of the first commit file.
Now let's change it in the working directory:

cat test.txt 1 2 3 # first comment # last comment 4 

Create a utility:

cat /usr/local/bin/git-cdiff #!/bin/sh diff <(grep -Ev '^(#|$)' $1) <(git cat-file -p $2 | grep -Ev '^(#|$)') 
chmod 555 /usr/local/bin/git-cdiff 
git cdiff test.txt a4ec1 

The files are identical. Change the file in the working directory:

echo bye >> test.txt git cdiff test.txt a4ec1 5d4 < bye 

It remains to come up with a code that will find hash of the file by name in the desired commit.
As an option, change the command cat-file -p to a show and specify it like this:

git cdiff test.txt HEAD:test.txt 

Or:

git cdiff test.txt f1dca:test.txt 

And if this is the same file, then with the second parameter you can specify only the indent from the head and then programmatically combine the second parameter.

All through an example:

mkdir cdiff && cd cdiff git init cat text.txt # first comment 1 2 # midle comment 3 4 # last comment git add test.txt git commit -m 'first' 

Now let's change it in the working directory:

cat test.txt 1 2 3 # first comment # last comment 4 

Create a utility:

cat /usr/local/bin/git-cdiff #!/bin/sh diff <(grep -Ev '^(#|$)' $1) <(git show $2:$1 | grep -Ev '^(#|$)') 
chmod 555 /usr/local/bin/git-cdiff 
git cdiff test.txt HEAD 

Or:

git cdiff test.txt <hash commit> 

The files are identical. Change the file in the working directory:

echo bye >> test.txt git cdiff test.txt a4ec1 5d4 < bye 
added 187 characters in body
Source Link
nezabudka
  • 2.5k
  • 8
  • 15
Loading
Source Link
nezabudka
  • 2.5k
  • 8
  • 15
Loading