search
HomeDevelopment ToolsgitHow 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"".

How to modify the commit time in git

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&#39;s log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with &#39;git rebase --continue&#39;)
# 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&#39;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!

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
What do you need to set after downloading GitWhat do you need to set after downloading GitApr 17, 2025 pm 04:57 PM

After installing Git, in order to use more efficiently, the following settings are required: Set user information (name and mailbox) Select text editor Set external merge tool Generate SSH key settings Ignore file mode

What to do if the git download is not activeWhat to do if the git download is not activeApr 17, 2025 pm 04:54 PM

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

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

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

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment