I was trying to use git rebase -i to improv my commits messages. I am the only one working on this director. By mistake, the file opened in the editor became like this:
noop
# Rebase d172428..d172428 onto d172428 (1 command)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous
# commit's log message, unless -C is used, in which case
# keep only this commit's message; -c is same as -C but
# opens the editor
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified); use -c <commit> to reword the commit message
#
# 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.
#
I aborted the rebase and tried to do it again, but the file opens with this same content. I tried to rewrite the original contents (like examples in tutorials) by adding my commits SHAs and messages. I ran $ git rebase -i and rewrote the content like the following:
pick d172428 (HEAD -> master, origin/master) Add LCD Driver
pick cf6c9a2 Create README.md
pick 6c9286f Initial commit, first effort
# Rebase d172428..d172428 onto d172428 (1 command)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous
# commit's log message, unless -C is used, in which case
# keep only this commit's message; -c is same as -C but
# opens the editor
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# . create a merge commit using the original merge commit's
# . message (or the oneline, if no original merge commit was
# . specified); use -c <commit> to reword the commit message
#
# 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.
#
But errors appear like:
interactive rebase in progress; onto d172428
Last command done (1 command done):
pick d172428 Add LCD Driver
Next commands to do (2 remaining commands):
pick cf6c9a2 Create README.md
pick 6c9286f Initial commit, first effort
(use "git rebase --edit-todo" to view and edit)
You are currently rebasing branch 'master' on 'd172428'.
(all conflicts fixed: run "git rebase --continue")
nothing to commit, working tree clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:
git commit --allow-empty
Otherwise, please use 'git rebase --skip'
Could not apply d172428... Add LCD Driver
I tried to change pick to edit for example. I tried skip, continue and abort. with the same problem. Each time I abort and try to rebase again the file starts with the same contnet noob.
How
>Solution :
Assuming you also want to rebase all the way back to the first commit, you should be using:
git rebase -i --root
This should bring up the same screen you have been seeing:
pick d172428 (HEAD -> master, origin/master) Add LCD Driver
pick cf6c9a2 Create README.md
pick 6c9286f Initial commit, first effort
As the instructions say, you may change pick to reword for all the commits listed:
reword d172428 (HEAD -> master, origin/master) Add LCD Driver
reword cf6c9a2 Create README.md
reword 6c9286f Initial commit, first effort
Then press ESC followed by :wq to save and close. This will start the rebase. The rebase will reapply each of your commits from the root commit, allowing you to reword the commit message.