🤓
Thomas lab
Git&Github
Git&Github
  • Fetching & Pulling
  • Git alias
  • Git & Github : What is in .git ?
  • Git Rebase
  • Git reflog
  • Git Stash
  • Git tags
  • Git Workflow(Collaboration)
  • Quick High-Level
  • Git diff
  • Git installer
  • Reset & Revert commit
  • Github Collaborators
  • Github Basics
  • Introducing Git
  • Merging Branch
  • How to use multiple account
Powered by GitBook
On this page
  • Comparisons With Git Diff
  • What is Git Diff ?

Git diff

PreviousQuick High-LevelNextGit installer

Last updated 8 months ago

Comparisons With Git Diff

What is Git Diff ?

Gitdiff is command-line . We can use the git diff command to view changes between commits,branches,files,our working directory and more .

We often use diff alongside commands like git status and git log , to get a better of a repository and how it has changes over time .

git diff

git diff will compares staing Area and Working Directory .

Without addtional options ,git diff list all the changes in our working directory that are NOT staged for the next commit

Git Diff HEAD

git diff HEAD list all changes in the working tree since your last commit .

What this mean?

When you use command-line git diff HEAD, it respon result :

Compared files

For each comparison , Git explains which files it is comparing .Usually this is two version of the same file .

Git also declares one file as "a" and the other as "B"

Compared Files

Files Metadata you really do not need to care about the file metadata .

The first two number are the hashes of the two files being compared.

The last number is an internal file mode identifer

Markers

File A and File B are each symbol

  • File A gets a minus sign (-)

  • File B gets a plus sign (+)

Chunks

a diff won't show the entire contents of a file , but instead only shows portions or "chunks" that were modified

A chunk also includes some unchnged lines before and after a change to provide some context

A diff won't show

Chunks Header

$$ -3,4 +3,5@@

Each chunk starts with a chunk header , found between @@ and @@

From files a , 4 lines are extracted starting from line 3

From file b , 5 liens are extracted starting from line 3

Changes

Every line that changed between the two files is marked with either a + or - symbol .

lines that begin with - come from file A

lines that begin with + come from file B

git diff

git diff --staged or --cached will list the changes between the stagin area and our last commit .

git diff --staged

git diff --cached

Diff-ing specific Files

We can view the changes within a specific file by providing with a filename

git diff HEAD [Filename]

git dif --staged [Filename]

Comparing Branches

git diff branch1...branch2

git diff branch1..branch2 will list the changes between the tips of branch1 and branch2 .

Comparing Commits

git diff commit1..commit2

To compare two commits, provide git diff with the commit hashes of the commit in question

0