【发布时间】: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,然后推送。