How to modify the commit time in git
In git, you can use the "git commit --amend" command to modify the commit time; this method can not only modify the date of the most recent submission, but also modify the date of a specified submission, in which the format of the date It needs to be in "ISO-8601" format, and the syntax is "GIT_COMMITTER_DATE="time" git commit --amend --date="time"".
The operating environment of this article: Windows 10 system, Git version 2.30.0, Dell G3 computer.
How to modify the commit time in git
1. Modify the author date and submitter date of the most recent commit
If you want to modify the author of the most recent commit For date and submitter date, just use git commit --amend directly
Note: The date format must be ISO-8601 format
GIT_COMMITTER_DATE="2017-10-08T09:51:07" git commit --amend --date="2017-10-08T09:51:07"
2. Modify the author date of a certain submission and submitter date
If you want to change the author date and submitter date of a certain submission (it can be the most recent or non-recent), you can use interactive rebase:
Execute git rebase -i COMMIT_SHA. This COMMIT_SHA is the commit sha of the previous commit of the commit to be modified.
In the vi pop-up interactive information, change the date to be modified. The pick before commit is modified to e
Execute the date modification command GIT_COMMITTER_DATE="2017-10-08T09:51:07" git commit --amend --date="2017-10- 08T09:51:07"
Execute git rebase --continue to the next commit
Repeat this process until all commits are modified. Progress can be viewed through git status.
3. Modification example
The current git log submission information is as follows
admin@DESKTOP-PC MINGW64 /e/TestProj/ModifyTimeTest (master) $ git log --oneline 2fe64c4 (HEAD -> master) modify Readme.md 3 6b98331 modify Readme.md 2 98ddd80 modify Readme.md 1 fcfc064 add Readme.md
Assume that 6b98331 modify Readme needs to be modified at this time. The author date and submitter date of the commit md 2
The modification steps are:
Execute the interactive rebase command git rebase -i 98ddd80
In the pop-up vi editor In the information, change the pick before 6b98331 is submitted to e, and then execute: wq Save
e 6b98331 modify Readme.md 2 # 此处原为pick,将pick修改为e / edit pick 2fe64c4 modify Readme.md 3 # Rebase 98ddd80..2fe64c4 onto 98ddd80 (2 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message # x, exec <command> = run command (the rest of the line) using shell # b, break = stop here (continue rebase later with 'git rebase --continue') # d, drop <commit> = remove commit # l, label <label> = label current HEAD with a name # t, reset <label> = reset HEAD to a label # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>] # . create a merge commit using the original merge commit's # . message (or the oneline, if no original merge commit was # . specified). Use -c <commit> to reword the commit message. # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted.
Execute GIT_COMMITTER_DATE="2021-10-22T15:10:07" git commit --amend --date="2021 -10-22T15:10:07" Modify both the author date and submitter date to 2021-10-22T15:10:07. Then you can choose to modify the commit log in the pop-up vi information editing window, and then execute :wq to save
and then execute git rebase --continue to go to the next commit until all changes are saved. After completion, use git log to view the submission information and you will see that the submission information has been modified.
The complete log of the above example is as follows:
admin@DESKTOP-PC MINGW64 /e/TestProj/ModifyTimeTest (master) $ git log --oneline 2fe64c4 (HEAD -> master) modify Readme.md 3 6b98331 modify Readme.md 2 98ddd80 modify Readme.md 1 fcfc064 add Readme.md admin@DESKTOP-PC MINGW64 /e/TestProj/ModifyTimeTest (master) $ git rebase -i 98ddd80 Stopped at 6b98331... modify Readme.md 2 You can amend the commit now, with git commit --amend Once you are satisfied with your changes, run git rebase --continue admin@DESKTOP-PC MINGW64 /e/TestProj/ModifyTimeTest (master|REBASE 1/2) $ GIT_COMMITTER_DATE="2021-10-22T15:10:07" git commit --amend --date="2021-10-22T15:10:07" [detached HEAD 137f41d] modify Readme.md 2 Date: Fri Oct 22 15:10:07 2021 +0800 1 file changed, 16 insertions(+) admin@DESKTOP-PC MINGW64 /e/TestProj/ModifyTimeTest (master|REBASE 1/2) $ git status interactive rebase in progress; onto 98ddd80 Last command done (1 command done): edit 6b98331 modify Readme.md 2 Next command to do (1 remaining command): pick 2fe64c4 modify Readme.md 3 (use "git rebase --edit-todo" to view and edit) You are currently editing a commit while rebasing branch 'master' on '98ddd80'. (use "git commit --amend" to amend the current commit) (use "git rebase --continue" once you are satisfied with your changes) nothing to commit, working tree clean admin@DESKTOP-PC MINGW64 /e/TestProj/ModifyTimeTest (master|REBASE 1/2) $ git rebase --continue Successfully rebased and updated refs/heads/master. admin@DESKTOP-PC MINGW64 /e/TestProj/ModifyTimeTest (master) $ git status On branch master nothing to commit, working tree clean
Recommended learning: "Git Tutorial 》
The above is the detailed content of How to modify the commit time in git. 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



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

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

To delete a Git repository, follow these steps: Confirm the repository you want to delete. Local deletion of repository: Use the rm -rf command to delete its folder. Remotely delete a warehouse: Navigate to the warehouse settings, find the "Delete Warehouse" option, and confirm the operation.

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

When developing an e-commerce website, I encountered a difficult problem: How to achieve efficient search functions in large amounts of product data? Traditional database searches are inefficient and have poor user experience. After some research, I discovered the search engine Typesense and solved this problem through its official PHP client typesense/typesense-php, which greatly improved the search performance.

To submit an empty folder in Git, just follow the following steps: 1. Create an empty folder; 2. Add the folder to the staging area; 3. Submit changes and enter a commit message; 4. (Optional) Push the changes to the remote repository. Note: The name of an empty folder cannot start with . If the folder already exists, you need to use git add --force to add.

Code conflict refers to a conflict that occurs when multiple developers modify the same piece of code and cause Git to merge without automatically selecting changes. The resolution steps include: Open the conflicting file and find out the conflicting code. Merge the code manually and copy the changes you want to keep into the conflict marker. Delete the conflict mark. Save and submit changes.
