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 . first.
Git Diff Between Commits 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.
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. Order does matter when you're comparing branches.
git diff
by default shows difference between your working directory and the index (staging area for the next commit).
If you have already added (staged) the changes to the staging area, git diff --staged
does the job. Staging area is the data from which the next commit will be formed by git commit
.
P. S. Good reading (IMO) for Git beginners:
What i use for such cases is:
git diff HEAD *
This will show the changes since last commit. Although somehow it works quicker with
git diff .
or
git diff
To see the changes on previously git add
ed files, use the staged
flag:
git diff --staged
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With