Home  >  Article  >  Development Tools  >  How to check which files have been modified in git

How to check which files have been modified in git

PHPz
PHPzOriginal
2023-04-04 10:42:216706browse

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