[英]Git Fix existing commits history
I have a batch exe that script all database object and then automatically commit into a git repository.我有一个批处理 exe 脚本所有数据库对象,然后自动提交到 git 存储库。
For some reason ,that I've already fixed, actually i have this history:出于某种原因,我已经修复了,实际上我有这样的历史:
At commit 6, file is logically different from commit 4 But if i show file history i don't see nothing because the file is new for git system.在提交 6 时,文件在逻辑上与提交 4 不同但是如果我显示文件历史记录,我什么也看不到,因为该文件是 git 系统的新文件。
There is a way to solve this mess ?有没有办法解决这个烂摊子?
I wish this history:我希望这段历史:
Thanks for your support谢谢您的支持
You can use an interactive rebase to squash the commits where you deleted and re-added the file.您可以使用交互式 rebase压缩删除和重新添加文件的提交。
I'd recommend making a backup of your repository before following the next steps.我建议在执行后续步骤之前备份您的存储库。
f79c595bce675cf6109ce9c7d477741a55a9a247
.f79c595bce675cf6109ce9c7d477741a55a9a247
。git rebase --interactive <ref>
.git rebase --interactive <ref>
。pick f79c595 File sampleStoredProcedure.sql ...added
pick 141asd1 File sampleStoredProcedure.sql ...modified
pick 6d2b123 File sampleStoredProcedure.sql ...deleted
pick asd123a File sampleStoredProcedure.sql ...added
pick
to fixup
for all of the lines where the file was added again, ie with commit message "...added."pick
更改为fixup
,即带有提交消息“... added”。 If you have many commits and your commit messages all have the same format, you can use a macro or script in your editor to find all of the relevant commits.如果您有许多提交并且您的提交消息都具有相同的格式,您可以在编辑器中使用宏或脚本来查找所有相关的提交。 As an example, here is how I would do it in Vim:
举个例子,下面是我在 Vim 中的做法:
GIT_EDITOR=vim git rebase --interactive <ref>
.GIT_EDITOR=vim git rebase --interactive <ref>
启动交互式 rebase。qw/added<enter>^dwifixup <esc>jq:%normal @w<enter>
qw/added<enter>^dwifixup <esc>jq:%normal @w<enter>
: qw/added<enter>^dwifixup <esc>jq:%normal @w<enter>
:wq
.:wq
保存并退出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.