Git:如何在“git reset”之后重用/保留提交消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16858069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: How to reuse/retain commit messages after 'git reset'?
提问by bentolor
As Git user I regular come across the situation, that I need to rework one or more commits in a way which do not fit into --amend
or rebase -i
with fixup commits. Typically I would do something like
作为 Git 用户,我经常遇到这种情况,我需要以一种不适合--amend
或不适合修复提交的方式重新处理一个或多个rebase -i
提交。通常我会做类似的事情
git reset HEAD~1
# hack, fix, hack
git commit -a
# argh .. do I need to retype my message?
I take sensible composed commit messages quite serious. They typically contain larger text with references & justifications for the change. Until now, I'm quite annoyed on the lengthy process to recover my old commit message via an unsorted git reflog
, git log
and copy & paste process.
我非常认真地对待合理的组合提交消息。它们通常包含较大的文本以及更改的参考和理由。到现在为止,我很恼火的漫长的过程来恢复我的老经无序提交信息git reflog
,git log
并复制和粘贴的过程。
Is there a better to tackle this? And how would it, if my comprises more than one commit?
有没有更好的方法来解决这个问题?如果我的提交包含多个提交,它会如何?
Edit:After a bit thinking about this I think what I'm looking for is some git stash-like functionality for commit messages where fixup/amend commits are not appropriate.
编辑:稍微考虑一下之后,我认为我正在寻找的是一些类似于 git stash的功能,用于在修复/修改提交不合适的情况下提交消息。
回答by ibizaman
After a git reset
, this one-liner can do it:
在 a 之后git reset
,这个单行可以做到:
git commit --reuse-message=HEAD@{1}
or even shorter:
甚至更短:
git commit -C HEAD@{1}
You can use the other options given by @user2718704.
您可以使用@user2718704提供的其他选项。
回答by user2718704
When running "git commit" command, you've to check the following options,
运行“git commit”命令时,您必须检查以下选项,
To reuse,
为了重用,
--reuse-message=<commit>
To edit on reuse,
要编辑重用,
--reedit-message=<commit>
To change the author,
换作者,
--reset-author
回答by mart1n
Why reset if you can hack, fix, hack and then just run git commit --amend --no-edit
; thus, retaining your original commit message.
如果您可以破解,修复,破解然后运行git commit --amend --no-edit
,为什么要重置;因此,保留您的原始提交消息。
To make it work for multiple commits, just create a temporary commit with your newest changes and then use an interactive rebase to squash the previous commit (containing the good commit message) with the new temporary one, keeping the commit message of the old commit.
要使其适用于多个提交,只需使用最新的更改创建一个临时提交,然后使用交互式 rebase 将先前的提交(包含良好的提交消息)与新的临时提交压缩,保留旧提交的提交消息。
回答by Joe
You could consider git commit --reset-author -c <commit>
, to reuse the commit message with editing and the current time.
您可以考虑git commit --reset-author -c <commit>
,通过编辑和当前时间重用提交消息。