搜尋
首頁開發工具Gitgit怎麼修改commit時間

在git中,可以利用「git commit --amend」指令來修改commit時間;該方法既可以修改最近一次提交的日期,也可以修改指定某次提交的日期,其中日期的格式需要是「ISO-8601」格式,語法為「GIT_COMMITTER_DATE="時間" git commit --amend --date="時間"」。

git怎麼修改commit時間

本文操作環境:Windows10系統、Git2.30.0版、Dell G3電腦。

git怎麼修改commit時間

1.修改最近一次提交的作者日期和提交者日期

如果要修改最近一次commit的作者日期和提交者日期,直接使用git commit --amend即可

註:日期格式須為ISO-8601格式

GIT_COMMITTER_DATE="2017-10-08T09:51:07" git commit --amend --date="2017-10-08T09:51:07"

2.修改某次提交的作者日期和提交者日期

如果要更改某次(可以是最近一次也可以是非最近一次)提交的作者日期和提交者日期,可以使用互動式rebase:

  • #執行git rebase -i COMMIT_SHA , 此COMMIT_SHA為待修改日期的commit的前一個commit的commit sha

  • 在vi彈出交互信息中將待修改日期的commit前的pick修改為e

  • 執行日期修改指令GIT_COMMITTER_DATE="2017-10-08T09:51:07" git commit --amend --date="2017-10- 08T09:51:07"

  • 執行git rebase --continue轉到下一個commit

  • 重複此過程,直到修改所有提交。透過git status可查看進展。

3.修改範例

目前git log提交資訊如下

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

假設此時需要修改6b98331 modify Readme. md 2這一commit的作者日期和提交者日期

修改步驟為:

執行互動式變基指令git rebase -i 98ddd80

在彈出的vi編輯資訊中,將6b98331提交前的pick修改為e,隨後執行:wq 儲存

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.

執行GIT_COMMITTER_DATE="2021-10-22T15:10:07" git commit --amend --date="2021 -10-22T15:10:07" 將作者日期和提交者日期均修改為2021-10-22T15:10:07。然後可選擇在彈出的vi資訊編輯窗中可修改提交日誌,然後執行 :wq 儲存

然後執行 git rebase --continue到下一個提交,直到儲存所有修改。完成後再使用git log查看提交資訊即可看到提交資訊已被修改

上述範例的完整日誌如下:

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

推薦學習:《Git教學

以上是git怎麼修改commit時間的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
Git下載後需要設置什麼嗎Git下載後需要設置什麼嗎Apr 17, 2025 pm 04:57 PM

安裝 Git 後,為了更有效地使用,需要進行以下設置:設置用戶信息(姓名和郵箱)選擇文本編輯器設置外部合併工俱生成 SSH 秘鑰設置忽略文件模式

git下載不動怎麼辦git下載不動怎麼辦Apr 17, 2025 pm 04:54 PM

解決 Git 下載速度慢時可採取以下步驟:檢查網絡連接,嘗試切換連接方式。優化 Git 配置:增加 POST 緩衝區大小(git config --global http.postBuffer 524288000)、降低低速限制(git config --global http.lowSpeedLimit 1000)。使用 Git 代理(如 git-proxy 或 git-lfs-proxy)。嘗試使用不同的 Git 客戶端(如 Sourcetree 或 Github Desktop)。檢查防火

git為什麼下載這麼慢git為什麼下載這麼慢Apr 17, 2025 pm 04:51 PM

Git 下載慢的原因包括網絡連接差、Git 服務器問題、大文件或大量提交、Git 配置問題、計算機資源不足以及其他因素,如惡意軟件。解決方法包括改善網絡連接、調整防火牆設置、避免下載不必要的文件或提交、優化 Git 配置、提供充足的計算機資源以及掃描並刪除惡意軟件。

git怎麼更新本地代碼git怎麼更新本地代碼Apr 17, 2025 pm 04:48 PM

如何更新本地 Git 代碼?用 git fetch 從遠程倉庫拉取最新更改。用 git merge origin/<遠程分支名稱> 將遠程變更合併到本地分支。解決因合併產生的衝突。用 git commit -m "Merge branch <遠程分支名稱>" 提交合併更改,應用更新。

git怎麼更新代碼git怎麼更新代碼Apr 17, 2025 pm 04:45 PM

更新 git 代碼的步驟:檢出代碼:git clone https://github.com/username/repo.git獲取最新更改:git fetch合併更改:git merge origin/master推送更改(可選):git push origin master

git怎麼刪除分支git怎麼刪除分支Apr 17, 2025 pm 04:42 PM

可以通過以下步驟刪除 Git 分支:1. 刪除本地分支:使用 git branch -d <branch-name> 命令;2. 刪除遠程分支:使用 git push <remote-name> --delete <branch-name> 命令;3. 保護分支:使用 git config branch. <branch-name>.protected true 添加保護分支設置。

git怎麼合併代碼git怎麼合併代碼Apr 17, 2025 pm 04:39 PM

Git 代碼合併過程:拉取最新更改以避免衝突。切換到要合併的分支。發起合併,指定要合併的分支。解決合併衝突(如有)。暫存和提交合併,提供提交消息。

git怎麼下載項目到本地git怎麼下載項目到本地Apr 17, 2025 pm 04:36 PM

要通過 Git 下載項目到本地,請按以下步驟操作:安裝 Git。導航到項目目錄。使用以下命令克隆遠程存儲庫:git clone https://github.com/username/repository-name.git

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 個月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
1 個月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
1 個月前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它們
1 個月前By尊渡假赌尊渡假赌尊渡假赌

熱工具

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。