search
HomeDevelopment ToolsgitHow to check which files have been modified in git

Git is a distributed version control system widely used in software development and management. In Git, we can save the historical status of the project as different versions in the code base to facilitate tracking and management of code modifications. If you are developing with Git, then you may encounter some situations where you need to view modified files. So, this article will briefly introduce several Git methods to view modified files.

  1. git diff command

Git provides the git diff command, which is used to display the difference between the modified files in the current working directory and the submitted version. To use it, enter the following command in the terminal:

git diff

This will display all file changes you have made in the working directory. The output format is as follows:

diff --git a/file1 b/file1  
index 5d522b5..e7ce8f8 100644  
--- a/file1  
+++ b/file1  
@@ -1,6 +1,6 @@  
 This is some code.  
   
 Lorem ipsum dolor sit amet,  
-consectetur adipiscing elit.  
+consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.  
   
 Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

The above output shows the differences in the file1 file. The second line "index 5d522b5 to e7ce8f8" represents the version history of the file. In line 6 of the file, "-" represents the old version, where the content of "adipiscing elit" has been deleted; and " " represents the new version, where "sed do eiusmod tempor incididunt ut labore" has been added et dolore magna aliqua."

  1. git show command

The git show command can display the changes in the specified commit. It can be used to view modified files in a certain commit. By default, we look at the latest commit. The usage is as follows:

git show

You can also view a specific commit by using the SHA-1 value of the commit. As shown below:

git show 5d522b5

This command will output the contents of the file modified in the commit with a SHA-1 value of 5d522b5.

  1. git log command

The git log command is used to view the commit history. It can display basic information about all commits, such as committer, commit date, SHA-1 value, and commit message. You can use the git log command to see the changes made in each commit. By default, it displays the history of all commits under the current folder. The specific usage is as follows:

git log

If you only want to view the last three submissions, you can use the following command:

git log -3
  1. git status command

The git status command is used to view changes made in the working directory. When you make any changes to files in your working directory, you can use this command to view those changes. The specific usage is as follows:

git status

This command will display uncommitted and staged file updates. Uncommitted updates are marked with a red dark color, and staged updates are marked with a green dark color.

Summary

Whether you use the git diff, git show, git log, or git status commands, these commands provide you with different ways to view modified files. Whether you're tracking commit history, viewing the latest changes, or viewing all updates in the current working directory, these commands will provide you with essential information to better manage your Git projects.

The above is the detailed content of How to check which files have been modified in git. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Why is git downloading so slowWhy is git downloading so slowApr 17, 2025 pm 04:51 PM

Causes of slow Git downloads include poor network connections, Git server problems, large files or large submissions, Git configuration issues, insufficient computer resources, and other factors such as malware. Workarounds include improving network connectivity, adjusting firewall settings, avoiding downloading unnecessary files or submissions, optimizing Git configuration, providing adequate computer resources, and scanning and removing malware.

How to update local code in gitHow to update local code in gitApr 17, 2025 pm 04:48 PM

How to update local Git code? Use git fetch to pull the latest changes from the remote repository. Merge remote changes to the local branch using git merge origin/<remote branch name>. Resolve conflicts arising from mergers. Use git commit -m "Merge branch <Remote branch name>" to submit merge changes and apply updates.

How to update code in gitHow to update code in gitApr 17, 2025 pm 04:45 PM

Steps to update git code: Check out code: git clone https://github.com/username/repo.git Get the latest changes: git fetch merge changes: git merge origin/master push changes (optional): git push origin master

How to delete branches of gitHow to delete branches of gitApr 17, 2025 pm 04:42 PM

You can delete a Git branch through the following steps: 1. Delete the local branch: Use the git branch -d <branch-name> command; 2. Delete the remote branch: Use the git push <remote-name> --delete <branch-name> command; 3. Protected branch: Use git config branch. <branch-name>.protected true to add the protection branch settings.

How to merge code in gitHow to merge code in gitApr 17, 2025 pm 04:39 PM

Git code merge process: Pull the latest changes to avoid conflicts. Switch to the branch you want to merge. Initiate a merge, specifying the branch to merge. Resolve merge conflicts (if any). Staging and commit merge, providing commit message.

How to download git projects to localHow to download git projects to localApr 17, 2025 pm 04:36 PM

To download projects locally via Git, follow these steps: Install Git. Navigate to the project directory. cloning the remote repository using the following command: git clone https://github.com/username/repository-name.git

How to create a new branch in gitHow to create a new branch in gitApr 17, 2025 pm 04:33 PM

Steps to create a new branch in Git: 1. Make sure to be in the root of the Git repository; 2. Enter the command git branch < Branch Name> to create a branch; 3. (Optional) Use git checkout < Branch Name> to switch to a new branch.

How to generate public keys for gitHow to generate public keys for gitApr 17, 2025 pm 04:30 PM

How to generate a Git public key? Simply follow these steps: Open a terminal or command prompt; run the ssh-keygen -t rsa -b 4096 command; select the key saving location; enter a key phrase (optional); verify that the key has been created; copy the public key; add the public key to Git.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function