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.
- 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."
- 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.
- 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
- 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!

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 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.

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

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.

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.

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

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 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.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

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
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function