- We can use the git diff (compares staging area and working directory) command to view changes between commits, branches, files, our working directory and more.
Structure of a git diff output:
- At first it shows the which files it is comparing. Usually this is the same file being compared.
- File MetaData
- Markers
- chunks : it shows the part that has changed.
Git Diff Commands:
- git diff - compares staging area and working directory. it tells what changes done in staging area. (before using add)
- git diff Head - lists all changes in the working tree since your last commit (staged and unstaged)
- git diff —staged or git diff —cached - This will list the changed between the staging area and our last commit
- git diff Head [File Name] / git diff —staged [FileName] - shows all the changed within a specific file.
- git diff branch1..branch2 - lists all the changes between the tips of branch1 and branch2.
- git diff branch1..branch2 [FileName] - list the changes of that file in two branches
- git diff commit1..commit2 - To compare two commits, provide git diff with the commit hashes of the commits in question.