【问题标题】:With egit how can I change just the description of an older commit (not last commit)?使用 egit 如何仅更改旧提交(不是最后一次提交)的描述?
【发布时间】:2014-05-26 11:37:48
【问题描述】:

上下文:

我正在学习如何在 Eclipse 中使用 git,并将它用于一个只有本地存储库的小项目。

问题:

  • 我刚刚注意到我之前所做的提交附有不正确的描述。
  • 我提交的文件没有任何问题,但为了清楚起见(如果我想恢复或其他),我想更改具有误导性的描述。
  • 我不能只修改以前的提交,因为从那以后我做了更多的提交。

挣扎着解决问题:

我尝试过创建新的分支、修改提交然后变基,但最终会出现一堆看起来很吓人的合并冲突和看起来像意大利面条的历史树。 我可以将我较新的提交复制并粘贴到 txt 文件中,使用错误的信息恢复到提交并从那里重新开始,但我认为使用 git 的全部目的是避免做类似的事情。

问题:

有没有一种简单的方法来更改旧提交的描述文本?

如果不是egit中复杂的方法步骤是什么?!

【问题讨论】:

    标签: eclipse git commit egit


    【解决方案1】:

    如果您已经将修订推送到某个地方:不要

    否则:使用git rebase -i <SOME_OLD_REVISION> 并使用r(eword) 选项标记要更改的提交。

    关闭弹出的文件后,变基将开始,系统会提示您选择输入新提交消息的每个提交。

    假设您有以下提交历史记录(最新的优先):

    f6f6f6f last commit
    d4d4d4d ...
    c3c3c3c third commit
    b2b2b2b second commit
    a1a1a1a first commit
    

    如果想更改b2b2b2bc3c3c3c 的消息,您可以这样做

    git rebase -i a1a1a1a
    

    接下来,您最喜欢的编辑器将弹出并显示此对话框:

    pick f6f6f6f last commit
    pick ...
    pick c3c3c3c third commit
    pick b2b2b2b second commit
    
    # Rebase b2b2b2b..f6f6f6f onto a1a1a1a
    #
    # Commands:
    #  p, pick = use commit
    #  r, reword = use commit, but edit the commit message
    #  e, edit = use commit, but stop for amending
    #  s, squash = use commit, but meld into previous commit
    #  f, fixup = like "squash", but discard this commit's log message
    #  x, exec = run command (the rest of the line) using shell
    #
    # 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.
    #
    # Note that empty commits are commented out
    

    对于提交b2b2b2bc3c3c3c,将pick 更改为rreword,保存文件并退出编辑器。

    接下来,变基将开始。

    对于您选择到reword 的提交,您可以输入新的提交消息。

    【讨论】:

    • +1 以获得全面的答案,但我希望得到 egit 的答案,即 eclipse 插件。我还没有在 shell 级别使用 git(我想我应该学习。)我只使用本地存储库,所以无处可推。
    • @mallardz:请参阅stackoverflow.com/q/7197152/520162 了解 egit 上的 rebase -i。也许这会有所帮助。
    • 好吧,egit 有一个交互式 rebase 窗口,您可以在 Git 透视图中使用它。我几乎可以应付过去。我还开始学习 bash 级别的 git 基础知识,事实证明它非常有帮助,因此 +1 也让我也这样做了。
    猜你喜欢
    • 2021-04-27
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多