【问题标题】:Rebase error while amending Git message for mulitple commits [duplicate]修改多个提交的 Git 消息时出现 Rebase 错误 [重复]
【发布时间】:2021-10-05 18:26:59
【问题描述】:

我想更改我的提交消息,我正在关注so link

我给出了以下命令来更改我的旧提交和多次提交

git rebase -i HEAD~n

但我遇到了错误

error: cannot rebase: You have unstaged changes.
error: Please commit or stash them.

我不确定,为什么我会收到这个错误,我需要在推送到 bitbucket 之前更改我的提交消息,而不是存储或提交它们。

我有 8 个提交,需要推送。

编辑:-

git status

$ git status
On branch dev
Your branch is ahead of 'origin/dev' by 8 commits.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    ABC.log
        modified:   src/test/java/com/elastic/nftqa/TestqaApplicationTests.java

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .settings/

no changes added to commit (use "git add" and/or "git commit -a")



Git push 
    remote: Push rejected.
    remote:
    remote: refs/heads/dev: f5b0790e1d5: No Jira Issue found in commit message
    remote:
    remote: refs/heads/dev: 8f27f788c4c: No Jira Issue found in commit message
    remote:
    remote: refs/heads/dev: 0dba081770e: No Jira Issue found in commit message
    remote:
    remote: refs/heads/dev: a3d6680c680: No Jira Issue found in commit message
    remote:
    remote: refs/heads/dev: 76cccb2cc1d: No Jira Issue found in commit message

【问题讨论】:

  • 您有未分阶段的更改吗? git status 是否返回“没有提交,工作树干净”?
  • "我不确定,为什么会出现这个错误" 是的,你知道为什么。这是因为您有未分阶段的更改。如果您有未暂存的更改,则无法进行交互式变基。
  • 请看我的编辑
  • 正如我在回答中提到的:git config --global rebase.autoStash true,然后变基,确保在消息中添加 Jira,然后推送。

标签: git git-bash


【解决方案1】:

不打算隐藏或提交它们。

这不会让你有很多选择!

我更喜欢使用我在“Can “git pull” automatically stash and pop pending changes?”中提到的git config --global rebase.autoStash true

git rebase -i 不用担心存储步骤吗:Git 会为你存储并恢复阻止 rebase 的文件。

至少使用 Git .210 (Q3 2016) 以确保 Git 将在中止时恢复自动存储。

git push 错误消息完全是另一个问题,与git rebase 不同。
如“pre-receive hook declined: No JIRA Issue found in commit message?”详细说明,请确保在编辑的提交消息中添加 Jira 编号。

【讨论】:

    猜你喜欢
    • 2018-08-23
    • 2013-08-15
    • 2010-12-25
    • 1970-01-01
    • 2017-07-04
    • 2020-05-07
    • 2013-06-15
    • 2017-11-04
    • 2023-03-14
    相关资源
    最近更新 更多