I accidentally commit wrongly in Git and how can I amend a recent commit message? I tried both of these
git commit --amend
git rebase -i
which one is the correct command to do amending?
I accidentally commit wrongly in Git and how can I amend a recent commit message? I tried both of these
git commit --amend
git rebase -i
which one is the correct command to do amending?
git commit --amend -m "New commit message"
Make sure you don't have any working copy changes staged before doing this or they will get committed too. (Unstaged changes will not get committed.)
If the commit you want to fix isn’t the most recent one:
git rebase --interactive $parent_of_flawed_commit
If you want to fix several flawed commits, pass the parent of the oldest one of them.
An editor will come up, with a list of all commits since the one you gave.
Change pick to reword (or on old versions of Git, to edit) in front of any commits you want to fix.
Once you save, Git will replay the listed commits.
For each commit you want to reword, Git will drop you back into your editor. For each commit you want to edit, Git drops you into the shell. If you’re in the shell:
Change the commit in any way you like.
git commit --amend
git rebase --continue
Another option is before you perform below step make sure you have a clean working space.
git reset --soft HEAD~
Add/remove/update files as you want and then perform another commit.
git commit -m "new message that should go with this commit"