如何在通过git rebase --interactive编辑提交时保留提交消息? [英] How do I keep the commit message when editing commits via git rebase --interactive?

查看:197
本文介绍了如何在通过git rebase --interactive编辑提交时保留提交消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正处于 git rebase --interactive 会话中,我正在编辑提交。我按照的建议进行操作,我该如何分割Git commit埋在历史记录中?即,我运行了 git reset HEAD ^ 并做了我的修改。
现在我想要rebase继续,这需要我提交我的更改。我想修改旧的提交消息,但问题是,如果我运行 git commit --amend ,我会收到commit 之前我实际上正在修改 - 我当然不希望将我的更改合并到该提交中。

所以,如何检索我现在正在处理的提交的旧提交消息?

解决方案

while CharlesB的解决方案是正确的,可能更简单,原因是原始发布者在提交之前看到提交信息 他想编辑是因为他使用 - 修改 git commit 的标志,这会修改 之前的 提交。



代替使用 - 修改更改,只需使用 git commit 而不用标志,这将不会触及前一个提交。你也可以传入一个选项来重用你使用 git reset head ^ 重置的提交的提交信息:



< pre-class =lang-bash prettyprint-override> git commit --reuse-message = HEAD @ {1}

#或者使用-C,这是相同的事情,但更短:
git commit -C HEAD @ {1}

HEAD @ {1} 指向您在执行 git reset head ^ 之前的提交。您也可以直接传递该提交的sha ID。



git commit 文档


  -C< commit> 
--reuse-message =< commit>

取一个现有的提交对象,并重用日志消息和作者信息(包括时间戳)创建提交。

当然,正如我所说的,CharlesB的解决方案更简单,因为如果您不做第一个 git reset head ^ ,你可以直接修改并修改你要修改的提交,当你执行时,你会自动获得前一个提交信息。 git commit --amend ,你不必为它提交commit sha。


I'm currently in the midst of a git rebase --interactive session, where I'm editing a commit. I'm proceeding as suggested by How can I split up a Git commit buried in history? i.e. I ran git reset HEAD^ and did my modifications. Now I want rebase to continue, which requires me to commit my changes. I'd like to modify my old commit message, but the problem is, if I run git commit --amend, I'm given the commit message of the commit before the one I'm actually modifiying -- and I certainly don't want to merge my changes into that commit.

So how do I retrieve my old commit message for the commit I'm working on now?

解决方案

While CharlesB's solution is correct and probably easier, the reason that the original poster is seeing the commit message before the commit he wants to edit is because he's using the --amend flag of git commit, which modifies the previous commit.

Instead of using --amend to commit your changes, just use git commit without the flag, which won't touch the previous commit. You can also pass in an option to reuse the commit message from the commit that you reset using git reset head^:

git commit --reuse-message=HEAD@{1}

# Or use -C, which is the same thing, but shorter:
git commit -C HEAD@{1}

HEAD@{1} points to the commit you were at before you did git reset head^. You can also just pass in the sha id for that commit directly.

From the git commit docs:

-C <commit>
--reuse-message=<commit>

Take an existing commit object, and reuse the log message and the authorship information (including the timestamp) when creating the commit.

Of course, like I said, CharlesB's solution is simpler, since if you don't do the first git reset head^, you can just make changes and amend the commit you're trying to modify directly, and you automatically get the previous commit message when you do git commit --amend, you don't have to pass in the commit sha for it.

这篇关于如何在通过git rebase --interactive编辑提交时保留提交消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆