JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM > Git >

Git diff shows diff details of uncommitted changes

Author:JIYIK Last Updated:2025/03/31 Views:

This article outlines how we can get diff details of uncommitted work in Git. We use the git diff command to show the differences between various Git references, such as commits, the index, and the working tree.

We can use this command to display details of unsubmitted work, as we will discuss below.


Show diff details of uncommitted changes in Git

For a simpler context, we will use an example. Assume that the following diagram represents the current state of the working directory in our repository.

Working Directory

Both the above files belong to the category of uncommitted work. However, the git diff command works differently on staged and unstaged files.

To see this more clearly, let's start with basic git diff with no arguments .

$ git diff

The output is as follows:

git diff no param

You'll notice that the command without arguments git diffwill only show changes to unstaged files. From the Git documentation, git diffthe command without arguments will show changes relative to the index.

These changes should go into the index but have not yet been added.

How can we show the diff details of staged files?

To show the changes in the staged files, we use the git diff command as shown below.

$ git diff --cached

Output:

git diff --cached

We can see that adding the --cached flag to our git git diffcommit command will show the diff details of the staged files. Indeed, the Git documentation states that git commit git diff --cachedwill show the staged changes relative to the current commit ( HEAD ).

What if we don't want to run the commands individually?

To display the difference details of the staged and unstaged changes, run the git diff command as shown below.

$ git diff HEAD

Output:

git diff HEAD

git diff HEADThe command will display the differences between your working directory and the current commit.

hint

If you have trouble reading the diff details above, you can use a third-party diff tool like Meld.

In short, we can manipulate the git diff command to display the difference details of the uncommitted work, depending on the category of the file. We have already seen how to display the difference details of staged and unstaged files in Git.

Previous:Staging area in Git

Next: None

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

使用 Git Diff 忽略 Git 中的空格

Publish Date:2023/03/31 Views:626 Category:Git

本文将讨论如何使用 git diff 命令忽略空格。 我们使用 git diff 来比较跨分支或修订的提交、分支和文件。

在 Git 中将文件差异化为任意版本

Publish Date:2023/03/31 Views:131 Category:Git

本文讨论了如何将单个文件与 Git 中的一个版本进行比较。 如果您的存储库的某个分支中有一个文件有 30 个迭代,您可以将当前版本与任何其他版本进行比较。

Git diff 显示未提交更改的差异详细信息

Publish Date:2023/03/30 Views:274 Category:Git

本文概述了我们如何在 Git 中获取未提交工作的差异详细信息。 我们使用 git diff 命令来显示各种 Git 引用之间的差异,例如提交、索引和工作树。

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial