git diff vs git diff HEAD--File

Source: Internet
Author: User
Tags commit diff

Recently, I started to touch git. Learning to Git diff is always confusing. Git diff compares the difference between the two files. After searching the net on the net, finally found Le answer.

There are two cases, one is when there are files in staging area, and the other is no files in staging area.

(1) When there are no files in staging area, git diff compares the files in the workspace with the files that were last submitted to the repository.

(2) When there are files in staging area, git diff compares the files in the current workspace with those in the staging area.

git diff HEAD-file, compares the differences between the files in the workspace and the files in the repository. Head points to the current version in the repository, and file refers to the files in the current workspace.

Add: The git diff command compares the difference between the current file in the working directory and the staging area snapshot, which is a change that has not been staged since the modification.

Note: Git diff itself only shows changes that have not yet been staged, not all of the changes that have been made since the last commit. So, sometimes after you save all the updated files, you run Git diff and nothing, that's why.

If you want to see what has been staged to be added to the next commit, you can use Git diff--cached or git diff--staged.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.