-2

i want to change my commit messages, where i am following the so link

i gave below command to change my older and multiple commits

git rebase -i HEAD~n

but i am getting below error

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

i am not sure, why i am getting this error, where i need to change my commit message before pushing to bitbucket, not intended to stash or commit them .

i have 8 commits, which needs to be pushed.

EDIT :-

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
pappu_kutty
  • 2,378
  • 8
  • 49
  • 93
  • Do you have unstaged changes? Does ```git status``` return "nothing to commit, working tree clean" ? – milo Jul 30 '21 at 07:37
  • 1
    "i am not sure, why i am getting this error" Yes, you are sure why. It is because you have unstaged changes. You cannot do an interactive rebase if you have unstaged changes. – matt Jul 30 '21 at 07:37
  • please see my edit – pappu_kutty Jul 30 '21 at 07:43
  • 1
    As I mention in my answer: `git config --global rebase.autoStash true`, then rebase, making sure to add Jira in the messages, then push. – VonC Jul 30 '21 at 07:44

1 Answers1

1

not intended to stash or commit them .

That does not leave you with many options!

I would prefer to use the git config --global rebase.autoStash true I mention in "Can “git pull” automatically stash and pop pending changes?"

Do you git rebase -i without worrying about the stash step: Git will stash and restore for you the files which are blocking the rebase.

Use at least Git .210 (Q3 2016) in order to be sure Git will restore autostash on abort.

The git push error message is another problem entirely, separate from the git rebase.
As illustrated in detail with "pre-receive hook declined: No JIRA Issue found in commit message?", make sure to add the Jira number in the edited commit message.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250