git extracts time interval modification files
Git is a very popular version control tool that allows us to easily manage code modifications and collaboration. And when we need to extract the modification history of a specified file within a period of time, how should we do it? Today, we will introduce how to use Git commands to extract file modification records within a time interval.
First of all, we need to understand some basic knowledge of Git:
- Git submission record
In Git, every code submission will be recorded and Save it as a commit record, that is, a commit. Each commit has a unique hash value that is used to distinguish different commit records.
- Git submission history
All submission records are saved in the Git warehouse, forming a submission history. We can use Git commands to view the submission history, including the hash value, author, submission time, modified files and other information of each submission.
- Git time interval
In Git, we can use time interval to represent a period of time. There are several ways to express time intervals, such as:
- Date: 2019-01-01
- Relative time: 2 weeks ago
- Time period: 2019-01 -01..2019-12-31
After understanding these basic knowledge, let’s explore how to extract file modification records within the time interval.
Suppose we have the following submission history:
commit 2942849f3f44e6da111d2b58fe6c24c156835c90 Author: John Doe <john@example.com> Date: Mon Feb 22 11:27:23 2021 +0800 Add README.md commit e0fdb2b0364a73f347f1a1b46c13bfbd5ac07a08 Author: John Doe <john@example.com> Date: Sat Feb 20 14:52:32 2021 +0800 Fix typo in index.html commit 71f6be88b1562fe596c69b88ac9f72dbeac78786 Author: Alice Zhang <alice@example.com> Date: Fri Feb 19 22:33:12 2021 +0800 Update index.html commit 275711456d94c307b6416d94da74e5c8b98497c7 Author: Bob Chen <bob@example.com> Date: Thu Feb 18 09:45:43 2021 +0800 Add new feature commit fd9bf6e768bb58d2a1ebf0b604805d7cca34c563 Author: Alice Zhang <alice@example.com> Date: Wed Feb 17 15:18:02 2021 +0800 Initial commit
We want to extract all modified README.md files whose submission time was between February 18th and February 21st. You can use the following command:
git log --since=2021-02-18 --until=2021-02-21 --pretty=format:"%h - %an, %ar : %s" --name-only --grep='README.md'
Command analysis:
- git log: View submission history
- --since=2021-02-18: Limit viewing only Submissions starting from 2021-02-18
- --until=2021-02-21: Limit viewing to only submissions up to 2021-02-21
- --pretty=format:" %h - %an, %ar : %s": Specify the printing format, including the submitted hash value, author, submission time and submission information
- --name-only: only display the modified file name , do not display the modified content of the file
- --grep='README.md': only search for submission records containing README.md
After executing the above command, the following output will be Result:
2942849 - John Doe, 29 minutes ago : Add README.md e0fdb2b - John Doe, 2 days ago : Fix typo in index.html
As you can see, only two submission records meet the time interval and grep conditions. If we want to see the specific files modified in these submissions, we can add a --stat option:
git log --since=2021-02-18 --until=2021-02-21 --pretty=format:"%h - %an, %ar : %s" --name-only --grep='README.md' --stat
Command analysis:
- --stat: Display the list of files modified by each submission and the overall situation of file modifications
After executing the above command, the following results will be output:
2942849 - John Doe, 29 minutes ago : Add README.md README.md | 1 + 1 file changed, 1 insertion(+) e0fdb2b - John Doe, 2 days ago : Fix typo in index.html README.md | 2 ++ 1 file changed, 2 insertions(+)
You can see that the first submission The README.md file was added, and the second submission modified the README.md file and added two lines of content.
In addition to the above methods of viewing submission history, we can also use the git blame command to view the modification history of files, including the hash value and author of the submission.
git blame README.md --since=2021-02-18 --until=2021-02-21
Command analysis:
- git blame: View the modification history of the file
- README.md: Specify the file to be viewed
- --since =2021-02-18: Limit to view only the modification history from 2021-02-18
- --until=2021-02-21: Limit to view only the modification history until 2021-02-21
After executing the above command, the following results will be output:
2942849f (John Doe 2021-02-22 11:27:23 +0800 1) This is a README file. e0fdb2b0 (John Doe 2021-02-20 14:52:32 +0800 2) It contains information about the project. e0fdb2b0 (John Doe 2021-02-20 14:52:32 +0800 3) e0fdb2b0 (John Doe 2021-02-20 14:52:32 +0800 4) Update: fix typo.
As you can see, the first and fourth lines are two different submissions, both submitted by John Doe submitted.
To summarize, we can use Git commands to extract file modification records within a time interval. These commands are easy to master and only require an understanding of some basic concepts and parameters. When we need to view the code modification history within a certain period of time, these commands can help us quickly locate the relevant submission records and view the modified files and content.
The above is the detailed content of git extracts time interval modification files. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Git is a version control system, and GitHub is a Git-based code hosting platform. Git is used to manage code versions and supports local operations; GitHub provides online collaboration tools such as Issue tracking and PullRequest.

Git and GitHub are not the same thing. Git is a version control system, and GitHub is a Git-based code hosting platform. Git is used to manage code versions, and GitHub provides an online collaboration environment.

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

GitHub is not difficult to learn. 1) Master the basic knowledge: GitHub is a Git-based version control system that helps track code changes and collaborative development. 2) Understand core functions: Version control records each submission, supporting local work and remote synchronization. 3) Learn how to use: from creating a repository to push commits, to using branches and pull requests. 4) Solve common problems: such as merge conflicts and forgetting to add files. 5) Optimization practice: Use meaningful submission messages, clean up branches, and manage tasks using the project board. Through practice and community communication, GitHub’s learning curve is not steep.

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

Git Commit is a command that records file changes to a Git repository to save a snapshot of the current state of the project. How to use it is as follows: Add changes to the temporary storage area Write a concise and informative submission message to save and exit the submission message to complete the submission optionally: Add a signature for the submission Use git log to view the submission content

Resolve: When Git download speed is slow, you can take the following steps: Check the network connection and try to switch the connection method. Optimize Git configuration: Increase the POST buffer size (git config --global http.postBuffer 524288000), and reduce the low-speed limit (git config --global http.lowSpeedLimit 1000). Use a Git proxy (such as git-proxy or git-lfs-proxy). Try using a different Git client (such as Sourcetree or Github Desktop). Check for fire protection

On your resume, you should choose to write Git or GitHub based on your position requirements and personal experience. 1. If the position requires Git skills, highlight Git. 2. If the position values community participation, show GitHub. 3. Make sure to describe the usage experience and project cases in detail and end with a complete sentence.
